From 44536cb9f5f7453333fcc4173b830981a6946f9f Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Fri, 7 Jun 2024 15:37:39 +0500 Subject: [PATCH] common: add helper for registering repositories --- Notesnook.API/Startup.cs | 6 +++--- .../Extensions/ServiceCollectionServiceExtensions.cs | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Notesnook.API/Startup.cs b/Notesnook.API/Startup.cs index 9ef61e6..68721fa 100644 --- a/Notesnook.API/Startup.cs +++ b/Notesnook.API/Startup.cs @@ -172,9 +172,9 @@ namespace Notesnook.API services.AddScoped(); services.AddScoped(); - services.AddRepository("user_settings") - .AddRepository("monographs") - .AddRepository("announcements"); + services.AddRepository("user_settings", "notesnook") + .AddRepository("monographs", "notesnook") + .AddRepository("announcements", "notesnook"); services.AddMongoCollection(Collections.SettingsKey) .AddMongoCollection(Collections.AttachmentsKey) diff --git a/Streetwriters.Common/Extensions/ServiceCollectionServiceExtensions.cs b/Streetwriters.Common/Extensions/ServiceCollectionServiceExtensions.cs index c8277fa..82b8741 100644 --- a/Streetwriters.Common/Extensions/ServiceCollectionServiceExtensions.cs +++ b/Streetwriters.Common/Extensions/ServiceCollectionServiceExtensions.cs @@ -18,11 +18,20 @@ along with this program. If not, see . */ using Microsoft.Extensions.DependencyInjection; +using Streetwriters.Data.DbContexts; +using Streetwriters.Data.Repositories; namespace Streetwriters.Common.Extensions { public static class ServiceCollectionServiceExtensions { + public static IServiceCollection AddRepository(this IServiceCollection services, string collectionName, string database) where T : class + { + services.AddSingleton((provider) => MongoDbContext.GetMongoCollection(provider.GetService(), database, collectionName)); + services.AddScoped>(); + return services; + } + public static IServiceCollection AddDefaultCors(this IServiceCollection services) { services.AddCors(options =>