-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathProgram.cs
More file actions
52 lines (40 loc) · 1.5 KB
/
Program.cs
File metadata and controls
52 lines (40 loc) · 1.5 KB
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
using Microsoft.EntityFrameworkCore;
using Microsoft.OpenApi;
using MyServiceBroker;
using Newtonsoft.Json;
using OpenServiceBroker;
using OpenServiceBroker.Catalogs;
using OpenServiceBroker.Instances;
var builder = WebApplication.CreateBuilder(args);
// Catalog of available services
string catalogPath = File.ReadAllText(Path.Combine(AppContext.BaseDirectory, "catalog.json"));
builder.Services.AddSingleton(JsonConvert.DeserializeObject<Catalog>(catalogPath)!);
// Database for storing provisioned service instances
builder.Services.AddDbContext<MyServiceBroker.DbContext>(options => options.UseSqlite(builder.Configuration.GetConnectionString("Database")));
// Implementations of OpenServiceBroker.Server interfaces
builder.Services.AddTransient<ICatalogService, CatalogService>()
.AddTransient<IServiceInstanceBlocking, ServiceInstanceService>();
// Open Service Broker REST API
builder.Services.AddControllers()
.AddOpenServiceBroker();
// Swagger/OpenAPI
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(options =>
{
options.SwaggerDoc("v1", new OpenApiInfo
{
Title = "My Service Broker",
Version = "v1"
});
}).AddSwaggerGenNewtonsoftSupport();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();