public void Run() { var mediator = new DictionaryServiceFactoryBuilder() .AddRequestHandler(new AppendHelloRequestHandler()) .Build() .AsMediator(); var loginRequest = new LoginRequest("Anna"); mediator.Send(loginRequest, out string response); Console.WriteLine(response); }
public void Run() { var mediator = new DictionaryServiceFactoryBuilder() .AddNotificationHandler(new LineRequestHandler()) .AddNotificationHandler(new PrintNotificationHandler()) .AddNotificationHandler(new LineRequestHandler()) .Build() .AsMediator(); var loginRequest = new LoginRequest("Anna"); mediator.Publish(loginRequest); }
public static DictionaryServiceFactoryBuilder AddRequestHandler <TRequest, TResponse>(this DictionaryServiceFactoryBuilder self, IRequestHandler <TRequest, TResponse> handler) where TRequest : IRequest <TResponse> => self.AddRequestHandler(typeof(TRequest), handler);
public static DictionaryServiceFactoryBuilder AddNotificationHandler <TNotification>(this DictionaryServiceFactoryBuilder self, INotificationHandler <TNotification> handler) where TNotification : INotification => self.AddNotificationHandler(typeof(TNotification), handler);