What is InstancePerLifetimeScope in Autofac?

Can someone explain in plain English what lines of code where I put the question marks? Or maybe point me to an article that covers this. This code is for registering dependencies in an autofac container

var builder = new Autofac.ContainerBuilder(); builder.Register<NHibernateInstance>(c => new NHibernateInstance(ConnString, false)) .InstancePerDependency();//????? builder.Register(c => c.Resolve<NHibernateInstance>() .GetFactory().OpenSession()) .As<ISession>() .InstancePerLifetimeScope(); //-----????? 
+6
source share
1 answer

This is a dependency injection container. Autofac.ContainerBuilder gets a new container or logger that you could tell.

builder.Register<NHibernateInstance> states that when building an NHibernateInstance during the recovery phase (i.e. retrieving an instance from the container) this is how it should be built.

The last line indicates that when NHibernateInstance is OpenSession method should be called once during the lifetime of the object.

+3
source

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


All Articles