using Microsoft.AspNetCore.Server.Kestrel.Core; using Svrnty.CQRS; using Svrnty.CQRS.FluentValidation; using Svrnty.CQRS.Grpc; using Svrnty.Sample; using Svrnty.CQRS.MinimalApi; using Svrnty.CQRS.DynamicQuery; var builder = WebApplication.CreateBuilder(args); // Configure Kestrel to support both HTTP/1.1 (for REST APIs) and HTTP/2 (for gRPC) builder.WebHost.ConfigureKestrel(options => { // Port 6000: HTTP/2 for gRPC options.ListenLocalhost(6000, o => o.Protocols = HttpProtocols.Http2); // Port 6001: HTTP/1.1 for REST API options.ListenLocalhost(6001, o => o.Protocols = HttpProtocols.Http1); }); // IMPORTANT: Register dynamic query dependencies FIRST // (before AddSvrntyCqrs, so gRPC services can find the handlers) builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddDynamicQueryWithProvider(); // Configure CQRS with fluent API builder.Services.AddSvrntyCqrs(cqrs => { // Register commands and queries with validators cqrs.AddCommand(); cqrs.AddCommand(); cqrs.AddQuery(); // Enable gRPC endpoints with reflection cqrs.AddGrpc(grpc => { grpc.EnableReflection(); }); // Enable MinimalApi endpoints cqrs.AddMinimalApi(configure => { }); }); builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); var app = builder.Build(); // Map all configured CQRS endpoints (gRPC, MinimalApi, and Dynamic Queries) app.UseSvrntyCqrs(); app.UseSwagger(); app.UseSwaggerUI(); Console.WriteLine("Auto-Generated gRPC Server with Reflection, Validation, MinimalApi and Swagger"); Console.WriteLine("gRPC (HTTP/2): http://localhost:6000"); Console.WriteLine("HTTP API (HTTP/1.1): http://localhost:6001/api/command/* and http://localhost:6001/api/query/*"); Console.WriteLine("Swagger UI: http://localhost:6001/swagger"); app.Run();