Skip to content

Commit

Permalink
Add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaliumhexacyanoferrat committed Dec 5, 2024
1 parent cab2690 commit 1ebcae5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Modules/Reflection/IOperationInterceptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,36 @@

namespace GenHTTP.Modules.Reflection;

/// <summary>
/// A result returned by an interceptor.
/// </summary>
/// <param name="payload">The payload of the response</param>
public sealed class InterceptionResult(object? payload = null) : Result<object?>(payload);

/// <summary>
/// A piece of logic to be executed before the
/// actual method invocation. Triggered by methods
/// annotated with the <see cref="InterceptWithAttribute{T}" />
/// attribute.
/// </summary>
public interface IOperationInterceptor
{

/// <summary>
/// Invoked after the instance has been created to configure
/// the interceptor with the originally used attribute. Allows
/// the interceptor to read configuration data as needed.
/// </summary>
/// <param name="attribute">The original attribute instance on the method definition</param>
void Configure(object attribute);

/// <summary>
/// Invoked on every operation call by the client.
/// </summary>
/// <param name="request">The request which caused this invocation</param>
/// <param name="operation">The currently executed operation</param>
/// <param name="arguments">The operation arguments as derived by the framework</param>
/// <returns>If a result is returned, it will be converted into a response and the method is not invoked</returns>
ValueTask<InterceptionResult?> InterceptAsync(IRequest request, Operation operation, IReadOnlyDictionary<string, object?> arguments);

}
9 changes: 9 additions & 0 deletions Modules/Reflection/InterceptWithAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
namespace GenHTTP.Modules.Reflection;

/// <summary>
/// When annotated on a service method, the method handler
/// will create an instance of T and invoke it before
/// the actual method invocation.
/// </summary>
/// <typeparam name="T">The type of interceptor to be used</typeparam>
/// <remarks>
/// Allows to implement concerns on operation level such as authorization.
/// </remarks>
[AttributeUsage(AttributeTargets.Method)]
public class InterceptWithAttribute<T> : Attribute where T : IOperationInterceptor, new()
{
Expand Down

0 comments on commit 1ebcae5

Please sign in to comment.