-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHandlerRegistrationBuilderExtensions.cs
More file actions
31 lines (29 loc) · 1.36 KB
/
Copy pathHandlerRegistrationBuilderExtensions.cs
File metadata and controls
31 lines (29 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using Jameak.RequestAuthorization.Core.Abstractions;
using Mediator;
using Microsoft.Extensions.DependencyInjection;
namespace Jameak.RequestAuthorization.Adapter.Mediator;
/// <summary>
/// Provides extensions for registering Mediator adapters.
/// </summary>
public static class HandlerRegistrationBuilderExtensions
{
/// <summary>
/// Registers authorization pipeline behaviors for Mediator.
/// </summary>
/// <remarks>
/// Note that for NativeAOT usage, you instead need to reference the pipeline behavior types directly in the AddMediator call like so:
/// <code>
/// builder.Services.AddMediator(options =>
/// {
/// options.PipelineBehaviors = [typeof(RequestAuthorizationPipelineBehavior<,>)];
/// options.StreamPipelineBehaviors = [typeof(RequestAuthorizationStreamPipelineBehavior<,>)];
/// });
/// </code>
/// </remarks>
public static IHandlerRegistrationBuilder AddMediatorPipelineAdapter(this IHandlerRegistrationBuilder builder)
{
builder.Services.Add(new ServiceDescriptor(typeof(IPipelineBehavior<,>), typeof(RequestAuthorizationPipelineBehavior<,>), builder.ServiceLifetime));
builder.Services.Add(new ServiceDescriptor(typeof(IStreamPipelineBehavior<,>), typeof(RequestAuthorizationStreamPipelineBehavior<,>), builder.ServiceLifetime));
return builder;
}
}