-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for on-host-lifecycle events (#1989)
- Loading branch information
1 parent
fd2eb25
commit a1f25e2
Showing
28 changed files
with
515 additions
and
77 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
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
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
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
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 |
---|---|---|
@@ -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),]); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -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(); | ||
} | ||
); | ||
} | ||
} |
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 |
---|---|---|
@@ -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; } | ||
} |
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
Oops, something went wrong.