diff --git a/src/DatabaseFactory.cs b/src/DatabaseFactory.cs index b7643cb..0665dda 100644 --- a/src/DatabaseFactory.cs +++ b/src/DatabaseFactory.cs @@ -15,6 +15,14 @@ internal class DatabaseFactory : IDatabaseFactory private static Dictionary AddBuildersDictionary(IServiceCollection services) => _builders.GetOrAdd(services, _ => new Dictionary()); + /// + /// Adds with name into the list of builders for + /// . + /// + /// Service collection for which the builder is added. + /// The name of the database builder. + /// Database builder. + /// , if this was the first builder added, otherwise . internal static bool AddBuilder(IServiceCollection services, string name, KormBuilder builder) { Dictionary builders = AddBuildersDictionary(services); @@ -23,6 +31,9 @@ internal static bool AddBuilder(IServiceCollection services, string name, KormBu throw new ArgumentException(string.Format(Resources.DuplicateDatabaseName, name), nameof(name)); } builders.Add(name, builder); + + // We need to know if it was the first builder added. + // The first builder is added into the service container also as IDatabase dependency. return builders.Count == 1; } diff --git a/src/ServiceCollectionExtensions.cs b/src/ServiceCollectionExtensions.cs index 19b3fa1..a02b36f 100644 --- a/src/ServiceCollectionExtensions.cs +++ b/src/ServiceCollectionExtensions.cs @@ -25,7 +25,9 @@ public static class ServiceCollectionExtensions /// public const string KormAutoMigrateKey = "KormAutoMigrate"; - private static ConcurrentDictionary _databaseFactoryAdded = + // Only one IDatabaseFactory for service collection must be registered. + // This dictionary holds flags for already used service collections. + private static readonly ConcurrentDictionary _databaseFactoryAdded = new ConcurrentDictionary(); ///