dotnet-cqrs/Svrnty.CQRS.Grpc.Sample/Program.cs

30 lines
1018 B
C#

using Svrnty.CQRS.Abstractions;
using Svrnty.CQRS.FluentValidation;
using Svrnty.CQRS.Grpc.Sample;
using Svrnty.CQRS.Grpc.Sample.Grpc.Extensions;
var builder = WebApplication.CreateBuilder(args);
// Register command handlers with CQRS and FluentValidation
builder.Services.AddCommand<AddUserCommand, int, AddUserCommandHandler, AddUserCommandValidator>();
builder.Services.AddCommand<RemoveUserCommand, RemoveUserCommandHandler>();
// Register query handlers with CQRS
builder.Services.AddQuery<FetchUserQuery, User, FetchUserQueryHandler>();
// Auto-generated: Register gRPC services for both commands and queries (includes reflection)
builder.Services.AddGrpcCommandsAndQueries();
var app = builder.Build();
// Auto-generated: Map gRPC endpoints for both commands and queries
app.MapGrpcCommandsAndQueries();
// Map gRPC reflection service
app.MapGrpcReflectionService();
Console.WriteLine("Auto-Generated gRPC Server with Reflection and Validation");
Console.WriteLine("http://localhost:5000");
app.Run();