generated from staticwebdev/blazor-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Startup.cs
34 lines (31 loc) · 1.54 KB
/
Startup.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using Microsoft.Azure.Cosmos.Fluent;
using Microsoft.Azure.Functions.Extensions.DependencyInjection;
using Microsoft.Extensions.Caching.Cosmos;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;
[assembly: FunctionsStartup(typeof(BlazorApp.Api.Startup))]
namespace BlazorApp.Api
{
public class Startup : FunctionsStartup
{
private static IConfigurationRoot configuration = new ConfigurationBuilder()
.SetBasePath(Environment.CurrentDirectory)
// Loading the config, can be renamed to any file or any config source
.AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
public override void Configure(IFunctionsHostBuilder builder)
{
builder.Services.AddCosmosCache((CosmosCacheOptions cacheOptions) =>
{
cacheOptions.ContainerName = "myCacheContainer";
cacheOptions.DatabaseName = "myCacheDatabase";
cacheOptions.ClientBuilder = new CosmosClientBuilder(configuration["CosmosDBConnectionString"])
//.WithApplicationRegion("West US") consider configuring regional preference for data locality
.WithConnectionModeGateway(); // See https://docs.microsoft.com/azure/cosmos-db/sql-sdk-connection-modes, can remove and use Direct mode for more performance
cacheOptions.CreateIfNotExists = true;
});
}
}
}