64 lines
2.2 KiB
C#
64 lines
2.2 KiB
C#
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<PoweredSoft.Data.Core.IAsyncQueryableService, SimpleAsyncQueryableService>();
|
|
builder.Services.AddTransient<PoweredSoft.DynamicQuery.Core.IQueryHandlerAsync, PoweredSoft.DynamicQuery.QueryHandlerAsync>();
|
|
builder.Services.AddDynamicQueryWithProvider<User, UserQueryableProvider>();
|
|
|
|
// Configure CQRS with fluent API
|
|
builder.Services.AddSvrntyCqrs(cqrs =>
|
|
{
|
|
// Register commands and queries with validators
|
|
cqrs.AddCommand<AddUserCommand, int, AddUserCommandHandler, AddUserCommandValidator>();
|
|
cqrs.AddCommand<RemoveUserCommand, RemoveUserCommandHandler>();
|
|
cqrs.AddQuery<FetchUserQuery, User, FetchUserQueryHandler>();
|
|
|
|
// 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();
|