using ColaFlow.Shared.Kernel.Modules; using Microsoft.AspNetCore.Builder; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using FluentValidation; using MediatR; using ColaFlow.Modules.ProjectManagement.Application.Behaviors; using ColaFlow.Modules.ProjectManagement.Application.Commands.CreateProject; using ColaFlow.Modules.ProjectManagement.Application.Common.Interfaces; using ColaFlow.Modules.ProjectManagement.Domain.Repositories; using ColaFlow.Modules.ProjectManagement.Infrastructure.Persistence; using ColaFlow.Modules.ProjectManagement.Infrastructure.Persistence.Interceptors; using ColaFlow.Modules.ProjectManagement.Infrastructure.Repositories; using ColaFlow.Modules.ProjectManagement.Infrastructure.Services; namespace ColaFlow.Modules.ProjectManagement; /// /// Project Management Module /// Responsible for managing projects, epics, stories, and tasks. /// public class ProjectManagementModule : IModule { public string Name => "ProjectManagement"; public void RegisterServices(IServiceCollection services, IConfiguration configuration) { // Register tenant context service (must be before DbContext for interceptor) services.AddScoped(); // Register audit interceptor services.AddScoped(); // Register DbContext with interceptor var connectionString = configuration.GetConnectionString("PMDatabase"); services.AddDbContext((serviceProvider, options) => { var auditInterceptor = serviceProvider.GetRequiredService(); options.UseNpgsql(connectionString) .AddInterceptors(auditInterceptor); }); // Register repositories services.AddScoped(); services.AddScoped(); // Note: IProjectNotificationService is registered in the API layer (Program.cs) // as it depends on IRealtimeNotificationService which is API-specific // Register MediatR handlers from Application assembly services.AddMediatR(cfg => { cfg.RegisterServicesFromAssembly(typeof(CreateProjectCommand).Assembly); }); // Register FluentValidation validators services.AddValidatorsFromAssembly(typeof(CreateProjectCommand).Assembly); // Register pipeline behaviors services.AddTransient(typeof(IPipelineBehavior<,>), typeof(ValidationBehavior<,>)); Console.WriteLine($"[{Name}] Module services registered"); } public void ConfigureApplication(IApplicationBuilder app) { // Configure module-specific middleware if needed Console.WriteLine($"[{Name}] Module application configured"); } }