Skip to content

Conversation

Copy link

Copilot AI commented Sep 1, 2025

This PR adds comprehensive support for .NET minimal APIs to the LittleBlocks framework, providing the same rich feature set that was previously only available for traditional MVC/Controller-based applications.

What's Changed

New Extension Methods

  • WebApplicationBuilder.BootstrapLittleBlocks() - Configures LittleBlocks services for minimal APIs
  • WebApplication.UseLittleBlocksPipeline() - Sets up the complete middleware pipeline with all LittleBlocks features

New Components

  • MinimalApiBootstrapper - Handles service registration without requiring a Startup class
  • WebApplicationExtensions - Pipeline configuration optimized for minimal APIs
  • MinimalApiPipelineOptions - Configuration options for customizing the pipeline

Features Supported

All existing LittleBlocks features work seamlessly with minimal APIs:

  • ✅ Global error handling with custom exceptions
  • ✅ Structured logging (Serilog integration)
  • ✅ Request correlation tracking
  • ✅ Health checks with UI dashboard
  • ✅ Authentication & authorization (OAuth2/Impersonation/None)
  • ✅ CORS configuration
  • ✅ Swagger/OpenAPI documentation
  • ✅ Configuration section binding
  • ✅ Dependency injection integration
  • ✅ Diagnostics endpoints
  • ✅ Branded start page with navigation

Usage Examples

Traditional Startup Pattern (Existing)

public class Program
{
    public static void Main(string[] args)
    {
        HostAsWeb.Run<Startup>(s => s.ConfigureLogger<Startup>());
    }
}

New Minimal API Pattern

using LittleBlocks.AspNetCore.Bootstrap;

var builder = WebApplication.CreateBuilder(args);

// Bootstrap LittleBlocks services
builder.BootstrapLittleBlocks(app => app
    .AddConfigSection<AppSettings>()
    .HandleApplicationException<MyApplicationException>()
    .ConfigureCorrelation(m => m.AutoCorrelateRequests())
    .ConfigureHealthChecks(c =>
    {
        c.AddUrlGroup(new Uri("http://www.google.com"), HttpMethod.Get, "google");
    })
    .AddServices((container, config) =>
    {
        container.AddScoped<IMyService, MyService>();
    })
);

var app = builder.Build();

// Configure the pipeline
app.UseLittleBlocksPipeline();

// Define minimal API endpoints
app.MapGet("/api/greeting", (IGreetingService service) => service.GetGreeting());
app.MapPost("/api/greeting", (GreetingRequest request, IGreetingService service) => 
    service.CreateGreeting(request));

app.Run();

Sample Application

A complete working sample (LittleBlocks.Sample.MinimalApi) demonstrates:

  • Service configuration and dependency injection
  • Health check setup with external dependencies
  • Custom API endpoints with GET/POST operations
  • Configuration binding and structured logging
  • Full integration with Swagger UI

Screenshots

Start Page with Navigation
LittleBlocks Minimal API Start Page

Swagger UI Integration
Swagger UI Working

Backward Compatibility

  • ✅ All existing traditional Startup-based applications continue to work unchanged
  • ✅ Existing configuration patterns and fluent APIs remain identical
  • ✅ No breaking changes to any existing functionality
  • ✅ All existing tests pass (4/4 bootstrap unit tests)

Technical Implementation

  • Reuses existing service registration and middleware configuration infrastructure
  • Handles authentication mode detection (None/OAuth2/Impersonated)
  • Optimizes for minimal APIs by excluding MVC-specific services (like IUrlHelper)
  • Uses AddEndpointsApiExplorer() and AddSwaggerGen() for minimal API documentation
  • Maintains the same fluent configuration API for consistency

This enables teams to modernize their APIs to use minimal APIs while keeping all the enterprise-grade features that LittleBlocks provides.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • http://crl3.digicert.com:443/DigiCertHighAssuranceEVRootCA.crl
    • Triggering command: dotnet build LittleBlocks.sln (http block)
  • http://crl3.digicert.com:443/NETFoundationProjectsCodeSigningCA.crl
    • Triggering command: dotnet build LittleBlocks.sln (http block)
  • httpbin.org
    • Triggering command: /usr/lib/dotnet/dotnet exec --runtimeconfig /home/REDACTED/work/LittleBlocks.API/LittleBlocks.API/src/Samples/LittleBlocks.Sample.WebAPI.IntegrationTests/bin/Debug/net8.0/LittleBlocks.Sample.WebAPI.IntegrationTests.runtimeconfig.json --depsfile /home/REDACTED/work/LittleBlocks.API/LittleBlocks.API/src/Samples/LittleBlocks.Sample.WebAPI.IntegrationTests/bin/Debug/net8.0/LittleBlocks.Sample.WebAPI.IntegrationTests.deps.json /home/REDACTED/work/LittleBlocks.API/LittleBlocks.API/src/Samples/LittleBlocks.Sample.WebAPI.IntegrationTests/bin/Debug/net8.0/testhost.dll --port 38079 --endpoint 127.0.0.1:038079 --role client --parentprocessid 4254 --telemetryoptedin false (dns block)
  • httpbintest.org
    • Triggering command: /usr/lib/dotnet/dotnet exec --runtimeconfig /home/REDACTED/work/LittleBlocks.API/LittleBlocks.API/src/Samples/LittleBlocks.Sample.WebAPI.IntegrationTests/bin/Debug/net8.0/LittleBlocks.Sample.WebAPI.IntegrationTests.runtimeconfig.json --depsfile /home/REDACTED/work/LittleBlocks.API/LittleBlocks.API/src/Samples/LittleBlocks.Sample.WebAPI.IntegrationTests/bin/Debug/net8.0/LittleBlocks.Sample.WebAPI.IntegrationTests.deps.json /home/REDACTED/work/LittleBlocks.API/LittleBlocks.API/src/Samples/LittleBlocks.Sample.WebAPI.IntegrationTests/bin/Debug/net8.0/testhost.dll --port 38079 --endpoint 127.0.0.1:038079 --role client --parentprocessid 4254 --telemetryoptedin false (dns block)
  • www.google.com
    • Triggering command: /home/REDACTED/work/LittleBlocks.API/LittleBlocks.API/src/Samples/LittleBlocks.Sample.MinimalApi/bin/Debug/net8.0/LittleBlocks.Sample.MinimalApi (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: moattarwork <1560935+moattarwork@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for minimal api to the little block Add minimal API support to LittleBlocks framework Sep 1, 2025
Copilot AI requested a review from moattarwork September 1, 2025 21:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants