I have a WebForms project with an Mvc Area.
I have two methods in the Application_Start of the Global.asax.cs to register services with Autofac Dependency Injection respectively;
private void WebFormsContainer()
{
var webFormsContainer = new ContainerBuilder();
webFormsContainer.RegisterAssemblyTypes(typeof(CompanyService).Assembly)
.Where(s => s.Name.EndsWith("Service"))
.AsImplementedInterfaces().InstancePerRequest();
_containerProvider = new ContainerProvider(webFormsContainer.Build());
}
and also,
private void MvcContainer()
{
var builder = new ContainerBuilder();
builder.RegisterControllers(Assembly.GetExecutingAssembly());
builder.RegisterAssemblyTypes(typeof(CompanyService).Assembly)
.Where(s => s.Name.EndsWith("Service"))
.AsImplementedInterfaces().InstancePerRequest();
IContainer container = builder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
}
The WebForms injection appears to work but when I try the Mvc part of the app I get the error;
No parameterless constructor defined for this object.
Question is how do I set up Autofac for MVC areas in a Webforms app?