// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } var injectorOptions = new MiddlewareInjectorOptions(); app.UseMiddlewareInjector(injectorOptions); app.Run(async context => { context.Response.ContentType = "text/html"; await context.Response.WriteAsync("<html><body>"); if (context.Request.Path.Equals("/clear")) { injectorOptions.InjectMiddleware(_ => { }); await context.Response.WriteAsync("Cleared middleware<br>"); } else if (context.Request.Path.Equals("/inject")) { injectorOptions.InjectMiddleware(InjectContent); await context.Response.WriteAsync("Injected middleware<br>"); } else { await context.Response.WriteAsync("Hello World!<br>"); } await context.Response.WriteAsync("<a href=\"/inject\">Inject</a><br>"); await context.Response.WriteAsync("<a href=\"/testpath\">Test Path</a><br>"); await context.Response.WriteAsync("<a href=\"/clear\">Clear</a><br>"); await context.Response.WriteAsync("<a href=\"/\">Home</a><br>"); await context.Response.WriteAsync("</body></html>"); }); }
public MiddlewareInjectorMiddleware(RequestDelegate next, IApplicationBuilder builder, MiddlewareInjectorOptions options) { _next = next ?? throw new ArgumentNullException(nameof(next)); _builder = builder ?? throw new ArgumentNullException(nameof(builder)); _options = options ?? throw new ArgumentNullException(nameof(options)); }
public MiddlewareInjectorMiddleware(AppFunc next, IAppBuilder builder, MiddlewareInjectorOptions options) { _next = next ?? throw new ArgumentNullException(nameof(next)); _builder = builder ?? throw new ArgumentNullException(nameof(builder)); _options = options ?? throw new ArgumentNullException(nameof(options)); }
public static IAppBuilder UseMiddlewareInjector(this IAppBuilder builder, MiddlewareInjectorOptions options) { return(builder.Use <MiddlewareInjectorMiddleware>(builder.New(), options)); }