CShells.AspNetCore 0.0.29

CShells.AspNetCore

ASP.NET Core integration for CShells providing middleware and shell resolution based on HTTP context.

Purpose

This package provides ASP.NET Core middleware, shell resolution strategies, and extensions for building multi-tenant web applications with CShells.

Key Features

  • HTTP middleware for shell resolution - Automatic per-request tenant/shell detection
  • Host-based tenant resolution - Route requests based on hostname
  • Path-based tenant resolution - Route requests based on URL path prefix
  • MapShells() extension - Automatically register endpoints from all shell features
  • Web routing configuration - Configure path prefixes and routing options per shell
  • Custom shell resolvers - Extensibility for custom resolution strategies

Installation

dotnet add package CShells
dotnet add package CShells.AspNetCore

Quick Start

1. Create a Web Feature

using CShells.AspNetCore.Features;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

[ShellFeature("Weather", DisplayName = "Weather API")]
public class WeatherFeature : IWebShellFeature
{
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddSingleton<IWeatherService, WeatherService>();
    }

    public void MapEndpoints(IEndpointRouteBuilder endpoints, IHostEnvironment? environment)
    {
        endpoints.MapGet("weather", (IWeatherService weatherService) =>
            weatherService.GetForecast());
    }
}

2. Configure Shells with Web Routing

{
  "CShells": {
    "Shells": {
      "Default": {
        "Features": { "Weather": {} },
        "Configuration": {
          "WebRouting": {
            "Path": ""
          }
        }
      },
      "Admin": {
        "Features": { "Admin": {} },
        "Configuration": {
          "WebRouting": {
            "Path": "admin",
            "RoutePrefix": "api/v1"
          }
        }
      }
    }
  }
}

3. Register CShells in Program.cs

Simple setup:

var builder = WebApplication.CreateBuilder(args);

// Register CShells from configuration
builder.AddShells();

var app = builder.Build();

// Configure middleware and endpoints for all shells
app.MapShells();

app.Run();

Explicit feature assembly selection:

Use From* members to select discovery sources, and WithAssemblyProvider(...) when attaching a provider that contributes assemblies.

var builder = WebApplication.CreateBuilder(args);

builder.AddShells(cshells =>
{
    cshells.WithConfigurationProvider(builder.Configuration);
    cshells.FromAssemblies(typeof(Program).Assembly);
    cshells.FromHostAssemblies();
});

var app = builder.Build();
app.MapShells();
app.Run();

If you do not call an assembly-source method, CShells uses the same host-derived feature assembly set as the default discovery behavior. Once you call FromAssemblies(...), FromHostAssemblies(), or WithAssemblyProvider(...), discovery switches to explicit provider mode and uses only the assemblies contributed by those appended providers.

Advanced setup with custom resolvers:

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddCShellsAspNetCore(cshells =>
{
    cshells.WithConfigurationProvider(builder.Configuration);
    cshells.WithWebRoutingResolver(options =>
    {
        options.ExcludePaths = new[] { "/api", "/health" };
        options.HeaderName = "X-Tenant-Id";
    });
});

var app = builder.Build();
app.MapShells();
app.Run();

Shell Resolution Strategies

Path-Based Resolution

Shells are resolved based on the URL path prefix:

{
  "Configuration": {
    "WebRouting": {
      "Path": "admin"
    }
  }
}

Requests to /admin/* will be routed to this shell.

Host-Based Resolution

Configure shells to respond to specific hostnames:

{
  "Configuration": {
    "WebRouting": {
      "Host": "admin.example.com"
    }
  }
}

Route Prefix

Apply a route prefix to all endpoints in a shell:

{
  "Configuration": {
    "WebRouting": {
      "Path": "tenant1",
      "RoutePrefix": "api/v1"
    }
  }
}

With this configuration, an endpoint mapped at weather will be accessible at /tenant1/api/v1/weather.

Custom Resolution

Implement IShellResolver for custom resolution logic:

public class CustomShellResolver : IShellResolver
{
    public Task<string?> ResolveShellIdAsync(HttpContext context)
    {
        // Custom logic to determine shell ID from HTTP context
        var shellId = context.Request.Headers["X-Tenant-Id"].FirstOrDefault();
        return Task.FromResult(shellId);
    }
}

builder.Services.AddCShellsAspNetCore(cshells =>
{
    cshells.WithResolver<CustomShellResolver>();
});

Web Routing Options

Configure routing behavior:

builder.Services.AddCShellsAspNetCore(cshells =>
{
    cshells.WithWebRoutingResolver(options =>
    {
        // Exclude paths from shell resolution
        options.ExcludePaths = new[] { "/api", "/health", "/swagger" };

        // Use custom header for tenant ID
        options.HeaderName = "X-Tenant-Id";

        // Configure default shell
        options.DefaultShell = "Default";
    });
});

Learn More

Showing the top 20 packages that depend on CShells.AspNetCore.

Packages Downloads
CShells.FastEndpoints
FastEndpoints integration for CShells. Provides a shell feature that automatically discovers and registers FastEndpoints from all enabled features. Reference this package in your host application to enable FastEndpoints support.
2
CShells.FastEndpoints
FastEndpoints integration for CShells. Provides a shell feature that automatically discovers and registers FastEndpoints from all enabled features. Reference this package in your host application to enable FastEndpoints support.
3

.NET 10.0

.NET 8.0

.NET 9.0

Version Downloads Last updated
0.0.29 1 09/27/2026
0.0.28 2 09/07/2026
0.0.27 2 09/07/2026
0.0.26 2 09/07/2026
0.0.25 2 09/07/2026
0.0.24 2 09/07/2026
0.0.23 2 09/07/2026
0.0.22 3 09/07/2026
0.0.21 2 09/07/2026
0.0.20 2 09/07/2026
0.0.19 2 09/07/2026
0.0.18 2 09/07/2026
0.0.17 3 09/07/2026
0.0.16 2 09/07/2026
0.0.15 2 09/07/2026
0.0.14 2 09/07/2026
0.0.13 2 09/07/2026
0.0.12 3 09/07/2026
0.0.11 2 09/07/2026
0.0.10 2 09/07/2026
0.0.9 2 09/07/2026
0.0.8 2 09/07/2026
0.0.7 2 09/07/2026
0.0.6 3 09/07/2026
0.0.5 2 09/07/2026
0.0.4 2 09/07/2026
0.0.3 2 09/07/2026
0.0.2 2 09/07/2026
0.0.1 2 09/07/2026