Skip to content

Commit

Permalink
Updated template to .NET 6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bastianeicher committed Nov 29, 2021
1 parent 97d6050 commit 76d6cf0
Show file tree
Hide file tree
Showing 13 changed files with 298 additions and 225 deletions.
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ services.AddControllers()
.AddOpenServiceBroker();
```

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

### Versioning

Expand Down
103 changes: 100 additions & 3 deletions template/.template.config/template.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,110 @@
{
"$schema": "http://json.schemastore.org/template",
"author": "Bastian Eicher",
"classifications": [ "Web", "OpenServiceBroker" ],
"classifications": [
"Web",
"WebAPI",
"OpenServiceBroker"
],
"name": "Open Service Broker",
"shortName": "osb",
"identity": "OpenServiceBroker",
"groupIdentity": "OpenServiceBroker",
"tags": {
"language": "C#"
"language": "C#",
"type": "project"
},
"sourceName": "MyServiceBroker",
"preferNameDirectory": true
"preferNameDirectory": true,
"symbols": {
"kestrelHttpPort": {
"type": "parameter",
"datatype": "integer",
"description": "Port number to use for the HTTP endpoint in launchSettings.json."
},
"kestrelHttpPortGenerated": {
"type": "generated",
"generator": "port",
"parameters": {
"low": 5000,
"high": 5300
}
},
"kestrelHttpPortReplacer": {
"type": "generated",
"generator": "coalesce",
"parameters": {
"sourceVariableName": "kestrelHttpPort",
"fallbackVariableName": "kestrelHttpPortGenerated"
},
"replaces": "5000"
},
"kestrelHttpsPort": {
"type": "parameter",
"datatype": "integer",
"description": "Port number to use for the HTTPS endpoint in launchSettings.json."
},
"kestrelHttpsPortGenerated": {
"type": "generated",
"generator": "port",
"parameters": {
"low": 7000,
"high": 7300
}
},
"kestrelHttpsPortReplacer": {
"type": "generated",
"generator": "coalesce",
"parameters": {
"sourceVariableName": "kestrelHttpsPort",
"fallbackVariableName": "kestrelHttpsPortGenerated"
},
"replaces": "5001"
},
"iisHttpPort": {
"type": "parameter",
"datatype": "integer",
"description": "Port number to use for the IIS Express HTTP endpoint in launchSettings.json."
},
"iisHttpPortGenerated": {
"type": "generated",
"generator": "port"
},
"iisHttpPortReplacer": {
"type": "generated",
"generator": "coalesce",
"parameters": {
"sourceVariableName": "iisHttpPort",
"fallbackVariableName": "iisHttpPortGenerated"
},
"replaces": "8080"
},
"iisHttpsPort": {
"type": "parameter",
"datatype": "integer",
"description": "Port number to use for the IIS Express HTTPS endpoint in launchSettings.json."
},
"iisHttpsPortGenerated": {
"type": "generated",
"generator": "port",
"parameters": {
"low": 44300,
"high": 44399
}
},
"iisHttpsPortReplacer": {
"type": "generated",
"generator": "coalesce",
"parameters": {
"sourceVariableName": "iisHttpsPort",
"fallbackVariableName": "iisHttpsPortGenerated"
},
"replaces": "44300"
}
},
"primaryOutputs": [
{
"path": "MyServiceBroker.csproj"
}
]
}
24 changes: 11 additions & 13 deletions template/CatalogService.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
using System.Threading.Tasks;
using OpenServiceBroker.Catalogs;

namespace MyServiceBroker
namespace MyServiceBroker;

public class CatalogService : ICatalogService
{
public class CatalogService : ICatalogService
{
private readonly Catalog _catalog;
private readonly Catalog _catalog;

public CatalogService(Catalog catalog)
{
_catalog = catalog;
}
public CatalogService(Catalog catalog)
{
_catalog = catalog;
}

public Task<Catalog> GetCatalogAsync()
{
return Task.FromResult(_catalog);
}
public Task<Catalog> GetCatalogAsync()
{
return Task.FromResult(_catalog);
}
}
23 changes: 11 additions & 12 deletions template/DbContext.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
using Microsoft.EntityFrameworkCore;

namespace MyServiceBroker
namespace MyServiceBroker;

/// <summary>
/// Describes the service's database model.
/// Used as a combination of the Unit Of Work and Repository patterns.
/// </summary>
public class DbContext : Microsoft.EntityFrameworkCore.DbContext
{
/// <summary>
/// Describes the service's database model.
/// Used as a combination of the Unit Of Work and Repository patterns.
/// </summary>
public class DbContext : Microsoft.EntityFrameworkCore.DbContext
{
public DbSet<ServiceInstanceEntity> ServiceInstances { get; set; } = default!;
public DbSet<ServiceInstanceEntity> ServiceInstances { get; set; } = default!;

public DbContext(DbContextOptions options)
: base(options)
{}
}
public DbContext(DbContextOptions options)
: base(options)
{}
}
5 changes: 3 additions & 2 deletions template/MyServiceBroker.csproj
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
<NoWarn>$(NoWarn);1591</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="OpenServiceBroker.Server" Version="0.4.3" />
<PackageReference Include="OpenServiceBroker.Server" Version="1.0-dev" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.21" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
<PackageReference Include="Swashbuckle.AspNetCore.Newtonsoft" Version="6.2.3" />
Expand Down
68 changes: 49 additions & 19 deletions template/Program.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,53 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.DotNet.PlatformAbstractions;
using Microsoft.EntityFrameworkCore;
using Microsoft.OpenApi.Models;
using MyServiceBroker;
using Newtonsoft.Json;
using OpenServiceBroker;
using OpenServiceBroker.Catalogs;
using OpenServiceBroker.Instances;

namespace MyServiceBroker
var builder = WebApplication.CreateBuilder(args);

// Catalog of available services
string catalogPath = File.ReadAllText(Path.Combine(ApplicationEnvironment.ApplicationBasePath, "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 =>
{
// Manage process lifecycle, configuration and logging
public static class Program
options.SwaggerDoc("v1", new OpenApiInfo
{
public static async Task Main(string[] args)
{
var host = CreateHostBuilder(args).Build();
using (var scope = host.Services.CreateScope())
await scope.ServiceProvider.GetRequiredService<DbContext>().Database.EnsureCreatedAsync();
await host.RunAsync();
}

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder => webBuilder.UseStartup<Startup>());
}
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();
20 changes: 19 additions & 1 deletion template/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:8080",
"sslPort": 44300
}
},
"profiles": {
"ServiceBroker": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"applicationUrl": "http://localhost:12345",
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
Expand Down
17 changes: 8 additions & 9 deletions template/ServiceInstanceEntity.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
using System.ComponentModel.DataAnnotations;

namespace MyServiceBroker
namespace MyServiceBroker;

public class ServiceInstanceEntity
{
public class ServiceInstanceEntity
{
[Key]
public string Id { get; set; } = default!;
[Key]
public string Id { get; set; } = default!;

public string ServiceId { get; set; } = default!;
public string ServiceId { get; set; } = default!;

public string PlanId { get; set; } = default!;
public string PlanId { get; set; } = default!;

public string? Parameters { get; set; }
}
public string? Parameters { get; set; }
}
Loading

0 comments on commit 76d6cf0

Please sign in to comment.