40 lines
1.5 KiB
C#
40 lines
1.5 KiB
C#
using MediatR;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Nashel.BuildingBlocks.Application.Abstractions;
|
|
using Nashel.BuildingBlocks.Application.Behaviors;
|
|
using Nashel.Modules.Identity.Application.Commands;
|
|
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;
|
|
|
|
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.AddScoped<IPasswordHasher, PasswordHasher>();
|
|
services.AddHttpContextAccessor();
|
|
|
|
services.AddMediatR(cfg =>
|
|
{
|
|
cfg.RegisterServicesFromAssembly(typeof(RegisterUserCommand).Assembly);
|
|
cfg.AddBehavior(typeof(IPipelineBehavior<,>), typeof(ValidationBehavior<,>));
|
|
});
|
|
|
|
services.AddDbContext<IdentityDbContext>(options =>
|
|
{
|
|
options.UseNpgsql(configuration.GetConnectionString("DefaultConnection"));
|
|
});
|
|
|
|
return services;
|
|
}
|
|
}
|