获取autofac与mvc6 beta5的工作 [英] Getting autofac to work with mvc6 beta5
问题描述
我试图让autofac与我工作的一个mvc6应用程序的工作。我发现本博客文章似乎有点过时了。它看起来像使用beta3版位的
I am trying to get autofac working with an mvc6 application I am working on. I found this blog article however it seems to be a little dated. It looks like its using the beta3 bits
我用这CLR版本
1.0.0-beta5-11911
1.0.0-beta5-11911
我的项目有以下2引用
"Autofac": "4.0.0-alpha2",
"Autofac.Dnx": "4.0.0-alpha2",
在文章是关于如何修改startup.cs会谈
Within the article is talks about how to modify the startup.cs
// Create the Autofac container builder.
var builder = new Autofac.ContainerBuilder();
// Add any Autofac modules or registrations.
builder.RegisterModule(new AutofacModule());
// Populate the services.
builder.Populate(services);
// Build the container.
var container = builder.Build();
return container.Resolve<IServiceProvider>();
以上code抱怨 builder.Populate(服务);
给我一个错误
该型'IServiceDescriptor'在未引用的程序集的定义。您必须添加一个引用程序集Microsoft.Framework.DependencyInjection.IServiceDescriptor,版本= 0.0.0.0,文化=中立,公钥=空'。
The type 'IServiceDescriptor' is defined in an assembly that is not referenced. You must add a reference to assembly 'Microsoft.Framework.DependencyInjection.IServiceDescriptor, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.
从我研究它看起来像BETA4 DependencyInjection.IserviceDescriptor被删除。
From me research it looks like in beta4 DependencyInjection.IserviceDescriptor was removed.
有没有其他人设法autofac与最新beta5的位工作?
Has anyone else managed to get autofac working with the latest beta5 bits?
推荐答案
对于任何人谁是寻找如何让AutoFac运行下面的配置让我在beta6使用它
For anyone who would be looking how to get AutoFac running below configuration allowed me to use it in beta6
下面是project.json的段
Below is snippet of project.json
"dependencies": {
"Autofac": "4.0.0-beta6-110",
"Autofac.Framework.DependencyInjection": "4.0.0-beta6-110",
"Microsoft.AspNet.Mvc": "6.0.0-beta6",
"Microsoft.AspNet.Server.IIS": "1.0.0-beta6",
"Microsoft.AspNet.Server.WebListener": "1.0.0-beta6",
"Microsoft.AspNet.StaticFiles": "1.0.0-beta6"
},
然后startup.cs的一部分
And then part of startup.cs
public IServiceProvider ConfigureServices(IServiceCollection services)
{
services.AddMvc();
//create Autofac container build
var builder = new ContainerBuilder();
//populate the container with services here..
builder.RegisterType<DemoService>().As<IProjectDemo>();
builder.Populate(services);
//build container
var container = builder.Build();
//return service provider
return container.ResolveOptional<IServiceProvider>();
}
正如@peco提到请确保您有
As mentioned by @peco make sure you have
using Autofac.Framework.DependencyInjection
这让我去notime与AutoFac :)希望这有助于!
And that got me going notime with AutoFac :) Hope this helps!
这篇关于获取autofac与mvc6 beta5的工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!