开发者

StructureMap 2.5.4 FindInterfaceThatCloses no longer supported, what is the new syntax?

previously I had :

public class PresentationModelConventionScanner : ITypeScanner
{
   public void Process(Type type, PluginGraph graph)
    {
        Type interfaceType = type.FindInterfaceThatCloses(typeof(IPresentationModel<>));
        if (interfaceType != null)
        {
            graph.AddType(interfaceType, type);
        }
    }

but 2.5.4 does not support FindInterfaceThatCloses anymore ...

it seems you have to implement IRegistrationConvention instead of ITypeScanner, so the Process method syntax has to change too...

Could开发者_如何学JAVA not find any example yet...


I still see the FindInterfaceThatCloses type extension method in the StructureMap source (in AssemblyScannerExtension.cs).

You can replace the behavior you require with the new ConnectImplementationsToTypesClosing method.

public interface IPresentationModel<T>{}
public class StringPresentationModel : IPresentationModel<string> {}
public class IntPresentationModel : IPresentationModel<int>{}

[TestFixture]
public class Structuremap_configuraiton
{
    [Test]
    public void connecting_implementations()
    {
        var container = new Container(cfg =>
        {
            cfg.Scan(scan =>
            {
                scan.TheCallingAssembly();
                scan.ConnectImplementationsToTypesClosing(typeof(IPresentationModel<>));
            });
        });

        container.GetInstance<IPresentationModel<string>>().ShouldBeOfType(typeof(StringPresentationModel));
        container.GetInstance<IPresentationModel<int>>().ShouldBeOfType(typeof(IntPresentationModel));
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜