public override Response <TestResult> Handle(IRequestBusContext context, TestRequest request) { return(new TestResult { Message = $"{request.Name} : handled by {this.GetType().Name}" }); }
public override Response <TestResult> Handle(IRequestBusContext context, None request) { return(new TestResult { Message = "Hello World!" }); }
public override IEnumerable <Error> Validate(IRequestBusContext context, TestRequest request) { if (string.IsNullOrWhiteSpace(request.Name)) { yield return(Error.Create("Name is required.", "Name")); } }
public override Response <TestResult> Handle(IRequestBusContext context, None request) { return(new TestResult { Message = "Shouldn't call" }); }
public override Response <TestResponse> Handle(IRequestBusContext context, TestRequest request) { return(new TestResponse { HandlerExecuted = this.GetType().Name }); }
protected override async Task <Response <TestResult> > Handle(IRequestBusContext context) { return(new TestResult { Message = "Hello World!" }); }
protected override async Task <Response <TestResult> > Handle(IRequestBusContext context) { return(new TestResult { Message = "Shouldn't call" }); }
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}" })); }
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")}" }); }
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)); }
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 }); }
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" })); }
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 }); }
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)); }
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); }
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" } })); }
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); }
public override bool IsApplicable(IRequestBusContext context, TestRequest request) => false;
protected virtual bool IsApplicable(IRequestBusContext context) => true;
protected abstract Task Filter(IRequestBusContext context, ResponseCollection <TResult> rspCollection);
bool IResponseFilterAsync <None, TResult> .IsApplicable(IRequestBusContext context, None request) { return(this.IsApplicable(context)); }
Task IResponseFilterAsync <None, TResult> .Filter(IRequestBusContext context, None request, ResponseCollection <TResult> rspCollection) { return(this.Filter(context, rspCollection)); }
void IResponseFilter <None, TResult> .Filter(IRequestBusContext context, None request, ResponseCollection <TResult> rspCollection) { this.Filter(context, rspCollection); }
protected override Response Handle(IRequestBusContext context, TestRequestContext request) { request.MsgInContext = context.GetOrDefault <string>("message"); return(Response.Ok()); }
protected override bool IsApplicable(IRequestBusContext context) => false;
public override bool IsApplicable(IRequestBusContext context, OrderPlaced @event) => false;
public void Write(IRequestBusContext context) { context.Set("message", "Hello World!"); }
public abstract Task <IEnumerable <Error> > Validate(IRequestBusContext context, TRequest request);
protected override Response Handle(IRequestBusContext context, TestRequest request) { request.HandlersExecuted.Add(this.GetType().Name); return(Response.Ok()); }
public virtual bool IsApplicable(IRequestBusContext context, TRequest request) => true;