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?
Prasanna Kumar TekumudiPosted Jan 16, 2020, 12:02 AM
Ramachandran MPosted Dec 4, 2019, 11:39 PM
// register types ending with 'Service' as their interfaces
builder.RegisterAssemblyTypes(AppDomain.CurrentDomain.GetAssemblies())
.Where(t => t.Name.EndsWith("Service"))
.AsImplementedInterfaces()
.InstancePerRequest();
Rajanikant HawaldarPosted Dec 4, 2019, 10:17 PM