结构图按名称自动解析实例

时间:2018-04-04 06:26:46

标签: dependency-injection instance structuremap named-instance

我的问题是我想为一个界面注册两种类型:

我查过这篇文章: https://groups.google.com/forum/#!msg/structuremap-users/2T_WTAjRVJ8/HKsELqJEOi4J
https://groups.google.com/forum/#!topic/structuremap-users/75-1AV1boMw

For<IPageManager>().Singleton().Use<PageManager>().Named("pageManager");
For<IPageManager>().Singleton().Use<EnhancedPageManager>().Named("enhancedPageManager");

在我的控制器中:

public class ValuesController
{
    public ValuesController(IPageManager pageManger)
    {
        // Here I want to be instance of page Manager 
    }
}

public class PagesController
{
    public PagesController(IPageManager enhancedPageManger)
    {
        // Here I want to be instance of enhancedPageManger
    }
}

但问题是我总是收到enhancedPageManger的实例 如何解决?

在文档中有配置示例,但不是用法:http://structuremap.github.io/glossary/#sec3

var container = new Container(c =>
{
   c.For<IFoo>().Use<Foo>();
   c.For<IFoo>().Add<SomeOtherFoo>();
});

0 个答案:

没有答案