// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc(); CosmosDBOptions options = new CosmosDBOptions(Configuration.GetSection("CosmosDB")); DocumentClient documentClient = new DocumentClient(options.Endpoint, options.Key); InitializeDocumentCollections(documentClient).Wait(); services.AddSingleton <IDocumentClient>(documentClient); }
public async Task Configuration_Caches_Clients() { // Arrange var options = new CosmosDBOptions { ConnectionString = "AccountEndpoint=https://someuri;AccountKey=c29tZV9rZXk=;" }; var config = new CosmosDBExtensionConfigProvider(new OptionsWrapper <CosmosDBOptions>(options), new DefaultCosmosDBServiceFactory(), new TestNameResolver(), NullLoggerFactory.Instance); var attribute = new CosmosDBAttribute { Id = "abcdef" }; // Act var context1 = config.CreateContext(attribute); var context2 = config.CreateContext(attribute); var binder = await config.BindForItemAsync(attribute, typeof(Item)); // Assert Assert.Single(config.ClientCache); }
public static async Task <Container> CreateOrGetContainerAsync( CosmosClient cosmosClient, IOptionsMonitor <CosmosDBOptions> monitoringOptions) { CosmosDBOptions options = monitoringOptions.CurrentValue; var databaseResponse = await cosmosClient.CreateDatabaseIfNotExistsAsync(options.CosmosDBName); var containerResponse = await databaseResponse .Database .CreateContainerIfNotExistsAsync( options.CosmosCollectionName, PRATITION_KEY, options.CosmosCollectionRUCap); return(containerResponse.Container); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); services.Configure <CosmosDBOptions>(Configuration); services.AddSingleton <CosmosClient>(serviceProvider => { var monitoringOptions = serviceProvider.GetRequiredService <IOptionsMonitor <CosmosDBOptions> >(); CosmosDBOptions options = monitoringOptions.CurrentValue; var cosmosClient = new CosmosClient( options.CosmosEndpoint, options.CosmosAccessKey); var container = TransactionResultCosmosRepository.CreateOrGetContainerAsync(cosmosClient, monitoringOptions).Result; return(cosmosClient); }); services.AddTransient <ITransactionResultRepository, TransactionResultCosmosRepository>(); services.Configure <BankClientOptions>(Configuration); services.AddHttpClient <BankClient>(); services.AddTransient <IBankClientService, BankClientService>(); services.AddTransient <IPaymentProvider, PaymentProvider>(); services.AddTransient <ITransactionResultMapper, TransactionResultMapper>(); services.AddTransient <ITransactionMapper, TransactionMapper>(); // Register the Swagger generator, defining 1 or more Swagger documents services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Swashbuckle.AspNetCore.Swagger.Info { Title = "Hello Payment Gateway", Version = "v1" }); c.IncludeXmlComments( string.Format(@"{0}\PaymentGateway.xml", System.AppDomain.CurrentDomain.BaseDirectory)); }); }
private static CosmosDBExtensionConfigProvider CreateExtensionConfigProvider(CosmosDBOptions options) { return(new CosmosDBExtensionConfigProvider(new OptionsWrapper <CosmosDBOptions>(options), new DefaultCosmosDBServiceFactory(), _emptyConfig, new TestNameResolver(), NullLoggerFactory.Instance)); }
public DatabaseController(IOptions <CosmosDBOptions> cosmosDBOptions) { _cosmosDBOptions = cosmosDBOptions.Value; this.cosmosDBClient = new CosmosDBClient(_cosmosDBOptions.URI, _cosmosDBOptions.Key); }
public UserDAO(CosmosDBOptions cosmosDBOptions) { _cosmosDBOptions = cosmosDBOptions; }
public HomeController(IOptions <CosmosDBOptions> options) { _cosmosDBOptions = options.Value; }