-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
57 lines (46 loc) · 1.96 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System.IO;
using System.Threading.Tasks;
using CosmosEfCore.Config;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
namespace CosmosEfCore
{
class Program
{
public static async Task Main(string[] args)
{
var services = ConfigureServices();
var serviceProvider = services.BuildServiceProvider();
await serviceProvider.GetService<University>().Run();
}
private static IServiceCollection ConfigureServices()
{
var config = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: false)
.AddUserSecrets<Program>()
.Build();
var services = new ServiceCollection();
services.AddLogging(builder => builder.AddDebug().AddConsole());
services.Configure<CosmosSettings>(config.GetSection("CosmosSettings"));
var serviceProvider = services.BuildServiceProvider();
var cosmos = serviceProvider.GetService<IOptions<CosmosSettings>>().Value;
services.AddDbContextPool<UniversityContext>(options =>
{
options.UseCosmos(cosmos.ServiceEndpoint, cosmos.Secret, cosmos.DatabaseName);
options.EnableDetailedErrors(true);
});
//var cosmosConfig = Configuration.GetSection("CosmosDb");
//services.AddDbContext<UniversityContext>(options =>
//{
// options.UseCosmos(cosmosConfig["Endpoint"], cosmosConfig["Secret"], cosmosConfig["DatabaseName"]);
// options.EnableDetailedErrors(true);
//}, ServiceLifetime.Transient);
services.AddTransient<University>();
return services;
}
}
}