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
This commit is contained in:
Louis DeJardin
2010-11-16 12:00:36 -08:00
parent 75257a4585
commit e25627db14
2 changed files with 11 additions and 0 deletions

View File

@@ -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();

View File

@@ -14,12 +14,20 @@ namespace Orchard {
public interface ISingletonDependency : IDependency {
}
/// <summary>
/// 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.
/// </summary>
public interface IUnitOfWorkDependency : IDependency {
}
/// <summary>
/// Base interface for services that are instantiated per usage.
/// </summary>
public interface ITransientDependency : IDependency {
}
public abstract class Component : IDependency {
protected Component() {
Logger = NullLogger.Instance;