From a715384e98fccb457650ebb844756d8d278363a3 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Mon, 21 Aug 2023 17:23:27 +0100 Subject: [PATCH 1/2] chore: bump to 3.3.0 --- X10D.DSharpPlus/X10D.DSharpPlus.csproj | 2 +- X10D.Hosting/X10D.Hosting.csproj | 2 +- X10D.Unity/X10D.Unity.csproj | 2 +- X10D/X10D.csproj | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/X10D.DSharpPlus/X10D.DSharpPlus.csproj b/X10D.DSharpPlus/X10D.DSharpPlus.csproj index 96264356c..585e78713 100644 --- a/X10D.DSharpPlus/X10D.DSharpPlus.csproj +++ b/X10D.DSharpPlus/X10D.DSharpPlus.csproj @@ -16,7 +16,7 @@ dotnet extension-methods $([System.IO.File]::ReadAllText("$(MSBuildProjectDirectory)/../CHANGELOG.md")) true - 3.2.2 + 3.3.0 enable true true diff --git a/X10D.Hosting/X10D.Hosting.csproj b/X10D.Hosting/X10D.Hosting.csproj index 3d986d620..074388a20 100644 --- a/X10D.Hosting/X10D.Hosting.csproj +++ b/X10D.Hosting/X10D.Hosting.csproj @@ -16,7 +16,7 @@ dotnet extension-methods $([System.IO.File]::ReadAllText("$(MSBuildProjectDirectory)/../CHANGELOG.md")) true - 3.2.2 + 3.3.0 enable true true diff --git a/X10D.Unity/X10D.Unity.csproj b/X10D.Unity/X10D.Unity.csproj index 41af9ef93..17c8d554f 100644 --- a/X10D.Unity/X10D.Unity.csproj +++ b/X10D.Unity/X10D.Unity.csproj @@ -16,7 +16,7 @@ dotnet extension-methods $([System.IO.File]::ReadAllText("$(MSBuildProjectDirectory)/../CHANGELOG.md")) true - 3.2.2 + 3.3.0 enable true true diff --git a/X10D/X10D.csproj b/X10D/X10D.csproj index 0f853d8a2..d74d84af5 100644 --- a/X10D/X10D.csproj +++ b/X10D/X10D.csproj @@ -17,7 +17,7 @@ README.md $([System.IO.File]::ReadAllText("$(MSBuildProjectDirectory)/../CHANGELOG.md")) true - 3.2.2 + 3.3.0 enable true true From 22532e8cef56125f4afaccd2600fded148bb876b Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Mon, 21 Aug 2023 17:25:41 +0100 Subject: [PATCH 2/2] feat: add service/impl register for AddHostedSingleton --- CHANGELOG.md | 10 ++++++- .../ServiceCollectionExtensions.cs | 30 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4716a77f7..a86ae2695 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [3.3.0] - 2023-08-21 + +### Added + +- X10D.Hosting: Added support for service/implementation registration with `AddHostedSingleton`. + ## [3.2.2] - 2023-06-05 ### Added @@ -577,7 +583,9 @@ please [open an issue](https://github.com/oliverbooth/X10D/issues)! Earlier versions of this package are undocumented and unlisted from package results. -[unreleased]: https://github.com/oliverbooth/X10D/compare/v3.2.2...main +[unreleased]: https://github.com/oliverbooth/X10D/compare/v3.3.0...main +[3.3.0]: https://github.com/oliverbooth/X10D/releases/tag/v3.3.0 +[3.2.2]: https://github.com/oliverbooth/X10D/releases/tag/v3.2.2 [3.2.0]: https://github.com/oliverbooth/X10D/releases/tag/v3.2.0 [3.1.0]: https://github.com/oliverbooth/X10D/releases/tag/v3.1.0 [3.0.0]: https://github.com/oliverbooth/X10D/releases/tag/v3.0.0 diff --git a/X10D.Hosting/src/DependencyInjection/ServiceCollectionExtensions.cs b/X10D.Hosting/src/DependencyInjection/ServiceCollectionExtensions.cs index 9a0bafe75..8df216c8a 100644 --- a/X10D.Hosting/src/DependencyInjection/ServiceCollectionExtensions.cs +++ b/X10D.Hosting/src/DependencyInjection/ServiceCollectionExtensions.cs @@ -21,6 +21,21 @@ public static IServiceCollection AddHostedSingleton(this IServiceColle return services.AddSingleton(provider => provider.GetRequiredService()); } + /// + /// Adds an registration for the given type, while simultaneously adding it as a singleton. + /// + /// The to add the service to. + /// The type of the service to add. + /// The type of the implementation to use. + /// A reference to this instance after the operation has completed. + public static IServiceCollection AddHostedSingleton(this IServiceCollection services) + where TService : class, IHostedService + where TImplementation : class, TService + { + services.AddSingleton(); + return services.AddSingleton(provider => provider.GetRequiredService()); + } + /// /// Adds an registration for the given type, while simultaneously adding it as a singleton. /// @@ -32,4 +47,19 @@ public static IServiceCollection AddHostedSingleton(this IServiceCollection serv services.AddSingleton(type); return services.AddSingleton(provider => (IHostedService)provider.GetRequiredService(type)); } + + /// + /// Adds an registration for the given type, while simultaneously adding it as a singleton. + /// + /// The to add the service to. + /// The type of the service to register. + /// The type of the implementation to use. + /// A reference to this instance after the operation has completed. + public static IServiceCollection AddHostedSingleton(this IServiceCollection services, + Type serviceType, + Type implementationType) + { + services.AddSingleton(serviceType, implementationType); + return services.AddSingleton(provider => (IHostedService)provider.GetRequiredService(serviceType)); + } }