コード例 #1
0
 public override Response <TestResult> Handle(IRequestBusContext context, TestRequest request)
 {
     return(new TestResult
     {
         Message = $"{request.Name} : handled by {this.GetType().Name}"
     });
 }
コード例 #2
0
 public override Response <TestResult> Handle(IRequestBusContext context, None request)
 {
     return(new TestResult
     {
         Message = "Hello World!"
     });
 }
コード例 #3
0
 public override IEnumerable <Error> Validate(IRequestBusContext context, TestRequest request)
 {
     if (string.IsNullOrWhiteSpace(request.Name))
     {
         yield return(Error.Create("Name is required.", "Name"));
     }
 }
コード例 #4
0
 public override Response <TestResult> Handle(IRequestBusContext context, None request)
 {
     return(new TestResult
     {
         Message = "Shouldn't call"
     });
 }
コード例 #5
0
 public override Response <TestResponse> Handle(IRequestBusContext context, TestRequest request)
 {
     return(new TestResponse
     {
         HandlerExecuted = this.GetType().Name
     });
 }
コード例 #6
0
 protected override async Task <Response <TestResult> > Handle(IRequestBusContext context)
 {
     return(new TestResult
     {
         Message = "Hello World!"
     });
 }
コード例 #7
0
 protected override async Task <Response <TestResult> > Handle(IRequestBusContext context)
 {
     return(new TestResult
     {
         Message = "Shouldn't call"
     });
 }
コード例 #8
0
 protected override void Filter(IRequestBusContext context, TestRequest request,
                                ResponseCollection <TestResult> rspCollection)
 {
     rspCollection.AddResponse(Response.Ok(new TestResult
     {
         Message = $"{request.Name} filtered by {this.GetType().Name}"
     }));
 }
コード例 #9
0
 public override Response <TestResponse> Handle(IRequestBusContext context, TestRequest request)
 {
     return(new TestResponse
     {
         HandlerExecuted = this.GetType().Name,
         Message =
             $"tenant:{context.GetOrDefault<string>("current-tenant")} user:{context.GetOrDefault<string>("user-name")}"
     });
 }
コード例 #10
0
            public override Task <IEnumerable <Error> > Validate(IRequestBusContext context, TestRequest request)
            {
                var result = new List <Error>();

                if (string.IsNullOrWhiteSpace(request.Name))
                {
                    result.Add(Error.Create("Name is required.", "Name"));
                }

                return(Task.FromResult((IEnumerable <Error>)result));
            }
コード例 #11
0
        Response <None> IRequestHandler <TRequest, None> .Handle(IRequestBusContext context, TRequest request)
        {
            var rsp = this.Handle(context, request);

            return(new Response <None>
            {
                Errors = rsp.Errors,
                IsSucceed = rsp.IsSucceed,
                StatusCode = rsp.StatusCode
            });
        }
コード例 #12
0
 public override Response <WidgetResponse> Handle(IRequestBusContext context, TestRequest request)
 {
     return(WidgetBuilder
            .WithName("main")
            .WithType("intro")
            .Build(new
     {
         Heading = "Welcome to app",
         Summary = "This is summary"
     }));
 }
コード例 #13
0
        async Task <Response <None> > IRequestHandlerAsync <TRequest, None> .Handle(IRequestBusContext context, TRequest request)
        {
            var rsp = await this.Handle(context, request);

            return(new Response <None>
            {
                StatusCode = rsp.StatusCode,
                IsSucceed = rsp.IsSucceed,
                Errors = rsp.Errors
            });
        }
コード例 #14
0
            public override Task <IEnumerable <Error> > Validate(IRequestBusContext context,
                                                                 RequestForShouldValidateRequest request)
            {
                var list = new List <Error>();

                if (string.IsNullOrWhiteSpace(request.Name))
                {
                    list.Add(Error.Create("Name is required.", nameof(request.Name)));
                }

                return(Task.FromResult((IEnumerable <Error>)list));
            }
コード例 #15
0
            protected override Task Filter(IRequestBusContext context, TestRequest request, ResponseCollection <TestResult> rspCollection)
            {
                rspCollection.Responses.Add(new ResponseUnit <TestResult>
                {
                    IsMainResponse = false,
                    Response       = Response.Ok(new TestResult
                    {
                        Message = $"{request.Name} filtered by {this.GetType().Name}"
                    })
                });

                return(Task.CompletedTask);
            }
コード例 #16
0
 public override Response <WidgetResponse> Handle(IRequestBusContext context, TestRequest request)
 {
     return(WidgetBuilder
            .WithName("latest-editorials")
            .WithType("data-carousel")
            .WithDisplayOrder(1)
            .Build(new[]
     {
         new
         {
             Id = 1,
             Heading = "This is title1",
             PhotoUrl = "http://resource.static.com/200x160"
         }
     }));
 }
コード例 #17
0
        private async Task <Response <TValue> > ValidateAsync <TRequest, TValue>(IRequestBusContext context, TRequest request)
        {
            var handlers = _sp.GetServices <IRequestValidatorAsync <TRequest> >()
                           .OrderByDescending(x => x.Priority);

            foreach (var handler in handlers)
            {
                if (!handler.IsApplicable(context, request))
                {
                    continue;
                }

                var errors = (await handler.Validate(context, request))?.ToArray() ?? Array.Empty <Error>();

                if (errors.Length > 0)
                {
                    return(Bolt.RequestBus.Response.Failed <TValue>(errors));
                }
            }

            return(null);
        }
コード例 #18
0
 public override bool IsApplicable(IRequestBusContext context, TestRequest request) => false;
コード例 #19
0
 protected virtual bool IsApplicable(IRequestBusContext context) => true;
コード例 #20
0
 protected abstract Task Filter(IRequestBusContext context, ResponseCollection <TResult> rspCollection);
コード例 #21
0
 bool IResponseFilterAsync <None, TResult> .IsApplicable(IRequestBusContext context, None request)
 {
     return(this.IsApplicable(context));
 }
コード例 #22
0
 Task IResponseFilterAsync <None, TResult> .Filter(IRequestBusContext context, None request, ResponseCollection <TResult> rspCollection)
 {
     return(this.Filter(context, rspCollection));
 }
コード例 #23
0
 void IResponseFilter <None, TResult> .Filter(IRequestBusContext context, None request, ResponseCollection <TResult> rspCollection)
 {
     this.Filter(context, rspCollection);
 }
コード例 #24
0
 protected override Response Handle(IRequestBusContext context, TestRequestContext request)
 {
     request.MsgInContext = context.GetOrDefault <string>("message");
     return(Response.Ok());
 }
コード例 #25
0
 protected override bool IsApplicable(IRequestBusContext context) => false;
コード例 #26
0
 public override bool IsApplicable(IRequestBusContext context, OrderPlaced @event) => false;
コード例 #27
0
 public void Write(IRequestBusContext context)
 {
     context.Set("message", "Hello World!");
 }
コード例 #28
0
 public abstract Task <IEnumerable <Error> > Validate(IRequestBusContext context, TRequest request);
コード例 #29
0
 protected override Response Handle(IRequestBusContext context, TestRequest request)
 {
     request.HandlersExecuted.Add(this.GetType().Name);
     return(Response.Ok());
 }
コード例 #30
0
 public virtual bool IsApplicable(IRequestBusContext context, TRequest request) => true;