From e25627db147f2299cccb55c95a40cb9536664ed2 Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Tue, 16 Nov 2010 12:00:36 -0800 Subject: [PATCH] Adding an IUnitOfWorkDependency lifecycle IUnitOfWork paints a component that it shared, but may only exist at per-request, -commandline, or -background task level The TransactionManager is a prime example of a component that would restrict itself to unit of work only This enables the ioc container to throw an exception when a singleton component depends directly or indirectly on something which it should not --HG-- branch : perf extra : rebase_source : bbe83ed7acc542e484c1b32ca81861dc07c1eb0e --- .../Environment/ShellBuilders/ShellContainerFactory.cs | 3 +++ src/Orchard/IDependency.cs | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/src/Orchard/Environment/ShellBuilders/ShellContainerFactory.cs b/src/Orchard/Environment/ShellBuilders/ShellContainerFactory.cs index c189ced00..bc79034ce 100644 --- a/src/Orchard/Environment/ShellBuilders/ShellContainerFactory.cs +++ b/src/Orchard/Environment/ShellBuilders/ShellContainerFactory.cs @@ -71,6 +71,9 @@ namespace Orchard.Environment.ShellBuilders { registration = registration.As(interfaceType); if (typeof(ISingletonDependency).IsAssignableFrom(interfaceType)) { registration = registration.InstancePerMatchingLifetimeScope("shell"); + } + else if (typeof(IUnitOfWorkDependency).IsAssignableFrom(interfaceType)) { + registration = registration.InstancePerMatchingLifetimeScope("work"); } else if (typeof(ITransientDependency).IsAssignableFrom(interfaceType)) { registration = registration.InstancePerDependency(); diff --git a/src/Orchard/IDependency.cs b/src/Orchard/IDependency.cs index 82262c5af..3f60961d1 100644 --- a/src/Orchard/IDependency.cs +++ b/src/Orchard/IDependency.cs @@ -14,12 +14,20 @@ namespace Orchard { public interface ISingletonDependency : IDependency { } + /// + /// Base interface for services that may *only* be instantiated in a unit of work. + /// This interface is used to guarantee they are not accidentally referenced by a singleton dependency. + /// + public interface IUnitOfWorkDependency : IDependency { + } + /// /// Base interface for services that are instantiated per usage. /// public interface ITransientDependency : IDependency { } + public abstract class Component : IDependency { protected Component() { Logger = NullLogger.Instance;