0

I've come across some code in the Application_EndRequest event and I'm trying to work out how it will behave:

var services = ObjectFactory.GetAllInstances<IService>();

Does this return all instances in the container? Given that there is a single container for the application, and a per request scope, does this mean this will return all instances for active requests?

However, I've put some logging in and sent multiple simultaneous requests and this count is only ever 1

ekad
  • 14,436
  • 26
  • 44
  • 46
  • What are you counting? Classes that implement IService, live object instances of classes that implement IService, or something else? Multithreading doesn't necessarily require multiple consumer objects, just multiple threads to do stuff... So depending on what you're counting, "1" might be correct, unless you're spinning up a new implementation and object instance of IService at runtime for every new request (which I find unlikely). – Izzy Jan 18 '16 at 11:12

1 Answers1

0

ObjectFactory.GetAllInstances<IService>(); returns all implementations of IService registered in the container. If it returns just one instance that means only one type is registered.

LetMeCodeThis
  • 591
  • 6
  • 10