开发者

How do I pass the UnityContainer as a parameter to a registration in a Unity IOC xml configuration file

I have an implementa开发者_StackOverflow中文版tion of a factory interface that uses an IOC container to create it's objects.

The container is a automatic property on the Factory, and ideally I would like to inject this property with same container where the factory is being registered.

For clarity I have described what I would like it to look like below.

<container name="MyContainer">
    <register type="IControllerFactory" mapTo="UnityControllerFactory">        
        <property name="UnityContainer" value="MyContainer" />
    </register>
</container>    

Of course I have registered a class after this that automatically injects this registration into it's IControllerFactory property.

Is there a way to do this?


The IUnityContainer registered with itself by default. You can just set up your constructor like this:

public UnityControllerFactory(IUnityContainer unityContainer) 
{
   this.unityContainer = unityContainer;
}

No addition configuration is needed.... the dependency will be resolved hassle-free.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜