Skip to content

Commit 76d6cf0

Browse files
committed
Updated template to .NET 6.0
1 parent 97d6050 commit 76d6cf0

13 files changed

Lines changed: 298 additions & 225 deletions

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ services.AddControllers()
3333
.AddOpenServiceBroker();
3434
```
3535

36-
You can use the **[project template](template/)** to quickly set up a pre-configured ASP.NET Core 5.0 project with `OpenServiceBroker.Server`.
36+
You can use the **[project template](template/)** to quickly set up a pre-configured ASP.NET Core 6.0 project with `OpenServiceBroker.Server`.
3737

3838
### Versioning
3939

Lines changed: 100 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,110 @@
11
{
2+
"$schema": "http://json.schemastore.org/template",
23
"author": "Bastian Eicher",
3-
"classifications": [ "Web", "OpenServiceBroker" ],
4+
"classifications": [
5+
"Web",
6+
"WebAPI",
7+
"OpenServiceBroker"
8+
],
49
"name": "Open Service Broker",
510
"shortName": "osb",
611
"identity": "OpenServiceBroker",
712
"groupIdentity": "OpenServiceBroker",
813
"tags": {
9-
"language": "C#"
14+
"language": "C#",
15+
"type": "project"
1016
},
1117
"sourceName": "MyServiceBroker",
12-
"preferNameDirectory": true
18+
"preferNameDirectory": true,
19+
"symbols": {
20+
"kestrelHttpPort": {
21+
"type": "parameter",
22+
"datatype": "integer",
23+
"description": "Port number to use for the HTTP endpoint in launchSettings.json."
24+
},
25+
"kestrelHttpPortGenerated": {
26+
"type": "generated",
27+
"generator": "port",
28+
"parameters": {
29+
"low": 5000,
30+
"high": 5300
31+
}
32+
},
33+
"kestrelHttpPortReplacer": {
34+
"type": "generated",
35+
"generator": "coalesce",
36+
"parameters": {
37+
"sourceVariableName": "kestrelHttpPort",
38+
"fallbackVariableName": "kestrelHttpPortGenerated"
39+
},
40+
"replaces": "5000"
41+
},
42+
"kestrelHttpsPort": {
43+
"type": "parameter",
44+
"datatype": "integer",
45+
"description": "Port number to use for the HTTPS endpoint in launchSettings.json."
46+
},
47+
"kestrelHttpsPortGenerated": {
48+
"type": "generated",
49+
"generator": "port",
50+
"parameters": {
51+
"low": 7000,
52+
"high": 7300
53+
}
54+
},
55+
"kestrelHttpsPortReplacer": {
56+
"type": "generated",
57+
"generator": "coalesce",
58+
"parameters": {
59+
"sourceVariableName": "kestrelHttpsPort",
60+
"fallbackVariableName": "kestrelHttpsPortGenerated"
61+
},
62+
"replaces": "5001"
63+
},
64+
"iisHttpPort": {
65+
"type": "parameter",
66+
"datatype": "integer",
67+
"description": "Port number to use for the IIS Express HTTP endpoint in launchSettings.json."
68+
},
69+
"iisHttpPortGenerated": {
70+
"type": "generated",
71+
"generator": "port"
72+
},
73+
"iisHttpPortReplacer": {
74+
"type": "generated",
75+
"generator": "coalesce",
76+
"parameters": {
77+
"sourceVariableName": "iisHttpPort",
78+
"fallbackVariableName": "iisHttpPortGenerated"
79+
},
80+
"replaces": "8080"
81+
},
82+
"iisHttpsPort": {
83+
"type": "parameter",
84+
"datatype": "integer",
85+
"description": "Port number to use for the IIS Express HTTPS endpoint in launchSettings.json."
86+
},
87+
"iisHttpsPortGenerated": {
88+
"type": "generated",
89+
"generator": "port",
90+
"parameters": {
91+
"low": 44300,
92+
"high": 44399
93+
}
94+
},
95+
"iisHttpsPortReplacer": {
96+
"type": "generated",
97+
"generator": "coalesce",
98+
"parameters": {
99+
"sourceVariableName": "iisHttpsPort",
100+
"fallbackVariableName": "iisHttpsPortGenerated"
101+
},
102+
"replaces": "44300"
103+
}
104+
},
105+
"primaryOutputs": [
106+
{
107+
"path": "MyServiceBroker.csproj"
108+
}
109+
]
13110
}

template/CatalogService.cs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1-
using System.Threading.Tasks;
21
using OpenServiceBroker.Catalogs;
32

4-
namespace MyServiceBroker
3+
namespace MyServiceBroker;
4+
5+
public class CatalogService : ICatalogService
56
{
6-
public class CatalogService : ICatalogService
7-
{
8-
private readonly Catalog _catalog;
7+
private readonly Catalog _catalog;
98

10-
public CatalogService(Catalog catalog)
11-
{
12-
_catalog = catalog;
13-
}
9+
public CatalogService(Catalog catalog)
10+
{
11+
_catalog = catalog;
12+
}
1413

15-
public Task<Catalog> GetCatalogAsync()
16-
{
17-
return Task.FromResult(_catalog);
18-
}
14+
public Task<Catalog> GetCatalogAsync()
15+
{
16+
return Task.FromResult(_catalog);
1917
}
2018
}

template/DbContext.cs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
using Microsoft.EntityFrameworkCore;
22

3-
namespace MyServiceBroker
3+
namespace MyServiceBroker;
4+
5+
/// <summary>
6+
/// Describes the service's database model.
7+
/// Used as a combination of the Unit Of Work and Repository patterns.
8+
/// </summary>
9+
public class DbContext : Microsoft.EntityFrameworkCore.DbContext
410
{
5-
/// <summary>
6-
/// Describes the service's database model.
7-
/// Used as a combination of the Unit Of Work and Repository patterns.
8-
/// </summary>
9-
public class DbContext : Microsoft.EntityFrameworkCore.DbContext
10-
{
11-
public DbSet<ServiceInstanceEntity> ServiceInstances { get; set; } = default!;
11+
public DbSet<ServiceInstanceEntity> ServiceInstances { get; set; } = default!;
1212

13-
public DbContext(DbContextOptions options)
14-
: base(options)
15-
{}
16-
}
13+
public DbContext(DbContextOptions options)
14+
: base(options)
15+
{}
1716
}

template/MyServiceBroker.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>net5.0</TargetFramework>
4+
<TargetFramework>net6.0</TargetFramework>
55
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
67
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
78
<NoWarn>$(NoWarn);1591</NoWarn>
89
</PropertyGroup>
910

1011
<ItemGroup>
11-
<PackageReference Include="OpenServiceBroker.Server" Version="0.4.3" />
12+
<PackageReference Include="OpenServiceBroker.Server" Version="1.0-dev" />
1213
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.21" />
1314
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
1415
<PackageReference Include="Swashbuckle.AspNetCore.Newtonsoft" Version="6.2.3" />

template/Program.cs

Lines changed: 49 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,53 @@
1-
using System.Threading.Tasks;
2-
using Microsoft.AspNetCore.Hosting;
3-
using Microsoft.Extensions.DependencyInjection;
4-
using Microsoft.Extensions.Hosting;
1+
using Microsoft.DotNet.PlatformAbstractions;
2+
using Microsoft.EntityFrameworkCore;
3+
using Microsoft.OpenApi.Models;
4+
using MyServiceBroker;
5+
using Newtonsoft.Json;
6+
using OpenServiceBroker;
7+
using OpenServiceBroker.Catalogs;
8+
using OpenServiceBroker.Instances;
59

6-
namespace MyServiceBroker
10+
var builder = WebApplication.CreateBuilder(args);
11+
12+
// Catalog of available services
13+
string catalogPath = File.ReadAllText(Path.Combine(ApplicationEnvironment.ApplicationBasePath, "catalog.json"));
14+
builder.Services.AddSingleton(JsonConvert.DeserializeObject<Catalog>(catalogPath)!);
15+
16+
// Database for storing provisioned service instances
17+
builder.Services.AddDbContext<MyServiceBroker.DbContext>(options => options.UseSqlite(builder.Configuration.GetConnectionString("Database")));
18+
19+
// Implementations of OpenServiceBroker.Server interfaces
20+
builder.Services.AddTransient<ICatalogService, CatalogService>()
21+
.AddTransient<IServiceInstanceBlocking, ServiceInstanceService>();
22+
23+
// Open Service Broker REST API
24+
builder.Services.AddControllers()
25+
.AddOpenServiceBroker();
26+
27+
// Swagger/OpenAPI
28+
builder.Services.AddEndpointsApiExplorer();
29+
builder.Services.AddSwaggerGen(options =>
730
{
8-
// Manage process lifecycle, configuration and logging
9-
public static class Program
31+
options.SwaggerDoc("v1", new OpenApiInfo
1032
{
11-
public static async Task Main(string[] args)
12-
{
13-
var host = CreateHostBuilder(args).Build();
14-
using (var scope = host.Services.CreateScope())
15-
await scope.ServiceProvider.GetRequiredService<DbContext>().Database.EnsureCreatedAsync();
16-
await host.RunAsync();
17-
}
18-
19-
public static IHostBuilder CreateHostBuilder(string[] args) =>
20-
Host.CreateDefaultBuilder(args)
21-
.ConfigureWebHostDefaults(webBuilder => webBuilder.UseStartup<Startup>());
22-
}
33+
Title = "My Service Broker",
34+
Version = "v1"
35+
});
36+
}).AddSwaggerGenNewtonsoftSupport();
37+
38+
var app = builder.Build();
39+
40+
// Configure the HTTP request pipeline.
41+
if (app.Environment.IsDevelopment())
42+
{
43+
app.UseSwagger();
44+
app.UseSwaggerUI();
2345
}
46+
47+
app.UseHttpsRedirection();
48+
49+
app.UseAuthorization();
50+
51+
app.MapControllers();
52+
53+
app.Run();

template/Properties/launchSettings.json

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
11
{
2+
"$schema": "https://json.schemastore.org/launchsettings.json",
3+
"iisSettings": {
4+
"windowsAuthentication": false,
5+
"anonymousAuthentication": true,
6+
"iisExpress": {
7+
"applicationUrl": "http://localhost:8080",
8+
"sslPort": 44300
9+
}
10+
},
211
"profiles": {
312
"ServiceBroker": {
413
"commandName": "Project",
14+
"dotnetRunMessages": true,
15+
"launchBrowser": true,
16+
"launchUrl": "swagger",
17+
"applicationUrl": "https://localhost:5001;http://localhost:5000",
18+
"environmentVariables": {
19+
"ASPNETCORE_ENVIRONMENT": "Development"
20+
}
21+
},
22+
"IIS Express": {
23+
"commandName": "IISExpress",
524
"launchBrowser": true,
6-
"applicationUrl": "http://localhost:12345",
725
"launchUrl": "swagger",
826
"environmentVariables": {
927
"ASPNETCORE_ENVIRONMENT": "Development"

template/ServiceInstanceEntity.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
using System.ComponentModel.DataAnnotations;
22

3-
namespace MyServiceBroker
3+
namespace MyServiceBroker;
4+
5+
public class ServiceInstanceEntity
46
{
5-
public class ServiceInstanceEntity
6-
{
7-
[Key]
8-
public string Id { get; set; } = default!;
7+
[Key]
8+
public string Id { get; set; } = default!;
99

10-
public string ServiceId { get; set; } = default!;
10+
public string ServiceId { get; set; } = default!;
1111

12-
public string PlanId { get; set; } = default!;
12+
public string PlanId { get; set; } = default!;
1313

14-
public string? Parameters { get; set; }
15-
}
14+
public string? Parameters { get; set; }
1615
}

0 commit comments

Comments
 (0)