My application exactly matches the default template for the VS 2013 Web API. Basically, Web API 2 is for the API, and MVC 5 is for the documentation.
I am using Autofac , and so far it works fine. Below is a version with a smaller version of what I have -
var builder = new ContainerBuilder();
var assemblies = Assembly.GetExecutingAssembly();
builder.RegisterControllers(assemblies);
builder.RegisterApiControllers(assemblies);
builder.RegisterType<MyService>().As<IMyService>()
.InstancePerHttpRequest();
var apiResolver = new AutofacWebApiDependencyResolver(container);
GlobalConfiguration.Configuration.DependencyResolver = apiResolver;
var mvcResolver = new AutofacDependencyResolver(container);
DependencyResolver.SetResolver(mvcResolver);
So far, InstancePerHttpRequest works for both MVC and Web API.
Question
I am wondering how to use InstancePerHttpRequest instead of InstancePerApiRequest , so I won’t be surprised if I encounter a problem in the future.
question, .
. SO, , MVC Web API . - MVC , MVC.
!