What is the disadvantage of using an instance of InstancePerHttpRequest instead of an instance of InstancePerApiRequest in MVC and the web API in the same project?

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.

!

+4
1

InstancePerApiRequest InstancePerHttpRequest : register InstancePerLifetimeScope " ". InstancePerMatchingLifetimeScope("AutofacWebRequest").

-, WebAPI MVC-, . . , , , " " . - / "-", ASP.NET, , , - .

.

, (, InstancePerApiControllerType) , " ".

+7

Source: https://habr.com/ru/post/1524370/


All Articles