From f5c3bee2558f90caca6595f28c521054802ce50b Mon Sep 17 00:00:00 2001 From: James Hadwen Date: Thu, 27 Jan 2022 20:15:57 +0700 Subject: [PATCH] Remove static variables from stores --- src/MongoRoleStore.cs | 6 +++--- src/MongoUserOnlyStore.cs | 6 +++--- src/MongoUserStore.cs | 10 +++++----- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/MongoRoleStore.cs b/src/MongoRoleStore.cs index 9fac314..8dac5e0 100644 --- a/src/MongoRoleStore.cs +++ b/src/MongoRoleStore.cs @@ -108,10 +108,10 @@ namespace AspNetCore.Identity.MongoDbCore /// /// Gets the database context for this store. /// - private static IMongoDbContext Context { get; set; } + private IMongoDbContext Context { get; } - private static IMongoRepository _mongoRepository; - private static IMongoRepository MongoRepository + private IMongoRepository _mongoRepository; + private IMongoRepository MongoRepository { get { diff --git a/src/MongoUserOnlyStore.cs b/src/MongoUserOnlyStore.cs index 1e88671..2e7539e 100644 --- a/src/MongoUserOnlyStore.cs +++ b/src/MongoUserOnlyStore.cs @@ -103,10 +103,10 @@ namespace AspNetCore.Identity.MongoDbCore /// /// Gets the database context for this store. /// - private static TContext Context { get; set; } + private TContext Context { get; } - private static IMongoRepository _mongoRepository; - private static IMongoRepository MongoRepository + private IMongoRepository _mongoRepository; + private IMongoRepository MongoRepository { get { diff --git a/src/MongoUserStore.cs b/src/MongoUserStore.cs index af3c69c..9c6d795 100644 --- a/src/MongoUserStore.cs +++ b/src/MongoUserStore.cs @@ -130,18 +130,18 @@ namespace AspNetCore.Identity.MongoDbCore /// /// Gets the database context for this store. /// - private static TContext Context { get; set; } + private TContext Context { get; } - private static object MongoRepositoryInitializationLock = new object(); - private static IMongoRepository _mongoRepository; - private static IMongoRepository MongoRepository + private readonly object _mongoRepositoryInitializationLock = new object(); + private IMongoRepository _mongoRepository; + private IMongoRepository MongoRepository { get { // double checked locking to prevent race to initialize the repository in multithreaded environment. if (_mongoRepository == null) { - lock (MongoRepositoryInitializationLock) + lock (_mongoRepositoryInitializationLock) { if (_mongoRepository == null) {