Creating one instance with Unity and use it everywhere

c#, unity-container

Solution

Add `ContainerControlledLifetimeManager()` like this:

container.RegisterType<IValidationService, ValidationService>(new ContainerControlledLifetimeManager());

Read more here: http://msdn.microsoft.com/en-us/library/ff647854.aspx

Problem

Hi I am using unity as my IoC framework and I have a case where I need to use the same instance of an object in my entire application , bassicly creating a singleton. Let's say I have this configuration: ``` container.RegisterType<IValidationService, ValidationService>(); ``` How would I go about in telling unity to create only one instance of the ValidationService and use it everywhere in my app?

Original source

Related problems