mirror of
https://github.com/streetwriters/notesnook-sync-server.git
synced 2026-02-12 11:12:44 +00:00
common: add helper for registering repositories
This commit is contained in:
@@ -172,9 +172,9 @@ namespace Notesnook.API
|
||||
services.AddScoped<IDbContext, MongoDbContext>();
|
||||
services.AddScoped<IUnitOfWork, UnitOfWork>();
|
||||
|
||||
services.AddRepository<UserSettings>("user_settings")
|
||||
.AddRepository<Monograph>("monographs")
|
||||
.AddRepository<Announcement>("announcements");
|
||||
services.AddRepository<UserSettings>("user_settings", "notesnook")
|
||||
.AddRepository<Monograph>("monographs", "notesnook")
|
||||
.AddRepository<Announcement>("announcements", "notesnook");
|
||||
|
||||
services.AddMongoCollection(Collections.SettingsKey)
|
||||
.AddMongoCollection(Collections.AttachmentsKey)
|
||||
|
||||
@@ -18,11 +18,20 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Streetwriters.Data.DbContexts;
|
||||
using Streetwriters.Data.Repositories;
|
||||
|
||||
namespace Streetwriters.Common.Extensions
|
||||
{
|
||||
public static class ServiceCollectionServiceExtensions
|
||||
{
|
||||
public static IServiceCollection AddRepository<T>(this IServiceCollection services, string collectionName, string database) where T : class
|
||||
{
|
||||
services.AddSingleton((provider) => MongoDbContext.GetMongoCollection<T>(provider.GetService<MongoDB.Driver.IMongoClient>(), database, collectionName));
|
||||
services.AddScoped<Repository<T>>();
|
||||
return services;
|
||||
}
|
||||
|
||||
public static IServiceCollection AddDefaultCors(this IServiceCollection services)
|
||||
{
|
||||
services.AddCors(options =>
|
||||
|
||||
Reference in New Issue
Block a user