Question

I wan to configure the unity container using ONLY xml (no fluent API) and I have a complex task. I have an interface which looks like this

public interface ISettingsDistributor {
    String TargetProperty;
}

And its implementation SettingsDistributor

public interface ISettingsConsumer { }
public class SettingsConsumer :ISettingsConsumer, OtherType {
    public SettingsConsumer(String theParameter) : base(theParameter) {

    }
}

This is a consumer of that setting. The following is the configuration section I've built so far. (typeAliases and other stuff is omitted)

   <containers>
        <container name="container">
            <types>
                <type type="ISettingsDistributor" mapTo="SettingsDistributor">
                    <lifetime type="singleton" />
                </type>
                <type type="ISettingsConsumer" mapTo="SettingsConsumer">
                    <lifetime type="perThread" />
                </type>                    
            </types>
        </container>
    </containers>

How can I say to unity in this xml file that when it tries to resolve the type ISettingsConsumer it should first resolve the ISettingsDistributor and inject its TargetProperty member as a value to the constructor?

Was it helpful?

Solution

Why don't you just inject your ISettingsDistributor?It will be the source of your magic string anyway.So whats the problem with that?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top