Skip to content

Commit

Permalink
Commented som things
Browse files Browse the repository at this point in the history
  • Loading branch information
satano committed Jul 25, 2019
1 parent 92a4ae3 commit 395af4a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/DatabaseFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ internal class DatabaseFactory : IDatabaseFactory
private static Dictionary<string, KormBuilder> AddBuildersDictionary(IServiceCollection services)
=> _builders.GetOrAdd(services, _ => new Dictionary<string, KormBuilder>());

/// <summary>
/// Adds <paramref name="builder"/> with name <paramref name="name"/> into the list of builders for
/// <paramref name="services"/>.
/// </summary>
/// <param name="services">Service collection for which the builder is added.</param>
/// <param name="name">The name of the database builder.</param>
/// <param name="builder">Database builder.</param>
/// <returns><see langword="true"/>, if this was the first builder added, otherwise <see langword="false"/>.</returns>
internal static bool AddBuilder(IServiceCollection services, string name, KormBuilder builder)
{
Dictionary<string, KormBuilder> builders = AddBuildersDictionary(services);
Expand All @@ -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;
}

Expand Down
4 changes: 3 additions & 1 deletion src/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ public static class ServiceCollectionExtensions
/// </summary>
public const string KormAutoMigrateKey = "KormAutoMigrate";

private static ConcurrentDictionary<IServiceCollection, bool> _databaseFactoryAdded =
// Only one IDatabaseFactory for service collection must be registered.
// This dictionary holds flags for already used service collections.
private static readonly ConcurrentDictionary<IServiceCollection, bool> _databaseFactoryAdded =
new ConcurrentDictionary<IServiceCollection, bool>();

/// <summary>
Expand Down

0 comments on commit 395af4a

Please sign in to comment.