Structuremap,为从类派生的所有实例调用SetProperty

时间:2015-07-28 02:07:25

标签: c# structuremap structuremap3

StructureMap 3中将SetProperty应用于从特定类派生的所有接口的最佳方法是什么?我有很多很多类的表格

public class FooBarProxy : Proxy, IFooBarProxy
{
    public string BaseAddress { get; set; }
}

我想做相同的事情(利用SetProperty的延迟 - 直到实例化后的性质)

scanner.For<IFooBarProxy>.Use(FooBarProxy)
    .SetProperty(m => m.BaseAddress = GetBaseAddress())

我通过IRegistrationConvention尝试过,但结果却变成了竹子:

public class WebApiProxyConvention2 : IRegistrationConvention
{
    public void Process(System.Type proxyType, StructureMap.Configuration.DSL.Registry registry)
    {
        // derived from FooBar.WebApiProxies.Proxy?
        if (!proxyType.IsSubclassOf(typeof(FooBar.WebApiProxies.Proxy)))
        {
            return;
        }

        // get the matching interface
        var proxyInterface = proxyType.GetInterface("I" + proxyType.Name);

        registry.For(proxyInterface).Use(proxyType)
            .????? // answer goes here.
    }
}

谢谢!

0 个答案:

没有答案
相关问题