You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Support for pooled instance lifetime scopes in Autofac dependency injection.
Autofac can help you implement a pool of components in your application without you having to write your
own pooling implementation, and making these pooled components feel more natural in the world of DI.
Please file issues and pull requests for this package in this repository rather than in the Autofac core repo.
Once you've added a reference to the Autofac.Pooling package, you can start using
the new PooledInstancePerLifetimeScope and PooledInstancePerMatchingLifetimeScope
methods:
varbuilder=newContainerBuilder();builder.RegisterType<MyCustomConnection>().As<ICustomConnection>().PooledInstancePerLifetimeScope();varcontainer=builder.Build();using(varscope=container.BeginLifetimeScope()){// Creates a new instance of MyCustomConnectionvarinstance=scope.Resolve<ICustomConnection>();instance.DoSomething();}// When the scope ends, the instance of MyCustomConnection// is returned to the pool, rather than being disposed.using(varscope2=container.BeginLifetimeScope()){// Does **not** create a new instance, but instead gets the // previous instance from the pool.varinstance=scope.Resolve<ICustomConnection>();instance.DoSomething();}// Instance gets returned back to the pool again at the // end of the lifetime scope.