This project is read-only.

XML Configuration

Oct 29, 2013 at 10:33 PM
I'm looking at all the features of Simple Injector for my project but I don't see any feature that allows for late binding (XML/Configuration). Surely there must be some way to do it?
Oct 29, 2013 at 10:51 PM
XML based configuration is deliberately left out from Simple Injector. XML based configuration is brittle, error prone and is always a subset of what you can achieve with code based configuration. The general consensus is to use code based configuration as much as possible and only fall back to XML based configuration for those parts of the configuration that really need to be changed after deployment. These are most of the time just a few lines, since most of the changes would still need developer interaction (write unit tests for instance).

And even for those few lines that need to be configurable, it's a bad idea to write the fully qualified type name in the configuration file. A configuration switch (true/false) is often enough. You can read the switch in your code based configuration and this allows you to keep the type names in your code. This allows you to refactor easily and have compile-time support.

Because of this Simple Injector stripped XML support.

But there are other ways of doing late binding, and perhaps you're interested in doing batch registration. This involves reflection and late binding and allows you to do a whole bunch of registrations in a single line of code, even without the use of XML configuration. More info on that can be found here.

But if XML based configuration is really what you need, Simple Injector is not suited for you. Try one of the other frameworks instead.
Marked as answer by dot_NET_Junkie on 2/26/2014 at 1:22 PM
Oct 29, 2013 at 11:38 PM
Thank you for the very fast and excellent response! I'm a DI noob, reading Mark Seemann's book and searching for the perfect container. I recognize that XML was probably left out "by design," of limited usefulness and not best practice for 99.9% of configuration. And you're correct, there are certainly plenty of containers that have XML config. Per, none of them work as fast overall as Simple Injector. I work on a web project that needs a flexible plugin architecture that needs to be customized & configured after deployment at client's sites without a trip back to the compiler for the core application. With your project's speed, you have every other feature I can conceive of. Perhaps I can use the plugin architecture from the article you reference but would have loved another answer.