Ejemplo n.º 1
0
        private async Task CreateContainerIfNotExistsAsync(CosmosContainerOptions options)
        {
            // TODO: Container単位のDefaultThroughputの実装
            CosmosContainer container = await Database.Containers.CreateContainerIfNotExistsAsync(options.ToCosmosContainerSettings());

            var throughput = await container.ReadProvisionedThroughputAsync();

            _logger.LogInformation($"Container:{container.Id}; throughput:{ConvertThroughputLogString(throughput)}");
        }
Ejemplo n.º 2
0
        private async Task CreateContainerIfNotExistsAsync(CosmosContainerOptions options)
        {
            // TODO: Container単位のDefaultThroughputの実装
            Container container = await Database.CreateContainerIfNotExistsAsync(options.ToContainerProperties());

            var throughputResponse = await container.ReadThroughputAsync();

            _logger.LogInformation($"Container:{container.Id}; throughput:{ConvertThroughputLogString(throughputResponse?.Resource?.Throughput)}");
        }
Ejemplo n.º 3
0
        public CosmosContainer(CosmosContainerOptions <T> options, ILoggerFactory loggerFactory)
        {
            _options = options ?? throw new ArgumentNullException(nameof(options));
            _logger  = loggerFactory.CreateLogger <CosmosContainer <T> >()
                       ?? throw new ArgumentNullException(nameof(loggerFactory));

            ValidateOptions(options);
            _containerProvider = CosmosContainerProvider.CreateFromOptions(options);
        }
Ejemplo n.º 4
0
 public static IServiceCollection AddCosmosRepository <T>(this IServiceCollection collection, Action <CosmosContainerOptions <T>, IConfiguration> configurationFactory)
     where T : class, IEntity
 {
     collection.AddSingleton(sp =>
     {
         var options       = new CosmosContainerOptions <T>();
         var configuration = sp.GetRequiredService <IConfiguration>();
         configurationFactory(options, configuration);
         return(options);
     });
     collection.AddSingleton <IRepositoryFactory <T>, CosmosContainerRepositoryFactory <T> >();
     collection.AddSingleton <IRepository <T> >(sp => sp.GetRequiredService <IRepositoryFactory <T> >().Create());
     return(collection);
 }