We use Unity as our IOC Container.
Our program is written so far in a way that we resolve an interface just before we need to use it.
This however results in the interface being resolved inside a loop. Which could result in the interface being resolved 100,000 times in one run.
Question is: Would moving the resolve outside the loop have a significant difference or is this just micro optimisation?
Our progrm takes over a day to run. So for those who will answer “test it yourself”, it is actually faster to ask the question here 🙂
It depends on how you registered the interface I would say. With which LifetimeManager did you register it?
Does your program always need a new instance? Or can it be the same instance over and over?
If you need the same instance (Singleton), use the ContainerControlledLifetimeManager:
If you don’t care about which instance you get (new or old, maintained by GC), you can use ExternallyControlledLifeTimeManager:
You can also create your own implementation of a LifetimeManager to better fit your needs.
Take a look at this article about LifetimeManagers