Exemple #1
0
        /// <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 void AddBuilder(IServiceCollection services, string name, KormBuilder builder)
        {
            Dictionary <string, KormBuilder> builders = AddBuildersDictionary(services);

            if (builders.ContainsKey(name))
            {
                throw new ArgumentException(string.Format(Resources.DuplicateDatabaseName, name), nameof(name));
            }
            builders.Add(name, builder);
        }
Exemple #2
0
        private static KormBuilder AddKormBuilder(
            IServiceCollection services,
            string name,
            KormConnectionSettings connectionSettings)
        {
            AddDatabaseFactory(services);
            var builder = new KormBuilder(services, connectionSettings);

            DatabaseFactory.AddBuilder(services, name, builder);
            services.TryAdd(ServiceDescriptor.Scoped <IDatabase>(
                                serviceProvider => serviceProvider.GetRequiredService <IDatabaseFactory>().GetDatabase(name)));
            return(builder);
        }
Exemple #3
0
        IMigrationsRunner IDatabaseFactory.GetMigrationsRunner(string name)
        {
            KormBuilder builder = GetBuilder(name);

            return(builder.MigrationsRunner);
        }
Exemple #4
0
        IDatabase IDatabaseFactory.GetDatabase(string name)
        {
            KormBuilder builder = GetBuilder(name);

            return(_databases.GetOrAdd(name, _ => builder.Build()));
        }