Skip to content

Commit

Permalink
feat: remove interface for IResolveRequestContext and re-add ResolveR…
Browse files Browse the repository at this point in the history
…equestContextBase defining all methods as abstract
  • Loading branch information
alsami committed Jul 26, 2020
1 parent 7ee38fb commit 3677371
Show file tree
Hide file tree
Showing 31 changed files with 103 additions and 97 deletions.
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "3.1.200",
"version": "3.1.302",
"rollForward": "latestFeature"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ public interface IDependencyTrackingResolveOperation : IResolveOperation
/// <see cref="CircularDependencyDetectorMiddleware" />,
/// hence it's internal.
/// </remarks>
SegmentedStack<IResolveRequestContext> RequestStack { get; }
SegmentedStack<ResolveRequestContextBase> RequestStack { get; }
}
}
4 changes: 2 additions & 2 deletions src/Autofac/Core/Resolving/IResolveOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public interface IResolveOperation
/// <summary>
/// Gets the active resolve request.
/// </summary>
IResolveRequestContext? ActiveRequestContext { get; }
ResolveRequestContextBase? ActiveRequestContext { get; }

/// <summary>
/// Gets the current lifetime scope of the operation; based on the most recently executed request.
Expand All @@ -24,7 +24,7 @@ public interface IResolveOperation
/// <summary>
/// Gets the set of all in-progress requests on the request stack.
/// </summary>
IEnumerable<IResolveRequestContext> InProgressRequests { get; }
IEnumerable<ResolveRequestContextBase> InProgressRequests { get; }

/// <summary>
/// Gets the <see cref="System.Diagnostics.DiagnosticListener" /> for the operation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private ActivatorErrorHandlingMiddleware()
public PipelinePhase Phase => PipelinePhase.Activation;

/// <inheritdoc />
public void Execute(IResolveRequestContext context, Action<IResolveRequestContext> next)
public void Execute(ResolveRequestContextBase context, Action<ResolveRequestContextBase> next)
{
try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public CircularDependencyDetectorMiddleware(int maxResolveDepth)
public PipelinePhase Phase => PipelinePhase.ResolveRequestStart;

/// <inheritdoc/>
public void Execute(IResolveRequestContext context, Action<IResolveRequestContext> next)
public void Execute(ResolveRequestContextBase context, Action<ResolveRequestContextBase> next)
{
if (!(context.Operation is IDependencyTrackingResolveOperation dependencyTrackingResolveOperation))
{
Expand Down Expand Up @@ -121,7 +121,7 @@ public void Execute(IResolveRequestContext context, Action<IResolveRequestContex
/// <inheritdoc/>
public override string ToString() => nameof(CircularDependencyDetectorMiddleware);

private static string CreateDependencyGraphTo(IComponentRegistration registration, IEnumerable<IResolveRequestContext> requestStack)
private static string CreateDependencyGraphTo(IComponentRegistration registration, IEnumerable<ResolveRequestContextBase> requestStack)
{
if (registration == null) throw new ArgumentNullException(nameof(registration));
if (requestStack == null) throw new ArgumentNullException(nameof(requestStack));
Expand Down
6 changes: 3 additions & 3 deletions src/Autofac/Core/Resolving/Middleware/CoreEventMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ namespace Autofac.Core.Resolving.Middleware
/// </summary>
public class CoreEventMiddleware : IResolveMiddleware
{
private readonly Action<IResolveRequestContext, Action<IResolveRequestContext>> _callback;
private readonly Action<ResolveRequestContextBase, Action<ResolveRequestContextBase>> _callback;

/// <summary>
/// Initializes a new instance of the <see cref="CoreEventMiddleware"/> class.
/// </summary>
/// <param name="eventType">The type of event.</param>
/// <param name="phase">The phase of the pipeine at which the event runs.</param>
/// <param name="callback">The middleware callback to process the event.</param>
internal CoreEventMiddleware(ResolveEventType eventType, PipelinePhase phase, Action<IResolveRequestContext, Action<IResolveRequestContext>> callback)
internal CoreEventMiddleware(ResolveEventType eventType, PipelinePhase phase, Action<ResolveRequestContextBase, Action<ResolveRequestContextBase>> callback)
{
Phase = phase;
_callback = callback;
Expand All @@ -35,7 +35,7 @@ internal CoreEventMiddleware(ResolveEventType eventType, PipelinePhase phase, Ac
public override string ToString() => EventType.ToString();

/// <inheritdoc/>
public void Execute(IResolveRequestContext context, Action<IResolveRequestContext> next)
public void Execute(ResolveRequestContextBase context, Action<ResolveRequestContextBase> next)
{
_callback(context, next);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Autofac/Core/Resolving/Middleware/DelegateMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ namespace Autofac.Core.Resolving.Middleware
internal class DelegateMiddleware : IResolveMiddleware
{
private readonly string _descriptor;
private readonly Action<IResolveRequestContext, Action<IResolveRequestContext>> _callback;
private readonly Action<ResolveRequestContextBase, Action<ResolveRequestContextBase>> _callback;

/// <summary>
/// Initializes a new instance of the <see cref="DelegateMiddleware"/> class.
/// </summary>
/// <param name="descriptor">The middleware description.</param>
/// <param name="phase">The pipeline phase.</param>
/// <param name="callback">The callback to execute.</param>
public DelegateMiddleware(string descriptor, PipelinePhase phase, Action<IResolveRequestContext, Action<IResolveRequestContext>> callback)
public DelegateMiddleware(string descriptor, PipelinePhase phase, Action<ResolveRequestContextBase, Action<ResolveRequestContextBase>> callback)
{
_descriptor = descriptor ?? throw new ArgumentNullException(nameof(descriptor));
Phase = phase;
Expand All @@ -53,7 +53,7 @@ public DelegateMiddleware(string descriptor, PipelinePhase phase, Action<IResolv
public PipelinePhase Phase { get; }

/// <inheritdoc />
public void Execute(IResolveRequestContext context, Action<IResolveRequestContext> next)
public void Execute(ResolveRequestContextBase context, Action<ResolveRequestContextBase> next)
{
_callback(context, next);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private DisposalTrackingMiddleware()
public PipelinePhase Phase => PipelinePhase.Activation;

/// <inheritdoc />
public void Execute(IResolveRequestContext context, Action<IResolveRequestContext> next)
public void Execute(ResolveRequestContextBase context, Action<ResolveRequestContextBase> next)
{
next(context);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private RegistrationPipelineInvokeMiddleware()
public PipelinePhase Phase => PipelinePhase.ServicePipelineEnd;

/// <inheritdoc/>
public void Execute(IResolveRequestContext context, Action<IResolveRequestContext> next)
public void Execute(ResolveRequestContextBase context, Action<ResolveRequestContextBase> next)
{
context.Registration.ResolvePipeline.Invoke(context);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private ScopeSelectionMiddleware()
public PipelinePhase Phase => PipelinePhase.ScopeSelection;

/// <inheritdoc/>
public void Execute(IResolveRequestContext context, Action<IResolveRequestContext> next)
public void Execute(ResolveRequestContextBase context, Action<ResolveRequestContextBase> next)
{
try
{
Expand Down
2 changes: 1 addition & 1 deletion src/Autofac/Core/Resolving/Middleware/SharingMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ internal class SharingMiddleware : IResolveMiddleware
public PipelinePhase Phase => PipelinePhase.Sharing;

/// <inheritdoc />
public void Execute(IResolveRequestContext context, Action<IResolveRequestContext> next)
public void Execute(ResolveRequestContextBase context, Action<ResolveRequestContextBase> next)
{
var registration = context.Registration;
var decoratorRegistration = context.DecoratorTarget;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private StartableMiddleware()
public PipelinePhase Phase => PipelinePhase.Activation;

/// <inheritdoc />
public void Execute(IResolveRequestContext context, Action<IResolveRequestContext> next)
public void Execute(ResolveRequestContextBase context, Action<ResolveRequestContextBase> next)
{
next(context);

Expand Down
2 changes: 1 addition & 1 deletion src/Autofac/Core/Resolving/Pipeline/IResolveMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ public interface IResolveMiddleware
/// </summary>
/// <param name="context">The context for the resolve request.</param>
/// <param name="next">The method to invoke to continue the pipeline execution; pass this method the <paramref name="context"/> argument.</param>
void Execute(IResolveRequestContext context, Action<IResolveRequestContext> next);
void Execute(ResolveRequestContextBase context, Action<ResolveRequestContextBase> next);
}
}
2 changes: 1 addition & 1 deletion src/Autofac/Core/Resolving/Pipeline/IResolvePipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ public interface IResolvePipeline
/// Invoke the pipeline to the end, or until an exception is thrown.
/// </summary>
/// <param name="context">The request context.</param>
void Invoke(IResolveRequestContext context);
void Invoke(ResolveRequestContextBase context);
}
}
2 changes: 1 addition & 1 deletion src/Autofac/Core/Resolving/Pipeline/PipelinePhase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public enum PipelinePhase : int

/// <summary>
/// This phase runs just before Activation, is the recommended point at which the resolve parameters should be replaced
/// (using <see cref="IResolveRequestContext.ChangeParameters(IEnumerable{Parameter})"/>).
/// (using <see cref="ResolveRequestContextBase.ChangeParameters(IEnumerable{Parameter})"/>).
/// </summary>
ParameterSelection = 250,

Expand Down
6 changes: 3 additions & 3 deletions src/Autofac/Core/Resolving/Pipeline/ResolvePipelineBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ internal class ResolvePipelineBuilder : IResolvePipelineBuilder, IEnumerable<IRe
/// <summary>
/// Termination action for the end of pipelines.
/// </summary>
private static readonly Action<IResolveRequestContext> _terminateAction = ctxt => { };
private static readonly Action<ResolveRequestContextBase> _terminateAction = ctxt => { };

private MiddlewareDeclaration? _first;
private MiddlewareDeclaration? _last;
Expand Down Expand Up @@ -262,9 +262,9 @@ private static IResolvePipeline BuildPipeline(MiddlewareDeclaration? lastDecl)
{
// When we build, we go through the set and construct a single call stack, starting from the end.
var current = lastDecl;
Action<IResolveRequestContext>? currentInvoke = _terminateAction;
Action<ResolveRequestContextBase>? currentInvoke = _terminateAction;

Action<IResolveRequestContext> Chain(Action<IResolveRequestContext> next, IResolveMiddleware stage)
Action<ResolveRequestContextBase> Chain(Action<ResolveRequestContextBase> next, IResolveMiddleware stage)
{
var stagePhase = stage.Phase;

Expand Down
34 changes: 17 additions & 17 deletions src/Autofac/Core/Resolving/Pipeline/ResolveRequestContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace Autofac.Core.Resolving.Pipeline
/// <summary>
/// Context area for a resolve request.
/// </summary>
internal class ResolveRequestContext : IResolveRequestContext
internal class ResolveRequestContext : ResolveRequestContextBase
{
private readonly ResolveRequest _resolveRequest;
private object? _instance;
Expand Down Expand Up @@ -63,59 +63,59 @@ internal ResolveRequestContext(
}

/// <inheritdoc />
public IResolveOperation Operation { get; }
public override IResolveOperation Operation { get; }

/// <inheritdoc />
public ISharingLifetimeScope ActivationScope { get; private set; }
public override ISharingLifetimeScope ActivationScope { get; protected set; }

/// <inheritdoc />
public IComponentRegistration Registration => _resolveRequest.Registration;
public override IComponentRegistration Registration => _resolveRequest.Registration;

/// <inheritdoc />
public Service Service => _resolveRequest.Service;
public override Service Service => _resolveRequest.Service;

/// <inheritdoc />
public IComponentRegistration? DecoratorTarget => _resolveRequest.DecoratorTarget;
public override IComponentRegistration? DecoratorTarget => _resolveRequest.DecoratorTarget;

/// <inheritdoc />
[DisallowNull]
public object? Instance
public override object? Instance
{
get => _instance;
set => _instance = value ?? throw new ArgumentNullException(nameof(value));
}

/// <inheritdoc />
public bool NewInstanceActivated => Instance is object && PhaseReached == PipelinePhase.Activation;
public override bool NewInstanceActivated => Instance is object && PhaseReached == PipelinePhase.Activation;

/// <inheritdoc />
public DiagnosticListener DiagnosticSource { get; }
public override DiagnosticListener DiagnosticSource { get; }

/// <inheritdoc />
public IEnumerable<Parameter> Parameters { get; private set; }
public override IEnumerable<Parameter> Parameters { get; protected set; }

/// <inheritdoc />
public PipelinePhase PhaseReached { get; set; }
public override PipelinePhase PhaseReached { get; set; }

/// <inheritdoc />
public IComponentRegistry ComponentRegistry => ActivationScope.ComponentRegistry;
public override IComponentRegistry ComponentRegistry => ActivationScope.ComponentRegistry;

/// <inheritdoc />
public event EventHandler<ResolveRequestCompletingEventArgs>? RequestCompleting;
public override event EventHandler<ResolveRequestCompletingEventArgs>? RequestCompleting;

/// <inheritdoc />
public DecoratorContext? DecoratorContext { get; set; }
public override DecoratorContext? DecoratorContext { get; set; }

/// <inheritdoc />
public void ChangeScope(ISharingLifetimeScope newScope) =>
public override void ChangeScope(ISharingLifetimeScope newScope) =>
ActivationScope = newScope ?? throw new ArgumentNullException(nameof(newScope));

/// <inheritdoc />
public void ChangeParameters(IEnumerable<Parameter> newParameters) =>
public override void ChangeParameters(IEnumerable<Parameter> newParameters) =>
Parameters = newParameters ?? throw new ArgumentNullException(nameof(newParameters));

/// <inheritdoc />
public object ResolveComponent(ResolveRequest request) =>
public override object ResolveComponent(ResolveRequest request) =>
Operation.GetOrCreateInstance(ActivationScope, request);

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,33 @@
namespace Autofac.Core.Resolving.Pipeline
{
/// <inheritdoc />
public interface IResolveRequestContext : IComponentContext
public abstract class ResolveRequestContextBase : IComponentContext
{
/// <summary>
/// Gets a reference to the owning resolve operation (which might emcompass multiple nested requests).
/// </summary>
IResolveOperation Operation { get; }
public abstract IResolveOperation Operation { get; }

/// <summary>
/// Gets the lifetime scope that will be used for the activation of any components later in the pipeline.
/// Gets or sets the lifetime scope that will be used for the activation of any components later in the pipeline.
/// Avoid resolving instances directly from this scope; they will not be traced as part of the same operation.
/// </summary>
ISharingLifetimeScope ActivationScope { get; }
public abstract ISharingLifetimeScope ActivationScope { get; protected set; }

/// <summary>
/// Gets the component registration that is being resolved in the current request.
/// </summary>
IComponentRegistration Registration { get; }
public abstract IComponentRegistration Registration { get; }

/// <summary>
/// Gets the service that is being resolved in the current request.
/// </summary>
Service Service { get; }
public abstract Service Service { get; }

/// <summary>
/// Gets the target registration for decorator requests.
/// </summary>
IComponentRegistration? DecoratorTarget { get; }
public abstract IComponentRegistration? DecoratorTarget { get; }

/// <summary>
/// Gets or sets the instance that will be returned as the result of the resolve request.
Expand All @@ -42,51 +42,57 @@ public interface IResolveRequestContext : IComponentContext
/// whether the object here was a newly activated instance, or a shared instance previously activated.
/// </summary>
[DisallowNull]
object? Instance { get; set; }
public abstract object? Instance { get; set; }

/// <summary>
/// Gets a value indicating whether the resolved <see cref="Instance"/> is a new instance of a component has been activated during this request,
/// or an existing shared instance that has been retrieved.
/// </summary>
bool NewInstanceActivated { get; }
public abstract bool NewInstanceActivated { get; }

/// <summary>
/// Gets the <see cref="System.Diagnostics.DiagnosticListener"/> to which trace events should be written.
/// </summary>
DiagnosticListener DiagnosticSource { get; }
public abstract DiagnosticListener DiagnosticSource { get; }

/// <summary>
/// Gets the current resolve parameters. These can be changed using the <see cref="ChangeParameters(IEnumerable{Parameter})"/> method.
/// Gets or sets the current resolve parameters. These can be changed using the <see cref="ChangeParameters(IEnumerable{Parameter})"/> method.
/// </summary>
IEnumerable<Parameter> Parameters { get; }
public abstract IEnumerable<Parameter> Parameters { get; protected set; }

/// <summary>
/// Gets or sets the phase of the pipeline reached by this request.
/// </summary>
PipelinePhase PhaseReached { get; set; }
public abstract PipelinePhase PhaseReached { get; set; }

/// <summary>
/// Gets or sets the active decorator context for the request.
/// </summary>
DecoratorContext? DecoratorContext { get; set; }
public abstract DecoratorContext? DecoratorContext { get; set; }

/// <summary>
/// Provides an event that will fire when the current request completes.
/// Requests will only be considered 'complete' when the overall <see cref="IResolveOperation"/> is completing.
/// </summary>
event EventHandler<ResolveRequestCompletingEventArgs>? RequestCompleting;
public abstract event EventHandler<ResolveRequestCompletingEventArgs>? RequestCompleting;

/// <summary>
/// Use this method to change the <see cref="ISharingLifetimeScope"/> that is used in this request. Changing this scope will
/// also change the <see cref="IComponentRegistry"/> available in this context.
/// </summary>
/// <param name="newScope">The new lifetime scope.</param>
void ChangeScope(ISharingLifetimeScope newScope);
public abstract void ChangeScope(ISharingLifetimeScope newScope);

/// <summary>
/// Change the set of parameters being used in the processing of this request.
/// </summary>
/// <param name="newParameters">The new set of parameters.</param>
void ChangeParameters(IEnumerable<Parameter> newParameters);
public abstract void ChangeParameters(IEnumerable<Parameter> newParameters);

/// <inheritdoc/>
public abstract IComponentRegistry ComponentRegistry { get; }

/// <inheritdoc/>
public abstract object ResolveComponent(ResolveRequest request);
}
}
Loading

0 comments on commit 3677371

Please sign in to comment.