autofac with webapi controller registry issue

Dec 4 2019 9:51 PM
Hi All,
 
When i use WebApi with Autofac, every time i'm getting runtime issue that "An error occurred when trying to create a controller of type 'EmployeeController'. Make sure that the controller has a parameterless public constructor"
 
I'm using below autofac code in WebAPI global.asax
 
var builder = new ContainerBuilder();
var config = GlobalConfiguration.Configuration;
builder.RegisterApiControllers(Assembly.GetExecutingAssembly()); 
var container = builder.Build(); config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
 
Can any one asisst for this?

Answers (3)