Dependency injection looks great, however when I look at examples I often see lots of XML config file. This is not good because:
- I don’t get compile time checking on the type names in the config files
- Refactoring tools don’t update the confilg files when types are renamed
- I don’t want the customers changing the configurat开发者_如何学Cion!
- I am a C# programmer, and would rather not hide the logic of my application in XML.
Some frameworks will let you config them from code, however most of their documentation (and examples) assumes you are using XML, as the XML config came first. So what dependency injection frameworks consider code based configuration to be the normal way of using them?
Almost all containers now have a code based API for registering dependencies, even those which were originally configured only via XML. And usually the XML approach is only recommended for edge-cases (e.g. where there maybe a need to change registration / wiring post-deployment)
Eg StructureMap and Castle Windsor
Ninject
AutoFac
Ninject
Simple Service Locator (shameless plug)
精彩评论