Answer the question
In order to leave comments, you need to log in
Where to store the IoC container?
Good evening.
I'm starting a big project, and I feel like it's time to use an IoC container, more specifically, UnityContainer. How to create an instance of a container is understandable. How to set up interface-default_object links in it is understandable. How to ask a container instance to create an instance of the default class for the IAnyInterface interface is understandable.
It is not clear where to store the same instance of UnityContainer? Create a field in a static type class
public readonly UnityContainer container = GetInitedContainer();
?
Answer the question
In order to leave comments, you need to log in
If it is an ApplicationContainer, then it can be implemented as a singleton.
And why provide global access to the container? Can I use constructor injection? True, if there are a lot of dependencies, then the constructor grows (each implementation has its drawbacks), but there are no problems with testability (and each has its pluses).
Singleton has more problems than advantages. If, nevertheless, a singleton, then look towards the Ambient Context implementation.
In general, a lot depends on the environment, implementation, etc.
Related article habrahabr.ru/post/62830
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question