ConfigurationProgramExtensions

This commit is contained in:
Artemy
2025-06-24 18:16:34 +07:00
parent 9893013bcc
commit 80e2ec30c6
3 changed files with 64 additions and 18 deletions
@@ -0,0 +1,57 @@
using Govor.API.Services;
using Govor.API.Services.AdminsStuff;
using Govor.API.Services.AdminsStuff.Interfaces;
using Govor.API.Services.Authentication;
using Govor.API.Services.Authentication.Interfaces;
using Govor.Core.Infrastructure.Extensions;
using Govor.Core.Infrastructure.Validators;
using Govor.Core.Models;
using Govor.Core.Repositories.Admins;
using Govor.Core.Repositories.Invaites;
using Govor.Core.Repositories.MediasAttachments;
using Govor.Core.Repositories.Messages;
using Govor.Core.Repositories.Users;
using Govor.Data;
using Govor.Data.Repositories;
using Microsoft.EntityFrameworkCore;
namespace Govor.API.Extensions;
public static class ConfigurationProgramExtensions
{
public static void AddServices(this IServiceCollection services)
{
services.AddScoped<IPasswordHasher, PasswordHasher>();
services.AddScoped<IJwtService, JwtService>();
services.AddScoped<IAccountService, AuthService>();
services.AddScoped<IUsersAdministration, UsersService>();
}
public static void AddRepositories(this IServiceCollection services)
{
services.AddScoped<IUsersRepository, UsersRepository>();
services.AddScoped<IMessagesRepository, MessagesRepository>();
services.AddScoped<IInvitesRepository, InvitesRepository>();
services.AddScoped<IAdminsRepository, AdminsRepository>();
services.AddScoped<IMediaAttachmentsRepository, MediaAttachmentsRepository>();
}
public static void AddValidators(this IServiceCollection services)
{
services.AddScoped<IObjectValidator<User>, UserValidator>();
services.AddScoped<IObjectValidator<Message>, MessageValidator>();
services.AddScoped<IObjectValidator<MediaAttachments>, MediaAttachmentsValidator>();
services.AddScoped<IObjectValidator<Admin>, AdminValidator>();
services.AddScoped<IObjectValidator<Invitation>, InvitationValidator>();
}
public static void AddGovorDbContext(this IServiceCollection services, IConfiguration configuration)
{
services.AddDbContext<GovorDbContext>(
options =>
{
options.UseNpgsql(configuration.GetConnectionString(nameof(GovorDbContext)));
}
);
}
}
+6 -18
View File
@@ -1,5 +1,6 @@
using System.Security.Cryptography;
using System.Text;
using Govor.API.Extensions;
using Govor.API.Hubs;
using Govor.API.Services;
using Govor.API.Services.AdminsStuff;
@@ -75,25 +76,12 @@ builder.Services.AddAuthorization();
builder.Services.AddControllers();
builder.Services.AddScoped<IPasswordHasher, PasswordHasher>();
builder.Services.AddScoped<IJwtService, JwtService>();
builder.Services.AddScoped<IAccountService, AuthService>();
builder.Services.AddScoped<IUsersRepository, UsersRepository>();
builder.Services.AddScoped<IObjectValidator<User>, UserValidator>();
builder.Services.AddScoped<IObjectValidator<Message>, MessageValidator>();
builder.Services.AddScoped<IObjectValidator<MediaAttachments>, MediaAttachmentsValidator>();
builder.Services.AddScoped<IMessagesRepository, MessagesRepository>();
builder.Services.AddScoped<IMediaAttachmentsRepository, MediaAttachmentsRepository>();
builder.Services.AddScoped<IUsersAdministration, UsersService>();
builder.Services.AddScoped<IInvitesRepository, InvitesRepository>();
builder.Services.AddScoped<IAdminsRepository, AdminsRepository>();
// Init DI
builder.Services.AddServices();
builder.Services.AddRepositories();
builder.Services.AddValidators();
builder.Services.AddDbContext<GovorDbContext>(
options =>
{
options.UseNpgsql(builder.Configuration.GetConnectionString(nameof(GovorDbContext)));
}
);
builder.Services.AddGovorDbContext(configuration); // GovorDbContext init
builder.Services.AddEndpointsApiExplorer();
+1
View File
@@ -4,6 +4,7 @@ public class Invitation
{
public Guid Id { get; set; }
public bool IsAdmin { get; set; }
public string Description { get; set; }
public DateTime DateCreated { get; set; }
public DateTime EndDate { get; set; }
public int MaxParticipants { get; set; }