-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
97d6050
commit 76d6cf0
Showing
13 changed files
with
298 additions
and
225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} |
Oops, something went wrong.