结构图和 ASP.NET 核心
Structuremap and ASP.NET core
我正在使用 ASP.NET 核心,我正在尝试为我的 IoC 使用结构图,但我似乎遇到了一些问题。当我编写直接初始化结构图的单元测试时,一切正常。当我将配置打印到文件时,我可以看到我的设置确实正确地注册了所有内容。
但是,填充似乎给我带来了麻烦。
我正在尝试使用 StructureMap.Microsoft.DependencyInjection,但在构建时出现错误:
The dependency structuremap >= 4.4.0 could not be resolved.
我的项目中安装了 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>();
}
将 "StructureMap" 包重命名为 "structuremap",似乎 NuGet 外壳出现了一些奇怪的问题。
干杯:)
在 StructureMap.Microsoft.DependencyInjection 问题跟踪器上查看此问题:
依赖结构图 >= 4.3.0 无法解析
https://github.com/structuremap/StructureMap.Microsoft.DependencyInjection/issues/17
我正在使用 ASP.NET 核心,我正在尝试为我的 IoC 使用结构图,但我似乎遇到了一些问题。当我编写直接初始化结构图的单元测试时,一切正常。当我将配置打印到文件时,我可以看到我的设置确实正确地注册了所有内容。
但是,填充似乎给我带来了麻烦。
我正在尝试使用 StructureMap.Microsoft.DependencyInjection,但在构建时出现错误:
The dependency structuremap >= 4.4.0 could not be resolved.
我的项目中安装了 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>();
}
将 "StructureMap" 包重命名为 "structuremap",似乎 NuGet 外壳出现了一些奇怪的问题。
干杯:)
在 StructureMap.Microsoft.DependencyInjection 问题跟踪器上查看此问题:
依赖结构图 >= 4.3.0 无法解析 https://github.com/structuremap/StructureMap.Microsoft.DependencyInjection/issues/17