1

What's the best way in StructureMap 3 to apply SetProperty to all interfaces deriving from a particular class? I have many, many classes of the form

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

I want to do the equivalent of this (taking advantage of the delay-until-after-instantiation nature of SetProperty)

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

I tried via IRegistrationConvention but ended up rather bamboozled:

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

Thanks!

stevieg
  • 652
  • 4
  • 14

0 Answers0