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?

Rajanikant HawaldarRank #110 · 20.2K reputationPosted Dec 4, 2019, 5:17 PM EST
Ramachandran MRank #2,660 · 522 reputationPosted Dec 4, 2019, 6:39 PM EST
// register types ending with 'Service' as their interfaces
builder.RegisterAssemblyTypes(AppDomain.CurrentDomain.GetAssemblies())
.Where(t => t.Name.EndsWith("Service"))
.AsImplementedInterfaces()
.InstancePerRequest();
Prasanna Kumar Tekumudi32 reputationPosted Jan 15, 2020, 7:02 PM EST