Where to place IoC container configuration?

Is it good practice to create another project in your solution just to configure the container and registries? I am wondering where I should put the container configuration, I currently have all the code in my global asax, but it is getting messy as I add more registries and more advanced injections.

+3
source share
4 answers

Usually I create a registry class in my web project, where I link everything together with StructureMap. See this: http://structuremap.github.com/structuremap/RegistryDSL.htm

If you have projects in your solution that have a lot of their own configuration, then you might want to provide these projects with your own registry, but don't really register it before the start_ application in global.asax.

Part of the IoC is waiting to bind everything together until you need it. Thus, it is more customizable. Therefore, if you can keep your registry on your website, you will have maximum flexibility.

+2
source

This article uses Castle Windsor in the examples, but this is good advice that applies regardless of which container you use.

http://devlicio.us/blogs/krzysztof_kozmic/archive/2010/06/20/how-i-use-inversion-of-control-containers.aspx

+2
source

, Global.asax. :

  IPreferredContainerType container = new RootContainerFactory().Container;
  Application["Container"] = container;
  Container = container;

, , . .

0

Each of my projects has its own registry and configuration (which Jeremy calls Bootstrapper) in your main application (Win / Web / Console). Thus, it is easy to replace the main application without touching any registries.

0
source

Source: https://habr.com/ru/post/1757236/


All Articles