IoC container configuration

How should IoC container configuration be organized? I know that registering with code should be placed at the highest level in the application, but what if there were hundreds of dependencies in the application that needed to be registered? It's the same with XML configurations. I know you can split XML configurations into multiple files, but it looks like this will become a maintenance issue if someone has to break through multiple XML files.

Are there any guidelines for organizing dependency registration? Of all the videos and tutorials I've seen, the code used in the demo was simple enough to put it in one place. I have yet to come across an example application that uses a large number of dependencies.

+2


a source to share


2 answers


Autofac and others (like Ninject) use the module concept for this exact purpose. http://code.google.com/p/autofac/wiki/StructuringWithModules might be what you are looking for.



Hth Nick

+6


a source


It would help a bit if we knew if you were talking about any particular IoC container.

Windsor, for example, allows you to define dependencies on a wide range of XML files (organized however you want) and just be included in the configuration. The structure should be in a format that makes sense. Have a file / folder for controllers, objects, etc. A hierarchy of related items.



With something more code oriented like Autofac, you can easily create a variety of container configuration providers to tweak your configuration. With Hiro, you don't need to do much configuration at all.

Regardless of the container used, they all provide configuration-based registration services, so this will be your first stop when clearing registrations. A good example would be registering all classes whose name ends in "Controller" in an MVC application.

+2


a source







All Articles