-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support nested redirects with call constraints (#70)
- Loading branch information
Showing
7 changed files
with
190 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,63 @@ | ||
using System; | ||
using System.Linq.Expressions; | ||
|
||
namespace DivertR | ||
{ | ||
/// <summary> | ||
/// A builder interface for providing nested register actions on parent registrations. | ||
/// Nested registrations can be used to intercept and redirect inner services created outside the dependency injection container e.g. from factories. | ||
/// </summary> | ||
public interface INestedRegisterBuilder | ||
public interface INestedRegisterBuilder<TTarget> where TTarget : class? | ||
{ | ||
/// <summary> | ||
/// Add a nested registration to redirect calls from the parent registration with return type <typeparamref name="TReturn"/> | ||
/// by proxying instances returned from parent methods via an <see cref="IRedirect{TReturn}"/>. | ||
/// A corresponding <see cref="IRedirect{TReturn}"/> is created and added to the underlying <see cref="IRedirectSet"/>. | ||
/// The returned instances are proxied by inserting a <see cref="IVia"/> on the <see cref="IRedirect{TReturn}"/> that is persistent, i.e. remains after reset. | ||
/// Redirect calls from the parent registration with return type <typeparamref name="TReturn"/> by proxying instances returned from parent methods via an <see cref="IRedirect{TReturn}"/>. | ||
/// The returned instances are proxied by inserting a persistent <see cref="IVia"/> on the <see cref="IRedirect{TReturn}"/>. | ||
/// </summary> | ||
/// <param name="registerAction">Optional nested register action.</param> | ||
/// <typeparam name="TReturn">The return type of calls to redirect.</typeparam> | ||
/// <returns>This <see cref="INestedRegisterBuilder"/> instance.</returns> | ||
/// <returns>This <see cref="INestedRegisterBuilder{TTarget}"/> instance.</returns> | ||
/// <exception cref="DiverterException">Thrown if a nested <see cref="IRedirect{TReturn}"/> has already been registered on the parent with matching <typeparamref name="TReturn"/> type and default <see cref="RedirectId.Name" />.</exception> | ||
INestedRegisterBuilder ThenRegister<TReturn>(Action<INestedRegisterBuilder>? registerAction = null) where TReturn : class?; | ||
INestedRegisterBuilder<TTarget> ThenRedirect<TReturn>(Action<INestedRegisterBuilder<TReturn>>? registerAction = null) where TReturn : class?; | ||
|
||
/// <summary> | ||
/// Add a nested registration to redirect calls from the parent registration with return type <typeparamref name="TReturn"/> | ||
/// by proxying instances returned from parent methods via an <see cref="IRedirect{TReturn}"/>. | ||
/// A corresponding <see cref="IRedirect{TReturn}"/> is created and added to the underlying <see cref="IRedirectSet"/>. | ||
/// The returned instances are proxied by inserting a <see cref="IVia"/> on the <see cref="IRedirect{TReturn}"/> that is persistent, i.e. remains after reset. | ||
/// Redirect calls from the parent registration with return type <typeparamref name="TReturn"/> by proxying instances returned from parent methods via an <see cref="IRedirect{TReturn}"/>. | ||
/// The returned instances are proxied by inserting a persistent <see cref="IVia"/> on the <see cref="IRedirect{TReturn}"/>. | ||
/// </summary> | ||
/// <param name="name">Specify the <see cref="DivertR.RedirectId.Name" /> of the returned <see cref="IRedirect{TReturn}"/>.</param> | ||
/// <param name="registerAction">Optional nested register action.</param> | ||
/// <typeparam name="TReturn">The return type of calls to redirect.</typeparam> | ||
/// <returns>This <see cref="INestedRegisterBuilder"/> instance.</returns> | ||
/// <returns>This <see cref="INestedRegisterBuilder{TTarget}"/> instance.</returns> | ||
/// <exception cref="DiverterException">Thrown if a nested <see cref="IRedirect{TReturn}"/> has already been registered on the parent with matching <typeparamref name="TReturn"/> type and <paramref name="name"/>.</exception> | ||
INestedRegisterBuilder ThenRegister<TReturn>(string? name, Action<INestedRegisterBuilder>? registerAction = null) where TReturn : class?; | ||
INestedRegisterBuilder<TTarget> ThenRedirect<TReturn>(string? name, Action<INestedRegisterBuilder<TReturn>>? registerAction = null) where TReturn : class?; | ||
|
||
/// <summary> | ||
/// Redirect calls matching a constraint from the parent registration by proxying instances returned from parent methods via an <see cref="IRedirect{TReturn}"/>. | ||
/// The returned instances are proxied by inserting a persistent <see cref="IVia"/> on the <see cref="IRedirect{TReturn}"/>. | ||
/// </summary> | ||
/// <param name="constraintExpression">The call constraint expression.</param> | ||
/// <param name="registerAction">Optional nested register action.</param> | ||
/// <typeparam name="TReturn">The return type of calls to redirect.</typeparam> | ||
/// <returns>This <see cref="INestedRegisterBuilder{TTarget}"/> instance.</returns> | ||
INestedRegisterBuilder<TTarget> ThenRedirect<TReturn>(Expression<Func<TTarget, TReturn>> constraintExpression, Action<INestedRegisterBuilder<TReturn>>? registerAction = null) where TReturn : class?; | ||
|
||
/// <summary> | ||
/// Redirect calls matching a constraint from the parent registration by proxying instances returned from parent methods via an <see cref="IRedirect{TReturn}"/>. | ||
/// The returned instances are proxied by inserting a persistent <see cref="IVia"/> on the <see cref="IRedirect{TReturn}"/>. | ||
/// </summary> | ||
/// <param name="name">Specify the <see cref="DivertR.RedirectId.Name" /> of the returned <see cref="IRedirect{TReturn}"/>.</param> | ||
/// <param name="constraintExpression">The call constraint expression.</param> | ||
/// <param name="registerAction">Optional nested register action.</param> | ||
/// <typeparam name="TReturn">The return type of calls to redirect.</typeparam> | ||
/// <returns>This <see cref="INestedRegisterBuilder{TTarget}"/> instance.</returns> | ||
INestedRegisterBuilder<TTarget> ThenRedirect<TReturn>(string? name, Expression<Func<TTarget, TReturn>> constraintExpression, Action<INestedRegisterBuilder<TReturn>>? registerAction = null) where TReturn : class?; | ||
|
||
/// <summary> | ||
/// Register a decorator on call returns of type <typeparamref name="TReturn"/> on the nested redirect. | ||
/// The decorator is applied by inserting a <see cref="IVia"/> on the nested redirect that is persistent, i.e. remains after reset. | ||
/// </summary> | ||
/// <param name="decorator">The decorator function.</param> | ||
/// <typeparam name="TReturn">The return type of calls to decorate.</typeparam> | ||
/// <returns>This <see cref="INestedRegisterBuilder"/> instance.</returns> | ||
INestedRegisterBuilder ThenDecorate<TReturn>(Func<TReturn, TReturn> decorator); | ||
/// <returns>This <see cref="INestedRegisterBuilder{TTarget}"/> instance.</returns> | ||
INestedRegisterBuilder<TTarget> ThenDecorate<TReturn>(Func<TReturn, TReturn> decorator); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.