Skip to content

Instantly share code, notes, and snippets.

@christiannagel
Last active Oct 18, 2018
Embed
What would you like to do?
Configure DI container for EF Core using Azure Cosmos DB
public static void ConfigureServices()
{
var configurationBuilder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json");
#if DEBUG
configurationBuilder.AddUserSecrets("1E2D66CC-11C9-4DE7-B25E-F1EAA5F0154A");
#endif
IConfigurationRoot config = configurationBuilder.Build();
IConfigurationSection configSection = config.GetSection("CosmosSettings");
var services = new ServiceCollection();
services.AddDbContext<BooksContext>(options => options.UseCosmos(configSection["ServiceEndpoint"], configSection["AuthKey"], configSection["DatabaseName"]));
services.AddTransient<BooksService>();
services.AddLogging(options =>
options.AddDebug().SetMinimumLevel(LogLevel.Trace));
Container = services.BuildServiceProvider();
}
public static ServiceProvider Container { get; private set; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment