-
-
Save christiannagel/8313546b3bea716f81c4e3388ea509dd to your computer and use it in GitHub Desktop.
Configure DI container for EF Core using Azure Cosmos DB
This file contains 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 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