2

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?

aleczandru
  • 5,319
  • 15
  • 62
  • 112

1 Answers1

9

Add ContainerControlledLifetimeManager() like this:

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

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

Big Daddy
  • 5,160
  • 5
  • 46
  • 76