Structuremap和ASP.NET核心

时间:2016-11-07 04:05:58

标签: c# asp.net-core structuremap

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

然而,人们似乎在给我带来麻烦。

我正在尝试使用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()的结果写入文件时,我的类都正确显示t0是结构图的一部分,但是当我运行container.AssertConfigurationIsValid();时,我收到的错误是关于正确定义为由WhatDoIHave()报告

这是我的配置方法的样子

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

2 个答案:

答案 0 :(得分:3)

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

干杯:)

答案 1 :(得分:0)

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

无法解析依赖关系结构图&gt; = 4.3.0 https://github.com/structuremap/StructureMap.Microsoft.DependencyInjection/issues/17

相关问题