O
O
Oxoron2015-09-22 19:34:41
Computer networks
Oxoron, 2015-09-22 19:34:41

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

2 answer(s)
V
VanKrock, 2015-09-23
@Oxoron

If it is an ApplicationContainer, then it can be implemented as a singleton.

O
om2804, 2015-09-23
@om2804

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 question

Ask a Question

731 491 924 answers to any question