-
Notifications
You must be signed in to change notification settings - Fork 252
/
Program.cs
66 lines (50 loc) · 2.1 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
58
59
60
61
62
63
64
65
66
using MySqlEFCore;
using MySqlEFCore.Data;
using Steeltoe.Connector.MySql;
using Steeltoe.Connector.MySql.EFCore;
using Steeltoe.Extensions.Configuration.CloudFoundry;
using Steeltoe.Management.Endpoint;
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
// Steeltoe: Setup
builder.AddCloudFoundryConfiguration();
builder.AddAllActuators();
// Steeltoe: MySQL EF Core Setup.
bool useMultipleDatabases = builder.Configuration.GetValue<bool>("useMultipleDatabases");
if (useMultipleDatabases)
{
// When using multiple databases, specify the service binding name.
// Review appsettings.development.json to see how local connection info is provided.
const string serviceName = "myMySqlService";
builder.Services.AddDbContext<AppDbContext>(options => options.UseMySql(builder.Configuration, serviceName));
builder.Services.AddMySqlHealthContributor(builder.Configuration, serviceName);
const string otherServiceName = "myOtherMySqlService";
builder.Services.AddDbContext<OtherDbContext>(options => options.UseMySql(builder.Configuration, otherServiceName));
builder.Services.AddMySqlHealthContributor(builder.Configuration, otherServiceName);
}
else
{
builder.Services.AddDbContext<AppDbContext>(options => options.UseMySql(builder.Configuration));
builder.Services.AddMySqlHealthContributor(builder.Configuration);
}
// Add services to the container.
builder.Services.AddControllersWithViews();
WebApplication app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");
// Steeltoe: Insert some rows into MySQL table.
await MySqlSeeder.CreateSampleDataAsync(app.Services);
if (useMultipleDatabases)
{
await MySqlSeeder.CreateOtherSampleDataAsync(app.Services);
}
app.Run();