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 bet
For anyone who would be looking how to get AutoFac running below configuration allowed me to use it in beta6
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"
},
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>();
}
As mentioned by @peco make sure you have
using Autofac.Framework.DependencyInjection
And that got me going notime with AutoFac :) Hope this helps!