StructureMap 2.5.4 FindInterfaceThatCloses больше не поддерживается, каков новый синтаксис? - PullRequest
0 голосов
/ 01 февраля 2010

ранее у меня было:

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

, но 2.5.4 больше не поддерживает FindInterfaceThatCloses ...

кажется, что вместо ITypeScanner нужно реализовать IRegistrationConvention, поэтому синтаксис метода Process тоже должен измениться ...

Не удалось найти ни одного примера ...

1 Ответ

2 голосов
/ 01 февраля 2010

Я все еще вижу метод расширения типа FindInterfaceThatCloses в источнике StructureMap (в AssemblyScannerExtension.cs).

Вы можете заменить требуемое поведение новым ConnectImplementationsToTypesClosing .

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