Autofac, ASP.NET and HttpRequestScoped integration

I previously asked a question here about autorun not deleting my objects when the HTTP request ends. Now I think I have a big problem, because there is evidence that it serves a SAME object-to-request request. Again, I use their instructions here . My test is a little more complicated because I use the delegate syntax to create the object, but I think I put it for the request for life. Global.asax.cs:

protected void Application_Start(object sender, EventArgs e)
{
    ...
    var builder = new Autofac.Builder.ContainerBuilder();
    builder.Register<IDBConnectionSelector>(
            (c) => new CachingDBConnections(ConstructorArgs...))
        .HttpRequestScoped();

    var container = builder.Build();
    _containerProvider = new ContainerProvider(container);
}
public IContainerProvider ContainerProvider
{
    get { return _containerProvider; }
}
static IContainerProvider _containerProvider;

My intention here is to register an IDBConnectionSelector to get specific types of CachingDBConnections created using a special constructor, but with an HTTP request scope.

CachingDBConnections , , , , NEW .

? ?

+3
2

!

WRONG - - , -.

D'!

+1

( IoC) , .

.

A → B → C

A "factory" , B "singleton", C "factory" , A B, C.

C , A, B "factory" .

? ?

+2

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


All Articles