Skip to content

Commit

Permalink
Added support for on-host-lifecycle events (#1989)
Browse files Browse the repository at this point in the history
  • Loading branch information
david-driscoll authored Apr 30, 2024
1 parent fd2eb25 commit a1f25e2
Show file tree
Hide file tree
Showing 28 changed files with 515 additions and 77 deletions.
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"commands": ["docfx"]
},
"strawberryshake.tools": {
"version": "14.0.0-p.90",
"version": "14.0.0-p.93",
"commands": ["dotnet-graphql"]
},
"dotnet-outdated-tool": {
Expand Down
60 changes: 32 additions & 28 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?xml version="1.0" encoding="utf-8" ?>
<Project>
<ItemGroup>
<PackageVersion Include="Microsoft.Extensions.Http.Resilience" Version="8.4.0" />
<PackageVersion Include="Microsoft.Extensions.ServiceDiscovery" Version="8.0.0-preview.6.24214.1" />
<PackageVersion Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="3.3.4" />
Expand Down Expand Up @@ -32,27 +34,27 @@
<PackageVersion Include="Grpc.AspNetCore" Version="2.62.0" />
<PackageVersion Include="Humanizer.Core" Version="2.14.1" />
<PackageVersion Include="Hellang.Middleware.ProblemDetails" Version="6.5.1" />
<PackageVersion Include="HotChocolate" Version="14.0.0-p.90" />
<PackageVersion Include="HotChocolate.Abstractions" Version="14.0.0-p.90" />
<PackageVersion Include="HotChocolate.AspNetCore" Version="14.0.0-p.90" />
<PackageVersion Include="HotChocolate.Data" Version="14.0.0-p.90" />
<PackageVersion Include="HotChocolate.Diagnostics" Version="14.0.0-p.90" />
<PackageVersion Include="HotChocolate.Execution.Abstractions" Version="14.0.0-p.90" />
<PackageVersion Include="HotChocolate.Data.AutoMapper" Version="14.0.0-p.90" />
<PackageVersion Include="HotChocolate.Data.EntityFramework" Version="14.0.0-p.90" />
<PackageVersion Include="HotChocolate.Data.Spatial" Version="14.0.0-p.90" />
<PackageVersion Include="HotChocolate.Types.Analyzers" Version="14.0.0-p.90" />
<PackageVersion Include="HotChocolate.Types.CursorPagination" Version="14.0.0-p.90" />
<PackageVersion Include="HotChocolate.Types.OffsetPagination" Version="14.0.0-p.90" />
<PackageVersion Include="HotChocolate.Types.NodaTime" Version="14.0.0-p.90" />
<PackageVersion Include="HotChocolate.Types.Spatial" Version="14.0.0-p.90" />
<PackageVersion Include="StrawberryShake.Transport.Http" Version="14.0.0-p.90" />
<PackageVersion Include="StrawberryShake" Version="14.0.0-p.90" />
<PackageVersion Include="StrawberryShake.Core" Version="14.0.0-p.90" />
<PackageVersion Include="StrawberryShake.Server" Version="14.0.0-p.90" />
<PackageVersion Include="StrawberryShake.Maui" Version="14.0.0-p.90" />
<PackageVersion Include="StrawberryShake.Blazor" Version="14.0.0-p.90" />
<PackageVersion Include="StrawberryShake.Razor" Version="14.0.0-p.90" />
<PackageVersion Include="HotChocolate" Version="14.0.0-p.93" />
<PackageVersion Include="HotChocolate.Abstractions" Version="14.0.0-p.93" />
<PackageVersion Include="HotChocolate.AspNetCore" Version="14.0.0-p.93" />
<PackageVersion Include="HotChocolate.Data" Version="14.0.0-p.93" />
<PackageVersion Include="HotChocolate.Diagnostics" Version="14.0.0-p.93" />
<PackageVersion Include="HotChocolate.Execution.Abstractions" Version="14.0.0-p.93" />
<PackageVersion Include="HotChocolate.Data.AutoMapper" Version="14.0.0-p.93" />
<PackageVersion Include="HotChocolate.Data.EntityFramework" Version="14.0.0-p.93" />
<PackageVersion Include="HotChocolate.Data.Spatial" Version="14.0.0-p.93" />
<PackageVersion Include="HotChocolate.Types.Analyzers" Version="14.0.0-p.93" />
<PackageVersion Include="HotChocolate.Types.CursorPagination" Version="14.0.0-p.93" />
<PackageVersion Include="HotChocolate.Types.OffsetPagination" Version="14.0.0-p.93" />
<PackageVersion Include="HotChocolate.Types.NodaTime" Version="14.0.0-p.93" />
<PackageVersion Include="HotChocolate.Types.Spatial" Version="14.0.0-p.93" />
<PackageVersion Include="StrawberryShake.Transport.Http" Version="14.0.0-p.93" />
<PackageVersion Include="StrawberryShake" Version="14.0.0-p.93" />
<PackageVersion Include="StrawberryShake.Core" Version="14.0.0-p.93" />
<PackageVersion Include="StrawberryShake.Server" Version="14.0.0-p.93" />
<PackageVersion Include="StrawberryShake.Maui" Version="14.0.0-p.93" />
<PackageVersion Include="StrawberryShake.Blazor" Version="14.0.0-p.93" />
<PackageVersion Include="StrawberryShake.Razor" Version="14.0.0-p.93" />
<PackageVersion Include="MediatR" Version="12.2.0" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.0" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.0" />
Expand All @@ -72,6 +74,7 @@
<PackageVersion Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Options" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.9.2" />
<PackageVersion Include="Microsoft.CodeAnalysis.Common" Version="4.9.2" />
Expand All @@ -91,15 +94,15 @@
<PackageVersion Include="Polly" Version="8.3.1" />
<PackageVersion Include="StronglyTypedId" Version="1.0.0-beta08" />
<PackageVersion Include="Rocket.Surgery.Build.Information" Version="3.3.11" />
<PackageVersion Include="Rocket.Surgery.Conventions" Version="14.0.0-beta.21" />
<PackageVersion Include="Rocket.Surgery.Conventions.Abstractions" Version="14.0.0-beta.21" />
<PackageVersion Include="Rocket.Surgery.CommandLine" Version="14.0.0-beta.21" />
<PackageVersion Include="Rocket.Surgery.Conventions.DependencyModel" Version="14.0.0-beta.21" />
<PackageVersion Include="Rocket.Surgery.Conventions.DryIoc" Version="14.0.0-beta.21" />
<PackageVersion Include="Rocket.Surgery.Conventions" Version="14.0.0-beta.22" />
<PackageVersion Include="Rocket.Surgery.Conventions.Abstractions" Version="14.0.0-beta.22" />
<PackageVersion Include="Rocket.Surgery.CommandLine" Version="14.0.0-beta.22" />
<PackageVersion Include="Rocket.Surgery.Conventions.DependencyModel" Version="14.0.0-beta.22" />
<PackageVersion Include="Rocket.Surgery.Conventions.DryIoc" Version="14.0.0-beta.22" />
<PackageVersion Include="Rocket.Surgery.DependencyInjection.Extensions" Version="12.1.0" />
<PackageVersion Include="Rocket.Surgery.Extensions" Version="12.1.0" />
<PackageVersion Include="Rocket.Surgery.Hosting" Version="14.0.0-beta.21" />
<PackageVersion Include="Rocket.Surgery.WebAssembly.Hosting" Version="14.0.0-beta.21" />
<PackageVersion Include="Rocket.Surgery.Hosting" Version="14.0.0-beta.22" />
<PackageVersion Include="Rocket.Surgery.WebAssembly.Hosting" Version="14.0.0-beta.22" />
<PackageVersion Include="Scrutor" Version="4.2.2" />
<PackageVersion Include="Serilog" Version="3.1.1" />
<PackageVersion Include="Serilog.AspNetCore" Version="8.0.1" />
Expand Down Expand Up @@ -133,6 +136,7 @@
<PackageVersion Include="OpenTelemetry.Api" Version="1.8.1" />
<PackageVersion Include="OpenTelemetry.Extensions.Hosting" Version="1.8.1" />
<PackageVersion Include="OpenTelemetry.Instrumentation.Http" Version="1.8.1" />
<PackageVersion Include="OpenTelemetry.Instrumentation.Runtime" Version="1.8.0" />
<PackageVersion Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.8.1" />
</ItemGroup>
<ItemGroup>
Expand Down
4 changes: 1 addition & 3 deletions sample/Sample.BlazorServer/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.Runtime.Loader;
using Rocket.Surgery.Conventions;
using Rocket.Surgery.Hosting;
using Rocket.Surgery.LaunchPad.AspNetCore;
using Sample.BlazorServer;
Expand All @@ -11,7 +9,7 @@
builder.Services.AddServerSideBlazor();
builder.Services.AddSingleton<WeatherForecastService>();

var app = await builder.LaunchWith(RocketBooster.For(Imports.Instance), b => b.Set(AssemblyLoadContext.Default));
var app = await builder.LaunchWith(RocketBooster.For(Imports.Instance));

if (builder.Environment.IsDevelopment())
{
Expand Down
4 changes: 1 addition & 3 deletions sample/Sample.Classic.Restful/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System.Reflection;
using System.Runtime.Loader;
using Hellang.Middleware.ProblemDetails;
using Rocket.Surgery.Conventions;
using Rocket.Surgery.Hosting;
using Rocket.Surgery.LaunchPad.AspNetCore;
using Sample.Classic.Restful;
Expand All @@ -22,7 +20,7 @@
}
)
);
var app = await builder.LaunchWith(RocketBooster.For(Imports.Instance), b => b.Set(AssemblyLoadContext.Default));
var app = await builder.LaunchWith(RocketBooster.For(Imports.Instance));

app.UseProblemDetails();
app.UseHttpsRedirection();
Expand Down
4 changes: 1 addition & 3 deletions sample/Sample.Graphql/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Runtime.Loader;
using HotChocolate.Types.Spatial;
using Rocket.Surgery.Conventions;
using Rocket.Surgery.Hosting;
using Rocket.Surgery.LaunchPad.AspNetCore;
using Rocket.Surgery.LaunchPad.HotChocolate;
Expand Down Expand Up @@ -30,7 +28,7 @@
.ModifyRequestOptions(options => options.IncludeExceptionDetails = true);

var app = await builder
.LaunchWith(RocketBooster.For(Imports.Instance), b => b.Set(AssemblyLoadContext.Default));
.LaunchWith(RocketBooster.For(Imports.Instance));

app.UseHttpLogging();
app.UseLaunchPadRequestLogging();
Expand Down
4 changes: 1 addition & 3 deletions sample/Sample.Pages/Program.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using System.Runtime.Loader;
using System.Text;
using System.Text.Json;
using Humanizer;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Rocket.Surgery.Conventions;
using Rocket.Surgery.Hosting;
using Rocket.Surgery.LaunchPad.AspNetCore;
using Sample.Pages;
Expand All @@ -12,7 +10,7 @@
builder.Services.AddRazorPages();
builder.Services.AddControllersWithViews();

var app = await builder.LaunchWith(RocketBooster.For(Imports.Instance), b => b.Set(AssemblyLoadContext.Default));
var app = await builder.LaunchWith(RocketBooster.For(Imports.Instance));

if (builder.Environment.IsDevelopment())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Rocket.Surgery.LaunchPad.AspNetCore.Conventions;
public class AspNetCoreConventionInstrumentationConvention : IOpenTelemetryConvention
{
/// <inheritdoc />
public void Register(IConventionContext conventionContext, IConfiguration configuration, IOpenTelemetryBuilder builder)
public void Register(IConventionContext context, IConfiguration configuration, IOpenTelemetryBuilder builder)
{
builder.WithTracing(b => b.AddAspNetCoreInstrumentation(options => options.RecordException = true));
builder.WithMetrics(b => b.AddAspNetCoreInstrumentation());
Expand Down
1 change: 1 addition & 0 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
<InternalsVisibleTo Include="Rocket.Surgery.LaunchPad.Pages" />
<InternalsVisibleTo Include="AspNetCore.Tests" />
<InternalsVisibleTo Include="Extensions.Tests" />
<InternalsVisibleTo Include="Sample.Pages.Tests" />
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions src/Foundation/Conventions/InstrumentationConvention.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ namespace Rocket.Surgery.LaunchPad.Foundation.Conventions;
public class InstrumentationConvention : IOpenTelemetryConvention
{
/// <inheritdoc />
public void Register(IConventionContext conventionContext, IConfiguration configuration, IOpenTelemetryBuilder builder)
public void Register(IConventionContext context, IConfiguration configuration, IOpenTelemetryBuilder builder)
{
builder.WithTracing(b => b.AddHttpClientInstrumentation(x => x.RecordException = true));
builder.WithMetrics(b => b.AddHttpClientInstrumentation());
builder.WithMetrics(b => b.AddRuntimeInstrumentation().AddHttpClientInstrumentation());
}
}
40 changes: 40 additions & 0 deletions src/Foundation/Conventions/OptionsConvention.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System.Reflection;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Rocket.Surgery.Conventions;
using Rocket.Surgery.Conventions.DependencyInjection;

namespace Rocket.Surgery.LaunchPad.Foundation.Conventions;

/// <summary>
/// A convention that registers any options POCOs that are found with the <see cref="RegisterOptionsConfigurationAttribute" />
/// </summary>
[ExportConvention]
public class OptionsConvention : IServiceConvention
{
private readonly MethodInfo _configureMethod;

/// <summary>
/// A convention that registers any options POCOs that are found with the <see cref="RegisterOptionsConfigurationAttribute" />
/// </summary>
public OptionsConvention()
{
_configureMethod = typeof(OptionsConfigurationServiceCollectionExtensions).GetMethod(
nameof(OptionsConfigurationServiceCollectionExtensions.Configure),
[typeof(IServiceCollection), typeof(string), typeof(IConfiguration),]
)!;
}

/// <inheritdoc />
public void Register(IConventionContext context, IConfiguration configuration, IServiceCollection services)
{
var classes = context.AssemblyProvider.GetTypes(
s => s.FromAssemblyDependenciesOf<RegisterOptionsConfigurationAttribute>().GetTypes(f => f.WithAttribute<RegisterOptionsConfigurationAttribute>())
);
foreach (var options in classes)
{
var attribute = options.GetCustomAttribute<RegisterOptionsConfigurationAttribute>()!;
_configureMethod.MakeGenericMethod(options).Invoke(null, [services, attribute.OptionsName, configuration.GetSection(attribute.ConfigurationKey),]);
}
}
}
28 changes: 28 additions & 0 deletions src/Foundation/Conventions/ServiceDiscoveryConvention.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Rocket.Surgery.Conventions;
using Rocket.Surgery.Conventions.DependencyInjection;

namespace Rocket.Surgery.LaunchPad.Foundation.Conventions;

/// <summary>
/// Service conventions using service discovery
/// </summary>
[PublicAPI]
[ExportConvention]
public class ServiceDiscoveryConvention : IServiceConvention
{
/// <inheritdoc />
public void Register(IConventionContext context, IConfiguration configuration, IServiceCollection services)
{
services.AddServiceDiscovery();

services.ConfigureHttpClientDefaults(
http =>
{
http.AddStandardResilienceHandler();
http.AddServiceDiscovery();
}
);
}
}
1 change: 1 addition & 0 deletions src/Foundation/GenerationIgnoreAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ namespace Rocket.Surgery.LaunchPad.Foundation;
/// <summary>
/// Exclude the given property from the generation via launch pad source generators
/// </summary>
[PublicAPI]
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Method | AttributeTargets.Constructor)]
public sealed class GenerationIgnoreAttribute : Attribute;
19 changes: 19 additions & 0 deletions src/Foundation/RegisterOptionsConfigurationAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace Rocket.Surgery.LaunchPad.Foundation;

/// <summary>
/// Register the options using the configuration key as the configuration root
/// </summary>
[PublicAPI]
[AttributeUsage(AttributeTargets.Class)]
public sealed class RegisterOptionsConfigurationAttribute(string configurationKey) : Attribute
{
/// <summary>
/// The configuration key to use
/// </summary>
public string ConfigurationKey { get; } = configurationKey;

/// <summary>
/// The optional options name
/// </summary>
public string? OptionsName { get; set; }
}
5 changes: 4 additions & 1 deletion src/Foundation/Rocket.Surgery.LaunchPad.Foundation.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
<PackageReference Include="Microsoft.Extensions.DependencyInjection" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" />
<PackageReference Include="Microsoft.Extensions.Logging" />
<PackageReference Include="Microsoft.Extensions.Options" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" />
<PackageReference Include="Microsoft.Extensions.Http.Resilience" />
<PackageReference Include="Microsoft.Extensions.ServiceDiscovery" />
<PackageReference Include="NodaTime" />
<PackageReference Include="NodaTime.Serialization.SystemTextJson" />
<PackageReference Include="Rocket.Surgery.Conventions" />
Expand All @@ -28,6 +30,7 @@
<PackageReference Include="System.Reactive.Observable.Aliases" />
<PackageReference Include="System.Text.Json" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" />
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Serilog\Rocket.Surgery.LaunchPad.Serilog.csproj" />
Expand Down
Loading

0 comments on commit a1f25e2

Please sign in to comment.