diff --git a/Govor.API/Extensions/ConfigurationProgramExtensions.cs b/Govor.API/Extensions/ConfigurationProgramExtensions.cs new file mode 100644 index 0000000..0a59251 --- /dev/null +++ b/Govor.API/Extensions/ConfigurationProgramExtensions.cs @@ -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(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + } + + public static void AddRepositories(this IServiceCollection services) + { + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + } + + public static void AddValidators(this IServiceCollection services) + { + services.AddScoped, UserValidator>(); + services.AddScoped, MessageValidator>(); + services.AddScoped, MediaAttachmentsValidator>(); + services.AddScoped, AdminValidator>(); + services.AddScoped, InvitationValidator>(); + } + + public static void AddGovorDbContext(this IServiceCollection services, IConfiguration configuration) + { + services.AddDbContext( + options => + { + options.UseNpgsql(configuration.GetConnectionString(nameof(GovorDbContext))); + } + ); + } +} \ No newline at end of file diff --git a/Govor.API/Program.cs b/Govor.API/Program.cs index 0186809..6c736f2 100644 --- a/Govor.API/Program.cs +++ b/Govor.API/Program.cs @@ -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(); -builder.Services.AddScoped(); -builder.Services.AddScoped(); -builder.Services.AddScoped(); -builder.Services.AddScoped, UserValidator>(); -builder.Services.AddScoped, MessageValidator>(); -builder.Services.AddScoped, MediaAttachmentsValidator>(); -builder.Services.AddScoped(); -builder.Services.AddScoped(); -builder.Services.AddScoped(); -builder.Services.AddScoped(); -builder.Services.AddScoped(); +// Init DI +builder.Services.AddServices(); +builder.Services.AddRepositories(); +builder.Services.AddValidators(); -builder.Services.AddDbContext( - options => - { - options.UseNpgsql(builder.Configuration.GetConnectionString(nameof(GovorDbContext))); - } -); +builder.Services.AddGovorDbContext(configuration); // GovorDbContext init builder.Services.AddEndpointsApiExplorer(); diff --git a/Govor.Core/Models/Invitation.cs b/Govor.Core/Models/Invitation.cs index f04bf0c..5e3bf01 100644 --- a/Govor.Core/Models/Invitation.cs +++ b/Govor.Core/Models/Invitation.cs @@ -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; }