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); }
public CosmosWrapperService(CosmosService cosmosService, IOptions <CosmosConfig> cosmosConfig) { _cosmosService = cosmosService; this.cosmosConfig = cosmosConfig.Value; }