我正在關注洋蔥體系結構並在依賴項解析項目中使用simple injector
。這裏是我的架構:簡單注射器依賴性解決方案錯誤 - 無法加載文件或程序集System.Web.Http
1-Core
- Domain Classes
- Repository Interfaces
- Service Interfaces
2-Infrastructure
- Data
- Dependency Resolution
- Repository Interfaces Implementation
- Service Interfaces Implementation
3-WebApi
- Web Api Project
4-WebClient
- My AngularJs App
5-Test
- Test Project
StartUp.cs
public partial class Startup
{
public void Configuration(IAppBuilder app)
{
// Here I am getting error at runtime.
SimpleInjectorInitializer.Initialize(app);
ConfigureAuth(app);
}
}
SimpleInjectorInitializer.Initialize
public static Container Initialize(IAppBuilder app)
{
var container = GetInitializeContainer(app);
// This is an extension method from the integration package.
container.RegisterWebApiControllers(GlobalConfiguration.Configuration);
container.Verify();
GlobalConfiguration.Configuration.DependencyResolver =
new SimpleInjectorWebApiDependencyResolver(container);
return container;
}
在這裏,我添加引用,從項目的WebAPI採取System.Web, System.Web.Http, System.Web.Http.Host
。
我把我的DependencyResolution項目的輸出路徑放到WebApi bin中,並在web.config
中設置owinstart的值。
這裏是我得到的錯誤:
型「System.IO.FileLoadException」發生在 Infrastructure.DependencyResolution.dll但在用戶 代碼
其他沒有處理的例外信息:無法加載文件或程序集 'System.Web.Http,Version = 4.0.0.0,Culture = neutral, PublicKeyToken = 31bf3856ad364e35'或其依賴項之一。位於程序集清單定義中的 與程序集 的引用不匹配。 (異常來自HRESULT:0x80131040)
編輯:
這裏是App.Config中:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security.Cookies" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
我也試過這個。不工作。 –
在我的情況下,SimpleInjector正確添加了System.Web.Http的程序集標識符 - 我必須刪除'bin'和'obj'文件夾,以便它使用最新的web.config。 –