Created
October 24, 2022 05:13
-
-
Save dbarkol/c4b74267b5cb14e8c9d515294e2db186 to your computer and use it in GitHub Desktop.
Outbox pattern - Dependency injection for Cosmos
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
using Microsoft.Azure.Cosmos; | |
using Microsoft.Azure.Functions.Extensions.DependencyInjection; | |
using Microsoft.Extensions.DependencyInjection; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
[assembly: FunctionsStartup(typeof(OrderMaker.Startup))] | |
namespace OrderMaker | |
{ | |
public class Startup : FunctionsStartup | |
{ | |
public override void Configure(IFunctionsHostBuilder builder) | |
{ | |
// Inject the CosmosDB client as a singleton | |
var connectionString = Environment.GetEnvironmentVariable("CosmosDBConnectionString"); | |
var options = new CosmosClientOptions() | |
{ | |
SerializerOptions = new CosmosSerializationOptions() | |
{ | |
PropertyNamingPolicy = CosmosPropertyNamingPolicy.CamelCase | |
} | |
}; | |
builder.Services.AddSingleton<CosmosClient>(s => new CosmosClient(connectionString, options)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment