简体   繁体   English

与scan.TheCallingAssembly一起使用时,StructureMap找不到通用类型

[英]StructureMap not finding generic Types when used with scan.TheCallingAssembly

I have an Application-Assembly, which contains an amount of generic IMapper Interfaces. 我有一个应用程序组装,其中包含大量的通用IMapper接口。 Each implementation has said Types and two methods to map the objects in each direction. 每个实现都有所述类型和两个方法来在每个方向上映射对象。 Using AutoMapper, I went ahead using their documentation and created an IocRegistry-Class in said Application-Assembly, which should register all Types: 使用AutoMapper,我继续使用他们的文档,并在所说的Application-Assembly中创建了一个IocRegistry-Class,它应该注册所有类型:

public class IocRegistry : Registry
{
    public IocRegistry()
    {
        Scan(
            scan =>
            {
                scan.TheCallingAssembly(); // Scan this assembly
                scan.WithDefaultConventions();
                scan.AddAllTypesOf(typeof(IMapper<,>));
            });
    }
}

And if I use the "WhatDidIScan"-method, I can see the configuration: 如果我使用“ WhatDidIScan”方法,则可以看到配置:

IocRegistry Scanner #1 Assemblies IocRegistry扫描仪#1程序集

  • Mmu.Ddws.Application, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null Mmu.Ddws.Application,版本= 1.0.0.0,文化=中性,PublicKeyToken =空

Conventions 约定

  • Default I[Name]/[Name] registration convention 默认的I [名称] / [名称]注册约定
  • Find and register all types implementing Mmu.Ddws.Application.Common.Mapping.IMapper`2 查找并注册实现Mmu.Ddws.Application.Common.Mapping.IMapper`2的所有类型

Yet, as soon as I try to get an instance of such a Mapper, I get the error it didn't find it. 但是,一旦我尝试获取此类Mapper的实例,就会收到找不到它的错误。

Interesting enough, if I'm registerering the Interfaces on my WebServices-Assembly, which is the starting point, via: 足够有趣的是,如果我要通过以下方法在WebServices-Assembly上注册接口(这是起点):

internal static class IocInitialization
{
    internal static IServiceProvider InitializeIoc(IServiceCollection services)
    {
        var container = new Container();

        container.Configure(
            config =>
            {
                config.Scan(
                    scan =>
                    {
                        scan.AssembliesFromApplicationBaseDirectory();
                        scan.LookForRegistries();
                        scan.WithDefaultConventions();
                        scan.AddAllTypesOf(typeof(IMapper<,>));
                    });

                config.Populate(services);
            });

        Debug.WriteLine(container.WhatDidIScan());
        var result = container.GetInstance<IServiceProvider>();
        return result;
    }
}

I get exactly the same convention: 我得到完全一样的约定:

Conventions 约定

  • StructureMap.Graph.FindRegistriesScanner StructureMap.Graph.FindRegistriesScanner
  • Default I[Name]/[Name] registration convention 默认的I [名称] / [名称]注册约定
  • Find and register all types implementing Mmu.Ddws.Application.Common.Mapping.IMapper`2 查找并注册实现Mmu.Ddws.Application.Common.Mapping.IMapper`2的所有类型

And yet, this way it works. 然而,这种方式有效。 I have the Interface and the Implementations in the Application-Assembly, therefore the most discussions resolving around Interfaces in different Assemblies, doesn't seem to fit here. 我在应用程序组装中拥有接口和实现,因此围绕不同组装中的接口进行的大多数讨论似乎都不适合这里。 So my best bet would be, that scanning the calling Assembly is kinda wrong, but I couldn't find any remarks regarding this? 因此,我最好的选择是,扫描调用方的程序集是不对的,但是我找不到关于此的任何评论?

有关详细信息和使用开放通用类型进行类型扫描的示例,请参见此内容: http : //structuremap.github.io/generics/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM