Use Azure Cosmos DB with Your ASP.NET App

Use Azure Cosmos DB with Your ASP.NET App

‘This tutorial walks you through building an ASP.NET 4.x application using Azure Cosmos DB for storage.’

pbrooke

Chris,

great article thanks - it really helped me get started on better organising config.

I slightly modified your approach and used a static config class & static constructor so there’s just a single place for all the relevant info with no requirement to instantiate the class; once it’s declared it’s available.

public static class CosmosConfig
{
public static string EndPointUrl { get; set; }
public static string AuthorizationKey { get; set; }
public static string DatabaseId { get; set; }
public static string ConnectionString { get; set; }

static CosmosConfig()
{
DatabaseId = ConfigurationManager.AppSettings[“Cosmos.DatabaseId”];
EndPointUrl = ConfigurationManager.AppSettings[“Cosmos.EndPointUrl”];
AuthorizationKey = ConfigurationManager.AppSettings[“Cosmos.AuthorizationKey”];
ConnectionString = ConfigurationManager.AppSettings[“Cosmos.ConnectionString”];
}
}

Thanks for putting up the code - very helpful