mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
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:
@@ -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();
|
||||
|
@@ -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;
|
||||
|
Reference in New Issue
Block a user