1

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.
    }
}

谢谢!

4

0 回答 0