This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[FunctionName("DocsByUsingCosmosClient")] | |
public static async Task<IActionResult> Run( | |
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", | |
Route = null)]HttpRequest req, | |
[CosmosDB( | |
databaseName: "ToDoItems", | |
containerName: "Items", | |
Connection = "CosmosDBConnection")] CosmosClient client, | |
ILogger log) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cosmosDB": { | |
"userAgentSuffix": "MyUniqueIdentifier" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[FunctionName("Function1")] | |
public static void Run([CosmosDBTrigger( | |
databaseName: "test", | |
containerName: "items", | |
LeaseContainerPrefix = "test", | |
Connection = "cosmosDB")] | |
IReadOnlyList<MyPOCOWithSystemTextJson> input, ILogger log) | |
{ | |
//... | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[assembly: FunctionsStartup(typeof(FunctionApp1.Startup))] | |
namespace FunctionApp1 | |
{ | |
public class Startup : FunctionsStartup | |
{ | |
public override void Configure(IFunctionsHostBuilder builder) | |
{ | |
builder.Services.AddSingleton<ICosmosDBSerializerFactory, MyCosmosDBSerializerFactory>(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void captureDiagnostics(CosmosDiagnostics diagnostics) | |
{ | |
if (diagnostics.GetClientElapsedTime() > SomePredefinedThresholdTime) | |
{ | |
Console.WriteLine(diagnostics.ToString()); | |
} | |
} | |
services.AddCosmosCache((CosmosCacheOptions cacheOptions) => | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyBusinessClass | |
{ | |
private readonly IDistributedCache cache; | |
public MyBusinessClass(IDistributedCache cache) | |
{ | |
this.cache = cache; | |
} | |
public async Task SomeOperationAsync() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services.AddCosmosCache((CosmosCacheOptions cacheOptions) => | |
{ | |
cacheOptions.ContainerName = "myContainer"; | |
cacheOptions.DatabaseName = "myDatabase"; | |
cacheOptions.CosmosClient = preExistingClient; | |
/* Creates the container if it does not exist */ | |
cacheOptions.CreateIfNotExists = true; | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void ConfigureServices(IServiceCollection services) | |
{ | |
/* Other service configurations */ | |
services.AddCosmosCache((CosmosCacheOptions cacheOptions) => | |
{ | |
CosmosClientBuilder clientBuilder = new CosmosClientBuilder("myConnectionString") | |
.WithApplicationRegion("West US"); | |
cacheOptions.ContainerName = "myContainer"; | |
cacheOptions.DatabaseName = "myDatabase"; | |
cacheOptions.ClientBuilder = clientBuilder; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CosmosClientOptions clientOptions = new CosmosClientOptions(){ | |
// other client options | |
EnableContentResponseOnWrite = false | |
}; | |
CosmosClient client = new CosmosClient("<connection-string>", clientOptions); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<(string, string)> containers = new List<(string, string)> | |
{ | |
("DatabaseNameForContainer1", "ContainerName1"), | |
("DatabaseNameForContainer2", "ContainerName2") | |
}; | |
CosmosClientOptions cosmosClientOptions = new CosmosClientOptions | |
{ | |
ApplicationName = "MyApplicationName", | |
// any other setting I want to customize |
NewerOlder