示例#1
0
 /// <summary>
 /// Add delegate of <see cref="RequestResponseDelegateAsync{TRequest, TResponse}"/> to the services collection.
 /// </summary>
 /// <typeparam name="TRequest">The request type</typeparam>
 /// <typeparam name="TResponse">The response time.</typeparam>
 /// <param name="services">The <see cref="IServiceCollection"/> to add the services to.</param>
 /// <param name="requestDelegate">The instance of the publish processing delegate.</param>
 /// <param name="servicingOrder">The order of the processing.</param>
 /// <returns>The <see cref="IServiceCollection"/> so that additional calls can be chained.</returns>
 public static IServiceCollection AddRequestProcessingHandler <TRequest, TResponse>(this IServiceCollection services, RequestResponseDelegateAsync <TRequest, TResponse> requestDelegate, ServicingOrder servicingOrder = ServicingOrder.Processing) where TRequest : class where TResponse : class
 {
     if (requestDelegate == null)
     {
         throw new ArgumentNullException(nameof(requestDelegate));
     }
     services.AddSingleton <IRequestHandler <TRequest, TResponse> >(new RequestHandlerProcessingWrapper <TRequest, TResponse>(requestDelegate, servicingOrder));
     return(services);
 }
 /// <summary>
 /// Constructs the wrapper class.
 /// </summary>
 /// <param name="requestDelegate">The processing delegate.</param>
 /// <param name="servicingOrder">The processing priority.</param>
 public RequestHandlerProcessingWrapper(RequestResponseDelegateAsync <TRequest, TResponse> requestDelegate, ServicingOrder servicingOrder = ServicingOrder.Processing)
 {
     _delegate       = requestDelegate ?? throw new ArgumentNullException(nameof(requestDelegate));
     OrderInTheGroup = servicingOrder;
 }
 /// <summary>
 /// Add delegate of <see cref="NotificationDelegateAsync{TRequest}"/> to the services collection.
 /// </summary>
 /// <typeparam name="TNotification">The request type</typeparam>
 /// <param name="services">The <see cref="IServiceCollection"/> to add the services to.</param>
 /// <param name="notificationDelegate">The instance of the publish processing delegate.</param>
 /// <param name="servicingOrder">The order of the processing.</param>
 /// <returns>The <see cref="IServiceCollection"/> so that additional calls can be chained.</returns>
 public static IServiceCollection AddNotificationProcessingHandler <TNotification>(this IServiceCollection services, NotificationDelegateAsync <TNotification> notificationDelegate, ServicingOrder servicingOrder = ServicingOrder.Processing) where TNotification : class
 {
     if (notificationDelegate == null)
     {
         throw new ArgumentNullException(nameof(notificationDelegate));
     }
     services.AddSingleton <INotificationHandler <TNotification> >(new NotificationHandlerProcessingWrapper <TNotification>(notificationDelegate, servicingOrder));
     return(services);
 }
 /// <summary>
 /// Constructs the wrapper class.
 /// </summary>
 /// <param name="notificationDelegate">The processing delegate.</param>
 /// <param name="servicingOrder">The processing priority.</param>
 public NotificationHandlerProcessingWrapper(NotificationDelegateAsync <TNotification> notificationDelegate, ServicingOrder servicingOrder = ServicingOrder.Processing)
 {
     _delegate       = notificationDelegate ?? throw new ArgumentNullException(nameof(notificationDelegate));
     OrderInTheGroup = servicingOrder;
 }