c# - Best Practices for IOC Container -


I am using Integration IOC container and I am thinking that what is the best way to reach containers for multiple Classes are

Will each class be an IUNTTTEIER member and then go through the constructor in the container? Should I have a singleton class with IoC container?

How about the development of asp.net?

Can anyone guide me in the right direction? Thank you.

IMHO To make this whole container inject into a class or an application, a comprehensive static IOC service locator.

You want to be able to see from a class constructor (can call Fu), how to get the services / objects used to achieve this clarity, test qualification and degubability Improves

We say that Fu requires only email service, but I get solved by email service container in the entire container and in any way the code will be very difficult to follow in this case. Instead, it is better to have the e-mail service injected directly to clarify the dependence of foo.

If Fu requires the creation of several examples of email service, then the e-mail service service (through the IoC container), which will create the necessary frequencies on the fly.

In the latter case, the dependency of Fu is still indicated as possible - only those who can make an email service provider. If I had to inject the whole container, then it would not be clear what is the exact dependency of Fu.

Now, if I later want to provide different examples of email service, then I swap it out EmailServiceFactory I can also swap the entire factory, if all the services need to be swapped (such as during the trial).

So at the cost of making an additional square (factory), I get a lot of cleaner code and there is no need to worry about the inquisitive worms which may occur when using global positioning is done. Apart from this, when socks are being supplied for testing, I know what is needed and not copied the entire container types.

This approach also has the advantage, that now, when a module is started (applies only to Prism / Modularity), there is no need to register all types of objects with Ioc container. Instead it can only register its service factory, which then supplies those objects.

To be clear, the module's initialization class (implies IMU) will still be able to access the expanded IoC container for the supply of services in its constructor, consumed by other modules, but The container should not invade sections of the module.

Finally, there is a good example of what we have here, how an extra layer of indirection solves a problem.


Comments