Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial work on webhosting #1179

Merged
merged 3 commits into from
Jul 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
<PackageVersion Include="Rocket.Surgery.Extensions" Version="11.4.1" />
<PackageVersion Include="Rocket.Surgery.Hosting" Version="12.2.3" />
<PackageVersion Include="Rocket.Surgery.Hosting.Abstractions" Version="12.2.3" />
<PackageVersion Include="Rocket.Surgery.Web.Hosting" Version="12.2.3" />
<PackageVersion Include="Rocket.Surgery.WebAssembly.Hosting" Version="12.2.3" />
<PackageVersion Include="Scrutor" Version="4.2.0" />
<PackageVersion Include="Serilog" Version="2.11.0" />
Expand Down
15 changes: 15 additions & 0 deletions LaunchPad.sln
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample.BlazorWasm", "sample
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample.BlazorWasm.Tests", "test\Sample.BlazorWasm.Tests\Sample.BlazorWasm.Tests.csproj", "{A2C670CA-EFDD-468E-BEA1-D6D5A97270C4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rocket.Surgery.LaunchPad.Web.Hosting", "src\Web.Hosting\Rocket.Surgery.LaunchPad.Web.Hosting.csproj", "{10D4A16B-F9F0-4D88-8705-7AB36E20D8EF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -729,6 +731,18 @@ Global
{A2C670CA-EFDD-468E-BEA1-D6D5A97270C4}.Release|x64.Build.0 = Release|Any CPU
{A2C670CA-EFDD-468E-BEA1-D6D5A97270C4}.Release|x86.ActiveCfg = Release|Any CPU
{A2C670CA-EFDD-468E-BEA1-D6D5A97270C4}.Release|x86.Build.0 = Release|Any CPU
{10D4A16B-F9F0-4D88-8705-7AB36E20D8EF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{10D4A16B-F9F0-4D88-8705-7AB36E20D8EF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{10D4A16B-F9F0-4D88-8705-7AB36E20D8EF}.Debug|x64.ActiveCfg = Debug|Any CPU
{10D4A16B-F9F0-4D88-8705-7AB36E20D8EF}.Debug|x64.Build.0 = Debug|Any CPU
{10D4A16B-F9F0-4D88-8705-7AB36E20D8EF}.Debug|x86.ActiveCfg = Debug|Any CPU
{10D4A16B-F9F0-4D88-8705-7AB36E20D8EF}.Debug|x86.Build.0 = Debug|Any CPU
{10D4A16B-F9F0-4D88-8705-7AB36E20D8EF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{10D4A16B-F9F0-4D88-8705-7AB36E20D8EF}.Release|Any CPU.Build.0 = Release|Any CPU
{10D4A16B-F9F0-4D88-8705-7AB36E20D8EF}.Release|x64.ActiveCfg = Release|Any CPU
{10D4A16B-F9F0-4D88-8705-7AB36E20D8EF}.Release|x64.Build.0 = Release|Any CPU
{10D4A16B-F9F0-4D88-8705-7AB36E20D8EF}.Release|x86.ActiveCfg = Release|Any CPU
{10D4A16B-F9F0-4D88-8705-7AB36E20D8EF}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -787,5 +801,6 @@ Global
{A64647FF-BCBA-4B13-BC99-CDE23C1D3CE8} = {8FFDF555-DB50-45F9-9A2D-6410F39151C3}
{B786542C-3EE7-4B6C-9C5B-23E5CA4FE07C} = {5D11C19B-E8E4-4CE3-9C8A-1D368578EBCB}
{A2C670CA-EFDD-468E-BEA1-D6D5A97270C4} = {DF33E0FB-9790-4654-B60F-8AB22E0CC3D1}
{10D4A16B-F9F0-4D88-8705-7AB36E20D8EF} = {8FFDF555-DB50-45F9-9A2D-6410F39151C3}
EndGlobalSection
EndGlobal
4 changes: 4 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ A common set of libraries used to build console and web applications.
| Rocket.Surgery.LaunchPad.Spatial | [![nuget-version-ze4kfhfg7xqg-badge]![nuget-downloads-ze4kfhfg7xqg-badge]][nuget-ze4kfhfg7xqg] |
| Rocket.Surgery.LaunchPad.Spatial.NewtonsoftJson | [![nuget-version-qmfh1x0xpofq-badge]![nuget-downloads-qmfh1x0xpofq-badge]][nuget-qmfh1x0xpofq] |
| Rocket.Surgery.LaunchPad.Testing | [![nuget-version-bhdja8ikzcgq-badge]![nuget-downloads-bhdja8ikzcgq-badge]][nuget-bhdja8ikzcgq] |
| Rocket.Surgery.LaunchPad.Web.Hosting | [![nuget-version-r6lkw/f1bsvg-badge]![nuget-downloads-r6lkw/f1bsvg-badge]][nuget-r6lkw/f1bsvg] |
<!-- nuget packages -->

# Whats next?
Expand Down Expand Up @@ -132,6 +133,9 @@ TBD
[nuget-bhdja8ikzcgq]: https://www.nuget.org/packages/Rocket.Surgery.LaunchPad.Testing/
[nuget-version-bhdja8ikzcgq-badge]: https://img.shields.io/nuget/v/Rocket.Surgery.LaunchPad.Testing.svg?color=004880&logo=nuget&style=flat-square "NuGet Version"
[nuget-downloads-bhdja8ikzcgq-badge]: https://img.shields.io/nuget/dt/Rocket.Surgery.LaunchPad.Testing.svg?color=004880&logo=nuget&style=flat-square "NuGet Downloads"
[nuget-r6lkw/f1bsvg]: https://www.nuget.org/packages/Rocket.Surgery.LaunchPad.Web.Hosting/
[nuget-version-r6lkw/f1bsvg-badge]: https://img.shields.io/nuget/v/Rocket.Surgery.LaunchPad.Web.Hosting.svg?color=004880&logo=nuget&style=flat-square "NuGet Version"
[nuget-downloads-r6lkw/f1bsvg-badge]: https://img.shields.io/nuget/dt/Rocket.Surgery.LaunchPad.Web.Hosting.svg?color=004880&logo=nuget&style=flat-square "NuGet Downloads"
<!-- generated references -->

<!-- nuke-data
Expand Down
5 changes: 5 additions & 0 deletions sample/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@
<IsPackable>false</IsPackable>
<NoWarn>$(NoWarn);1591</NoWarn>
</PropertyGroup>
<ItemGroup>
<InternalsVisibleTo Include="Sample.Graphql.Tests" />
<InternalsVisibleTo Include="Sample.Pages.Tests" />
<InternalsVisibleTo Include="Sample.Restful.Tests" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion sample/Sample.BlazorServer/Sample.BlazorServer.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net6.0</TargetFrameworks>
<TargetFrameworks>net6.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion sample/Sample.Command/Sample.Command.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp3.1;net6.0</TargetFrameworks>
<TargetFrameworks>net6.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Foundation\Rocket.Surgery.LaunchPad.Foundation.csproj" />
Expand Down
5 changes: 1 addition & 4 deletions sample/Sample.Core/DataConvention.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

namespace Sample.Core;

[LiveConvention]
internal class DataConvention : IServiceConvention
{
public void Register(IConventionContext context, IConfiguration configuration, IServiceCollection services)
Expand All @@ -24,11 +25,7 @@ public void Register(IConventionContext context, IConfiguration configuration, I
#pragma warning restore CA2000
connection.Open();
services
#if NETSTANDARD
.AddDbContextPool<RocketDbContext>(
#else
.AddPooledDbContextFactory<RocketDbContext>(
#endif
x => x
.ReplaceService<IValueConverterSelector, StronglyTypedIdValueConverterSelector>()
.EnableDetailedErrors()
Expand Down
13 changes: 13 additions & 0 deletions sample/Sample.Core/Domain/RocketDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Rocket.Surgery.LaunchPad.EntityFramework;
using Sample.Core.Models;

namespace Sample.Core.Domain;

Expand All @@ -13,6 +14,18 @@ public class RocketDbContext : LpContext<RocketDbContext>

public DbSet<ReadyRocket> Rockets { get; set; } = null!;
public DbSet<LaunchRecord> LaunchRecords { get; set; } = null!;

#if NET6_0_OR_GREATER
protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder)
{
configurationBuilder
.Properties<LaunchRecordId>()
.HaveConversion<LaunchRecordId.EfCoreValueConverter>();
configurationBuilder
.Properties<RocketId>()
.HaveConversion<RocketId.EfCoreValueConverter>();
}
#endif
}

public class StronglyTypedIdValueConverterSelector : ValueConverterSelector
Expand Down
2 changes: 1 addition & 1 deletion sample/Sample.Core/Sample.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.1;net6.0</TargetFrameworks>
<TargetFrameworks>net6.0</TargetFrameworks>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion sample/Sample.Grpc/Sample.Grpc.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net6.0</TargetFrameworks>
<TargetFrameworks>net6.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion sample/Sample.Pages/Sample.Pages.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net6.0</TargetFrameworks>
<TargetFrameworks>net6.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\AspNetCore.AppMetrics\Rocket.Surgery.LaunchPad.AspNetCore.AppMetrics.csproj" />
Expand Down
71 changes: 58 additions & 13 deletions sample/Sample.Restful/Program.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,66 @@
using Microsoft.Extensions.DependencyModel;
using Rocket.Surgery.Conventions;
using Rocket.Surgery.Hosting;
using System.Reflection;
using Hellang.Middleware.ProblemDetails;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.OpenApi.Models;
using Rocket.Surgery.LaunchPad.AspNetCore;
using Rocket.Surgery.LaunchPad.AspNetCore.AppMetrics;
using Rocket.Surgery.Web.Hosting;
using Sample.Restful;
using Serilog;
using Swashbuckle.AspNetCore.SwaggerGen;

namespace Sample.Restful;
var builder = WebApplication.CreateBuilder(args)
.ConfigureRocketSurgery(Imports.GetConventions);

[ImportConventions]
public static partial class Program
{
public static void Main(string[] args)
builder.Services.AddControllers().AddControllersAsServices();
builder.Services
.Configure<SwaggerGenOptions>(
c => c.SwaggerDoc(
"v1",
new OpenApiInfo
{
Version = typeof(Program).GetCustomAttribute<AssemblyVersionAttribute>()?.Version
?? typeof(Program).GetCustomAttribute<AssemblyFileVersionAttribute>()?.Version ?? "0.1.0",
Title = "Test Application",
}
)
);

var app = builder.Build();
app.UseProblemDetails();
app.UseHttpsRedirection();

// Should this move into an extension method?
app.UseSerilogRequestLogging(
x =>
{
CreateHostBuilder(args).Build().Run();
x.GetLevel = LaunchPadLogHelpers.DefaultGetLevel;
x.EnrichDiagnosticContext = LaunchPadLogHelpers.DefaultEnrichDiagnosticContext;
}
);
app.UseMetricsAllMiddleware();

app.UseRouting();

app
.UseSwaggerUI()
.UseReDoc();

public static IHostBuilder CreateHostBuilder(string[] args)
app.UseAuthorization();

app.UseEndpoints(
endpoints =>
{
return Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder => webBuilder.UseStartup<Startup>())
.LaunchWith(RocketBooster.ForDependencyContext(DependencyContext.Default), z => z.WithConventionsFrom(GetConventions));
endpoints.MapControllers();

// Should this move into an extension method?
endpoints.MapSwagger();
endpoints.MapAppMetrics();
}
);
app.Run();

public partial class Program
{
}
5 changes: 2 additions & 3 deletions sample/Sample.Restful/Sample.Restful.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net6.0</TargetFrameworks>
<TargetFrameworks>net6.0</TargetFrameworks>
<OpenApiGenerateDocumentsOnBuild>true</OpenApiGenerateDocumentsOnBuild>
<IncludeOpenAPIAnalyzers>true</IncludeOpenAPIAnalyzers>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\AspNetCore.AppMetrics\Rocket.Surgery.LaunchPad.AspNetCore.AppMetrics.csproj" />
<ProjectReference Include="..\..\src\AppMetrics\Rocket.Surgery.LaunchPad.AppMetrics.csproj" />
<ProjectReference Include="..\..\src\AspNetCore\Rocket.Surgery.LaunchPad.AspNetCore.csproj" />
<ProjectReference Include="..\..\src\Hosting\Rocket.Surgery.LaunchPad.Hosting.csproj" />
<ProjectReference Include="..\..\src\Web.Hosting\Rocket.Surgery.LaunchPad.Web.Hosting.csproj" />
<ProjectReference Include="..\Sample.Core\Sample.Core.csproj" />
<PackageReference
Include="Microsoft.Extensions.ApiDescription.Server"
Expand Down
73 changes: 0 additions & 73 deletions sample/Sample.Restful/Startup.cs

This file was deleted.

2 changes: 1 addition & 1 deletion sample/Sample.Worker/Sample.Worker.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk.Worker">
<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net6.0</TargetFrameworks>
<TargetFrameworks>net6.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" />
Expand Down
Loading