Пример #1
0
        public virtual Task Handle(RequestHandlerContext context, IRequest request)
        {
            if (!CanHandle(request))
            {
                string message = string.Format(Properties.Resources.CannotHandleRequest, request.GetType().Name);
                throw new ArgumentException(message, nameof(request));
            }

            return(Handle(context, (TRequest)request));
        }
Пример #2
0
        public Task Request(IServiceBus bus, ClaimsPrincipal user, IRequest request)
        {
            Guard.AgainstNull(nameof(bus), bus);
            Guard.AgainstNull(nameof(user), user);
            Guard.AgainstNull(nameof(request), request);

            var handler = Find(request);
            var context = new RequestHandlerContext(bus, user);

            return(handler.Handle(context, request));
        }
Пример #3
0
        public async Task <TResponse> Request <TResponse>(IServiceBus bus, ClaimsPrincipal user, IRequest <TResponse> request)
        {
            Guard.AgainstNull(nameof(bus), bus);
            Guard.AgainstNull(nameof(user), user);
            Guard.AgainstNull(nameof(request), request);

            var handler = Find(request);
            var context = new RequestHandlerContext <TResponse>(bus, user);

            await handler.Handle(context, request);

            return(context.Response == null ? default(TResponse) : context.Response);
        }
Пример #4
0
 protected abstract Task Handle(RequestHandlerContext context, TRequest request);