コード例 #1
0
        public static IServiceCollection AddCosmosDb(this IServiceCollection services, Action <CosmosDbClientBuilder> configure = null)
        {
            services.TryAddSingleton <ICosmosDbContainerFactory, CosmosDbContainerFactory>();

            services.AddSingleton <CosmosDbClientBuilder>(provider =>
            {
                CosmosDbClientBuilder clientBuilder = new CosmosDbClientBuilder(services);

                configure?.Invoke(clientBuilder);

                return(clientBuilder);
            });

            services.AddSingleton <ICosmosDbClient>(provider => provider.GetRequiredService <CosmosDbClientBuilder>().Build());

            return(services);
        }
コード例 #2
0
        public static IServiceCollection AddCosmosDb(this IServiceCollection services, Action <CosmosDbClientBuilder> configure = null)
        {
            services.AddTransient(provider =>
            {
                var config           = provider.GetRequiredService <IConfiguration>();
                var containerFactory = provider.GetService <ICosmosDbContainerFactory>();

                CosmosDbClientBuilder builder = new CosmosDbClientBuilder()
                                                .ReadConfiguration(config);

                builder.WithContainerFactory(containerFactory);

                configure?.Invoke(builder);

                return(builder);
            });

            services.AddSingleton <ICosmosDbClient>(provider => provider.GetRequiredService <CosmosDbClientBuilder>().Build());

            return(services);
        }