public void BuildHandler(IApplicationBuilder app, ISerialize serialize) { RequestDelegateFactory.CreateDelegate(logger, messageHandler, out List <SubscribeModel> subDelegate).ForEach(x => { app.Map(x.Path, handle => { handle.MapWhen(p => p.Request.Method.Equals("POST"), builder => { builder.Run(async ctx => { using var lifetimescope = Container.BeginLifetimeScope();//每次从静态根容器引用构造一个独立的生命周期范围 await x.Excute(ctx, lifetimescope); }); }); }); }); if (subDelegate.Any()) { app.Map("/dapr/subscribe", handle => handle.Run(async ctx => { ctx.Response.ContentType = "application/json"; await ctx.Response.WriteAsync(serialize.SerializesJson(subDelegate)); })); } }
public RequestDelegate(string serverName, MethodInfo method, ILogger logger, IMessageHandler messageHandler) { Path = new PathString($"/{serverName}/{method.Name}".ToLower()); if (typeof(Tin) == typeof(object)) { noInput = true; NoInputMethodDelegate = RequestDelegateFactory.CreateMethodDelegate <Tobj, Task <Tout> >(method); } else { noInput = false; MethodDelegate = RequestDelegateFactory.CreateMethodDelegate <Tobj, Tin, Task <Tout> >(method); } this.logger = logger; this.messageHandler = messageHandler; }