Register same instance for different instances in xml file

Mar 13, 2009 at 8:04 PM
Is it possible to specify in the configuration file that the same instance of an object is provided depending on the interface requested. This is fairly straight forward in code:



Michael Fischer
Mar 14, 2009 at 1:04 AM
Not directly, but you can get to the same place.

First step is to register the instance in the container through configuration, under it's concrete type. Next, add two type elements, each of which maps to the concrete type of the instance. Something like this:

    <type type="IInterfaceOne" mapTo="SomeClassImplementingInterfaceOneAndTwo" />
    <type type="IInterfaceTwo" mapTo="SomeClassImplementingInterfaceOneAndTwo" />
    <add type="SomeClassImplementingInterfaceOneAndTwo" value="..." typeConverter="..." />

That should do the trick.