Serializing Configurations for a Dependency Injection / Inversion of Control?

Most DI Containers support XML configuration in fact, most of them started out that way, and XML configuration was the only option. Nowadays XML configuration is one option among several However, in it's current incarnation, MEF doesn't use XML configuration. It's not a DI Container either.

Most DI Containers support XML configuration - in fact, most of them started out that way, and XML configuration was the only option. Nowadays, XML configuration is one option among several. However, in it's current incarnation, MEF doesn't use XML configuration.It's not a DI Container either.

Thanks for the link. Now that I've read more on MEF, I don't think unknown runtime discovery is what I'm looking for. It looks like an open debate between XML Configuration and Code Configuration.

Ultimately, I'd like to build a toolkit that can be used by non-programmers to "hook things together" given a rich set of programmer built libraries. It sounds like XML Configuration fits better here. – Joshua Starner Jun 9 '10 at 12:19.

I don't know about mef, but Spring does exactly what you describe using pretty much exactly the same method you describe (injection configured by an XML file or config section).

Cool, I've seen Spring mentioned, but I didn't pursue any further reading. I'll check it out. Thanks!

– Joshua Starner Jun 9 '10 at 0:55.

Using MEF (which you mentioned), you can use ImportMany to import a collection of Engine instances. You'd then be able to create one car per engine, and return that, with no XML required. Public class Application { ImportMany public IEnumerable Engines { get; set; } public void Go() { // I'm assuming this object was composed already... var cars = this.Engines.

Select(e => new Car(e)); foreach(var car in cars) { // Do something with each car } } } This has the advantage of allowing you to add new "Engines" any time, without changing your code. All of the wiring is handled dynamically at runtime without configuration.

Thanks Reed. I did find the ImportMany attribute in MEF, which seemed great for dynamically loading collections of things. I think the problem I'm trying to solve is allowing someone to be explicit about which object gets used for each Car.

I can see using this approach how new Engine objects would be added to the list at runtime, but I need some way of serializing the fact that "Car 1 uses a Fast Engine", so when I create Car 1, give it a Fast Engine. – Joshua Starner Jun 9 '10 at 0:52.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions