views:

801

answers:

2

I have a class

public class Broker
{
    public Broker(string[] hosts, string endPoint, string port, Type remoteType)
    {
    }
}

Which I want to configure using Unity XML Configuration, I can configure it using code in C# as follows already, where "container" is my Unity container

            container.Configure<InjectedMembers>()
                .ConfigureInjectionFor<Broker>("myBroker",
                                                           new InjectionConstructor(hosts, endPoint, port, new InjectionParameter(typeof(IMyBrokeredObject))));

and it will happly resolve using the normal unity calls

container.Resolve("myBroker");

But currently my xml cannot resolve the final parameter IMyBrokeredObject, I get a resolution exception, as Unity is trying to resolve the type insted of simply injecting the type, as it does in the code above.

Any Ideas?

A: 

Have you defined the type in the configuration file:

<unity>
<typeAliases>
  <typeAlias alias="IMyBrokeredObject" type="MyAssembly.IMyBrokeredObject, MyAssembly" />
</typeAliases>
<containers>
      <container>
        <types>
          <!-- Views -->
          <type type="IMyBrokeredObject" mapTo="MyAssembly.MyBrokeredObjectImplementation, MyAssembly" />
Bruno Shine
A: 

Hi Thanks Bruno

But my problem is that there is no implementation available for the IMyBrokeredObject, what is actually happening in the background of this is that the broker provides remote objects given an interface, the actual implementation is somewhere else.

In code I can get the container to provide an broker by giving an "InjectionParameter", I cannot find out how to do this in the xml configuration.

its tricky because I dont want the container to give an instance of the interface but to actually pass the interface as is, the "InjectionParameter" is a store for a value, the stored value is handed in when the object is created by the container, as is. What I am looking for is the required configuration xml to create the InjectionParameter and give it the value, if that is at all possible?