2013-06-12 10 views
2

我想garanty這種統一使用一個名爲註冊解析構造函數的參數,例如:命名映射類型使用,以解決構造函數的參數使用Unity

我有兩個類型登記:

_container.RegisterType<IMyInterface, Implementation1>("implementation1"); 
_container.RegisterType<IMyInterface, Implementation2>("implementation2"); 

當團結解決一類具有以下構造器:

public class Example 
{ 
    Example(IMyInterface args) 
    {  
    } 
} 

我應該怎麼指定必須解決在這種情況下使用「implementation2」團結只有

回答

1

您可以配置一個團結類型註冊使用,以解決構造函數參數到一個特定的命名類型如下:

container.RegisterType<IExample, Example>(
    new InjectionConstructor(new ResolvedParameter<IMyInterface>("implementation2"))); 
相關問題