Skip to content

Instantly share code, notes, and snippets.

@christiannagel
Last active October 18, 2018 08:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christiannagel/8313546b3bea716f81c4e3388ea509dd to your computer and use it in GitHub Desktop.
Save christiannagel/8313546b3bea716f81c4e3388ea509dd to your computer and use it in GitHub Desktop.
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