[英]Structuremap and ASP.NET core
我正在使用ASP.NET核心,我正在尝试将结构图用于我的IoC,但我似乎遇到了一些问题。 当我编写一个直接在structuremap中的单元测试时,一切正常。 当我将配置打印到文件时,我可以看到我的设置确实正确地注册了所有内容。
然而,人口似乎给我带来了麻烦。
我正在尝试使用StructureMap.Microsoft.DependencyInjection但我在构建时遇到错误:
无法解析依赖关系结构图> = 4.4.0。
我在我的项目中安装了StructureMap 4.4.1,包括我将StructureMap.Microsoft.DependencyInjection库安装到(我的Web API项目)的项目。
所以,然后我将文件从github上的项目中取出并加载到我的解决方案中,并删除了nuget包,但由于某种原因它无法正常工作。
理想情况下,我宁愿使用nuget包来执行此操作,但是当我已经安装了实际的依赖项时,我从未遇到过依赖性问题。
编辑:更多细节
当我将container.WhatDoIHave()
的结果写入文件时,我的类都正确显示t0是structmap的一部分,但是当我运行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>();
}
将“StructureMap”包重命名为“structuremap”,似乎与NuGet套管有些奇怪的问题。
干杯:)
在StructureMap.Microsoft.DependencyInjection问题跟踪器上查看此问题:
依赖结构图> = 4.3.0无法解析 https://github.com/structuremap/StructureMap.Microsoft.DependencyInjection/issues/17
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.