Пример #1
0
        public static CmsBuilder ConfigureCosmosDB(this CmsBuilder builder, Func <StorageConfiguration> storageConfigFunc)
        {
            var Configuration = builder.Configuration;
            var services      = builder.Services;

            services.Configure <CosmosConfig>(Configuration.GetSection(nameof(CosmosConfig)));

            StorageConfiguration storageConfig = storageConfigFunc();

            services.AddTransient <CosmosService>();

            if (storageConfig.ReadCmsItems)
            {
                services.AddTransient <IReadCmsItem, CosmosWrapperService>();
            }
            if (storageConfig.WriteCmsItems)
            {
                services.AddTransient <IWriteCmsItem, CosmosWrapperService>();
            }

            var cosmosConfig = new CosmosConfig();

            Configuration.GetSection(nameof(CosmosConfig)).Bind(cosmosConfig);
            var cosmosConfigOptions = Options.Create <CosmosConfig>(cosmosConfig);

            var cosmosService = new CosmosService(cosmosConfigOptions, Options.Create(new CmsConfiguration()));

            cosmosService.InitializeContainer();

            return(builder);
        }
Пример #2
0
 public CosmosWrapperService(CosmosService cosmosService, IOptions <CosmosConfig> cosmosConfig)
 {
     _cosmosService    = cosmosService;
     this.cosmosConfig = cosmosConfig.Value;
 }