tags:

views:

53

answers:

1

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 not find any example yet...

A: 

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));
    }
}
KevM
as far as I can tell, this seems to work !! thx
rekna