【问题标题】:Structuremap and ASP.NET core结构图和 ASP.NET 核心
【发布时间】:2016-11-07 04:05:58
【问题描述】:

我正在使用 ASP.NET 核心,我正在尝试为我的 IoC 使用结构映射,但我似乎遇到了一些问题。当我编写一个直接初始化结构映射的单元测试时,一切正常。当我将配置打印到文件中时,我可以看到我的设置确实正确注册了所有内容。

但是,人口似乎给我带来了麻烦。

我正在尝试使用StructureMap.Microsoft.DependencyInjection,但在构建时出现错误:

依赖结构映射 >= 4.4.0 无法解析。

我的项目中安装了 StructureMap 4.4.1,包括我将 StructureMap.Microsoft.DependencyInjection 库安装到的项目(我的 Web API 项目)。

然后,我从 github 上的项目中取出文件并将它们加载到我的解决方案中,并删除了 nuget 包,但由于某种原因它无法正常工作。

Here is a plunker with the relevant files

理想情况下,我宁愿使用 nuget 包来执行此操作,但是当我已经安装了实际依赖项时,我从未遇到过依赖项问题。

编辑:更多细节

当我将container.WhatDoIHave() 的结果写入文件时,我的类都正确显示为结构映射的一部分,但是当我运行container.AssertConfigurationIsValid(); 时,我收到关于@987654325 报告的正确定义的内容的错误@

这是我的配置方法的样子

    public IServiceProvider ConfigureIoC(IServiceCollection services)
    {
        var container = new Container();

        container.Configure(config =>
        {
            // scan the webapi to register all the controllers
            config.Scan(scan =>
            {
                scan.TheCallingAssembly();
                scan.WithDefaultConventions();
            });

            //this is an IoC configuration in another library that 
            //   ties together a bunch of class libraries so they 
            //   don't all have to be in my web project
            IoC.BootStrapper.Configure(config, "MembershipReboot");
        });

        System.IO.File.WriteAllText(@"C:\users\{me}\documents\structuremapTest.txt", container.WhatDoIHave());

        container.AssertConfigurationIsValid();

        //Populate the container using the service collection
        container.Populate(services);

        return container.GetInstance<IServiceProvider>();
    }

【问题讨论】:

    标签: c# asp.net-core structuremap


    【解决方案1】:

    将“StructureMap”包重命名为“structuremap”,这似乎是 NuGet 外壳的一些奇怪问题。

    干杯:)

    【讨论】:

      【解决方案2】:

      在 StructureMap.Microsoft.DependencyInjection 问题跟踪器上查看此问题:

      依赖结构映射 >= 4.3.0 无法解析 https://github.com/structuremap/StructureMap.Microsoft.DependencyInjection/issues/17

      【讨论】:

        猜你喜欢
        • 2020-11-17
        • 2017-03-12
        • 2018-10-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多