Search code examples
nhibernateorchardcmsdisposeautofac

How does Orchard dispose of objects?


I am relatively new to Orchard. I know it uses Autofac for dependency injection and NHibernate is the ORM. I've looked through other Modules that come with the vanilla Orchard install and I do not see any standard way that objects are disposed of. I know Autofac is used to manage the lifetime of objects, but without diving deep into the Orchard code it is hard to tell how it is done. I have created Records for my Module that I use to query the database, and I am particularly interested in knowing how that connection is disposed of.

Thanks in advance.


Solution

  • See http://docs.orchardproject.net/Documentation/How-Orchard-works#DependencyInjection

    Most objects implement IDependency, for which the scope/lifetime is the request. A few objects are shorter-lived by virtue of their implementing ITransientDependency. Those objects are created anew each time they are requested, and disappear with their scope, the code block that uses them. Some other objects, by implementing ISingletonDependency, have the same lifetime as the shell, which is the same as the tenant. Those persist in one copy per tenant, and only die with the app pool.