This commit is contained in:
Халимов Рустам
2026-02-09 23:54:03 +03:00
parent c98c96e408
commit ee40b38968
65 changed files with 6157 additions and 957 deletions
@@ -0,0 +1,46 @@
using MediatR;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Nashel.BuildingBlocks.Application.Abstractions;
using Nashel.BuildingBlocks.Application.Behaviors;
using Nashel.Modules.Identity.Domain.Repositories;
using Nashel.Modules.Identity.Domain.Services;
using Nashel.Modules.Identity.Infrastructure.Persistence;
using Nashel.Modules.Identity.Infrastructure.Repositories;
using Nashel.Modules.Identity.Infrastructure.Services;
using Nashel.Modules.Identity.Application.Commands;
namespace Nashel.Modules.Identity.Infrastructure;
public static class DependencyInjection
{
public static IServiceCollection AddIdentityModule(this IServiceCollection services, IConfiguration configuration)
{
services.AddScoped<IAccountRepository, AccountRepository>();
services.AddScoped<IJwtTokenGenerator, JwtTokenGenerator>();
services.AddScoped<ICurrentUserService, CurrentUserService>();
services.AddHttpContextAccessor(); // Ensure available
// Add MediatR (auto-scan for handlers in Application layer)
services.AddMediatR(cfg =>
{
cfg.RegisterServicesFromAssembly(typeof(RegisterUserCommand).Assembly);
cfg.AddBehavior(typeof(IPipelineBehavior<,>), typeof(ValidationBehavior<,>));
});
// Add DbContext
services.AddDbContext<IdentityDbContext>(options =>
// Configure PostgreSQL inside Host or pass options builder
// Assume Host configures DbContext options or use connection string here
// If "NativeAOT" -> Npgsql DataSource approach is preferred in Host Program.cs.
// But standard AddDbContext works too for now.
// Let's assume connection string is provided in configuration or options.
// For now, simple AddDbContext
{
// options.UseNpgsql(configuration.GetConnectionString("DefaultConnection"));
// This requires Microsoft.EntityFrameworkCore.Npgsql package in Infrastructure.
});
return services;
}
}