An open API service indexing awesome lists of open source software.

https://github.com/dazinator/reconfigurablemiddleware

enhancing ASP.NET Core applications by introducing a middleware pipeline capable of responding to configuration changes with dynamic rebuilding.
https://github.com/dazinator/reconfigurablemiddleware

Last synced: about 1 year ago
JSON representation

enhancing ASP.NET Core applications by introducing a middleware pipeline capable of responding to configuration changes with dynamic rebuilding.

Awesome Lists containing this project

README

          

## Reconfigurable Middleware

Allow middleware in your asp.net core application to be re-configured, by reloading it when configuration changes.

## Example

appsettings.json:

```json
{
"Pipeline": {
"UseDeveloperExceptionPage": false
}
}
```

startup.cs:

```csharp

public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}

public IConfiguration Configuration { get; }

// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
var configSection = Configuration.GetSection("Pipeline");
services.Configure(configSection);
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
// Note: Use vs Run (latter is terminal, former is not)
// make a change to appsettings.json "Pipelines" section and watch log output in console on furture requests.
app.UseReloadablePipeline(ConfigureReloadablePipeline);
app.UseWelcomePage();
}

private void ConfigureReloadablePipeline(IApplicationBuilder appBuilder, IWebHostEnvironment environment, PipelineOptions options)
{
var logger = appBuilder.ApplicationServices.GetRequiredService>();
logger.LogInformation("Building reloadable pipeline from current options!");

if (options.UseDeveloperExceptionPage)
{
appBuilder.Use(async (context, onNext) =>
{
var logger = context.RequestServices.GetRequiredService>();
logger.LogInformation("Using dev middleware!");
await onNext();
});
}
else
{
appBuilder.Use(async (context, onNext) =>
{
var logger = context.RequestServices.GetRequiredService>();
logger.LogInformation("Not using dev middleware..");
await onNext();
});
}
}
}

```