| | | 1 | | using Elsa.Mediator.Middleware.Notification.Contracts; |
| | | 2 | | using Microsoft.Extensions.DependencyInjection; |
| | | 3 | | |
| | | 4 | | namespace Elsa.Mediator.Middleware.Notification; |
| | | 5 | | |
| | | 6 | | /// <summary> |
| | | 7 | | /// Contains extension methods for <see cref="INotificationPipelineBuilder"/>. |
| | | 8 | | /// </summary> |
| | | 9 | | public static class MiddlewareExtensions |
| | | 10 | | { |
| | | 11 | | /// <summary> |
| | | 12 | | /// Adds a middleware to the notification pipeline. |
| | | 13 | | /// </summary> |
| | | 14 | | /// <param name="builder">The notification pipeline builder.</param> |
| | | 15 | | /// <param name="args">The arguments to pass to the middleware constructor.</param> |
| | | 16 | | /// <typeparam name="TMiddleware">The middleware type.</typeparam> |
| | | 17 | | public static INotificationPipelineBuilder UseMiddleware<TMiddleware>(this INotificationPipelineBuilder builder, par |
| | | 18 | | { |
| | 1 | 19 | | var middleware = typeof(TMiddleware); |
| | | 20 | | |
| | 1 | 21 | | return builder.Use(next => |
| | 1 | 22 | | { |
| | 1 | 23 | | var invokeMethod = MiddlewareHelpers.GetInvokeMethod(middleware); |
| | 2 | 24 | | var ctorParams = new[] { next }.Concat(args).Select(x => x).ToArray(); |
| | 1 | 25 | | var instance = ActivatorUtilities.CreateInstance(builder.ApplicationServices, middleware, ctorParams); |
| | 1 | 26 | | return (NotificationMiddlewareDelegate)invokeMethod.CreateDelegate(typeof(NotificationMiddlewareDelegate), i |
| | 1 | 27 | | }); |
| | | 28 | | } |
| | | 29 | | } |