Skip to content

Web Hosting

This is a simple library that allows you to add infrastructure to a WebApplicationBuilder and post-app build against the WebApplication to set all of the infrastructure up in one places. This allows for modular chunks of code to install things like authentication, authorization, logging, etc. without having to add them to the main application startup code.

  • Merges service container build and post build scenarios into a single class
  • All IInfrastructureModule implementations are automatically detected and run
  1. Install the NuGet package

  2. Add an infrastructure module by implementing IInfrastructureModule:

    using Shiny.Extensions.WebHosting;
    public class MyInfrastructureModule : IInfrastructureModule
    {
    public void Add(WebApplicationBuilder builder)
    {
    // Register your services here
    }
    public void Configure(WebApplication app)
    {
    // Configure your application here
    }
    }
  3. In your application hosting startup, add the following:

    using Shiny.Extensions.WebHosting;
    var builder = WebApplication.CreateBuilder(args);
    builder.AddInfrastructure(params Assembly[] assemblies)(); // this scans the assemblies for IInfrastructureModule implementations and runs Add methods
    // OR
    builder.AddInfrastructureModules(params IInfrastructureModule[] modules); // this doesn't use reflection
    var app = builder.Build();
    app.UseInfrastructure(); // this runs all IInfrastructureModule.Use methods