From e9fb43b7baa24d60e93106998cd518f2626a4e47 Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Fri, 7 Jun 2024 15:42:26 +0500 Subject: [PATCH] api: minor refactoring --- Notesnook.API/Models/Monograph.cs | 7 +++++++ Notesnook.API/Startup.cs | 13 ++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Notesnook.API/Models/Monograph.cs b/Notesnook.API/Models/Monograph.cs index 992df02..edb9e92 100644 --- a/Notesnook.API/Models/Monograph.cs +++ b/Notesnook.API/Models/Monograph.cs @@ -24,6 +24,13 @@ using Notesnook.API.Interfaces; namespace Notesnook.API.Models { + public class ObjectWithId + { + [BsonId] + [BsonRepresentation(BsonType.ObjectId)] + public string Id { get; set; } + } + public class Monograph : IMonograph { public Monograph() diff --git a/Notesnook.API/Startup.cs b/Notesnook.API/Startup.cs index 39397d2..691c36a 100644 --- a/Notesnook.API/Startup.cs +++ b/Notesnook.API/Startup.cs @@ -76,12 +76,11 @@ namespace Notesnook.API // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { - var dbSettings = new DbSettings + services.AddSingleton(MongoDbContext.CreateMongoDbClient(new DbSettings { ConnectionString = Constants.MONGODB_CONNECTION_STRING, DatabaseName = Constants.MONGODB_DATABASE_NAME - }; - services.AddSingleton(dbSettings); + })); services.TryAddSingleton(); @@ -181,9 +180,9 @@ namespace Notesnook.API .AddMongoCollection(Collections.ColorsKey) .AddMongoCollection(Collections.VaultsKey); - services.TryAddTransient(); - services.TryAddTransient(); - services.TryAddTransient(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); services.AddControllers(); @@ -241,7 +240,7 @@ namespace Notesnook.API realm.Subscribe(IdentityServerTopics.DeleteUserTopic, async (ev) => { IUserService service = app.GetScopedService(); - await service.DeleteUserAsync(ev.UserId, null); + await service.DeleteUserAsync(ev.UserId); }); realm.Subscribe(IdentityServerTopics.ClearCacheTopic, (ev) =>