IOC Unity configuration

I have a class

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

      

What I want to customize with Unity XML Configuration, I can customize it with C # code like below where "container" is my Unity container

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

      

and it will permit use with normal unity calls

container.Resolve ("myBroker");

But currently my xml cannot resolve the final IMyBrokeredObject, I get a permission exception as Unity is trying to resolve the insted type by simply inserting that type like in the code above.

Any ideas?

0


source to share


2 answers


Have you identified the type of config file:



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

      

+1


source


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

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



its tricky because i don't want the container to emit an instance of the interface, but actually pass the interface as is, "InjectionParameter" is the store for the value, the stored value is passed when the object is instantiated by the container as is. I'm looking for the required xml config to create an InjectionParameter and give it a value, if at all possible?

0


source







All Articles