From 3b47d0bd0c84569089aa3edc511f2ea37e4cc2dc Mon Sep 17 00:00:00 2001 From: Alex Macocian Date: Fri, 9 Jan 2026 13:20:18 +0100 Subject: [PATCH] Deprecate logging and config abstractions, in favor of standard MS provided ones --- .github/workflows/cd.yaml | 2 +- .github/workflows/ci.yaml | 2 +- .../DefaultOptionsManagerTests.cs | 25 ---- .../Configuration/DummyOptions.cs | 5 - .../Configuration/LiveOptionsResolverTests.cs | 66 --------- .../LiveUpdateableOptionsResolverTests.cs | 66 --------- .../LiveUpdateableOptionsWrapperTests.cs | 37 ----- .../Configuration/OptionsResolverTests.cs | 68 --------- .../UpdateableOptionsResolverTests.cs | 66 --------- .../UpdateableOptionsWrapperTests.cs | 42 ------ .../Logging/CVLoggerProviderTests.cs | 35 ----- .../Logging/CVLoggerTests.cs | 66 --------- .../Logging/DebugLogsWriterTests.cs | 29 ---- .../Logging/LoggerResolverTests.cs | 103 -------------- ...tStandard.DependencyInjection.Tests.csproj | 2 +- .../SystemExtensions.NetCore.csproj | 4 +- .../Configuration/DefaultOptionsManager.cs | 13 -- .../Configuration/ILiveOptions.cs | 8 -- .../Configuration/ILiveUpdateableOptions.cs | 6 - .../Configuration/IOptionsManager.cs | 9 -- .../Configuration/IUpdateableOptions.cs | 12 -- .../Configuration/LiveOptionsResolver.cs | 26 ---- .../LiveUpdateableOptionsResolver.cs | 25 ---- .../LiveUpdateableOptionsWrapper.cs | 30 ---- .../Configuration/OptionsResolver.cs | 32 ----- .../UpdateableOptionsResolver.cs | 32 ----- .../Configuration/UpdateableOptionsWrapper.cs | 22 --- .../Extensions/ServiceManagerExtensions.cs | 133 ------------------ .../Logging/CVLogger.cs | 43 ------ .../Logging/CVLoggerProvider.cs | 38 ----- .../Logging/DebugLogsWriter.cs | 11 -- .../Logging/ICVLoggerProvider.cs | 8 -- .../Logging/ILogsWriter.cs | 6 - .../Logging/LoggerResolver.cs | 49 ------- ...ons.NetStandard.DependencyInjection.csproj | 2 +- ...tensions.NetStandard.Security.Tests.csproj | 2 +- .../SystemExtensions.NetStandard.csproj | 2 +- .../Collections/AVLTreeTests.cs | 32 ----- .../Collections/BinaryHeapTests.cs | 31 ---- .../Collections/FibonacciHeapTests.cs | 32 ----- .../Collections/PriorityQueueTests.cs | 32 ----- .../Collections/SkipListTests.cs | 33 ----- .../Collections/TreapTests.cs | 33 ----- .../SystemExtensions.NetStandard.Tests.csproj | 2 +- 44 files changed, 9 insertions(+), 1313 deletions(-) delete mode 100644 SystemExtensions.DependencyInjection.Tests/Configuration/DefaultOptionsManagerTests.cs delete mode 100644 SystemExtensions.DependencyInjection.Tests/Configuration/DummyOptions.cs delete mode 100644 SystemExtensions.DependencyInjection.Tests/Configuration/LiveOptionsResolverTests.cs delete mode 100644 SystemExtensions.DependencyInjection.Tests/Configuration/LiveUpdateableOptionsResolverTests.cs delete mode 100644 SystemExtensions.DependencyInjection.Tests/Configuration/LiveUpdateableOptionsWrapperTests.cs delete mode 100644 SystemExtensions.DependencyInjection.Tests/Configuration/OptionsResolverTests.cs delete mode 100644 SystemExtensions.DependencyInjection.Tests/Configuration/UpdateableOptionsResolverTests.cs delete mode 100644 SystemExtensions.DependencyInjection.Tests/Configuration/UpdateableOptionsWrapperTests.cs delete mode 100644 SystemExtensions.DependencyInjection.Tests/Logging/CVLoggerProviderTests.cs delete mode 100644 SystemExtensions.DependencyInjection.Tests/Logging/CVLoggerTests.cs delete mode 100644 SystemExtensions.DependencyInjection.Tests/Logging/DebugLogsWriterTests.cs delete mode 100644 SystemExtensions.DependencyInjection.Tests/Logging/LoggerResolverTests.cs delete mode 100644 SystemExtensions.NetStandard.DependencyInjection/Configuration/DefaultOptionsManager.cs delete mode 100644 SystemExtensions.NetStandard.DependencyInjection/Configuration/ILiveOptions.cs delete mode 100644 SystemExtensions.NetStandard.DependencyInjection/Configuration/ILiveUpdateableOptions.cs delete mode 100644 SystemExtensions.NetStandard.DependencyInjection/Configuration/IOptionsManager.cs delete mode 100644 SystemExtensions.NetStandard.DependencyInjection/Configuration/IUpdateableOptions.cs delete mode 100644 SystemExtensions.NetStandard.DependencyInjection/Configuration/LiveOptionsResolver.cs delete mode 100644 SystemExtensions.NetStandard.DependencyInjection/Configuration/LiveUpdateableOptionsResolver.cs delete mode 100644 SystemExtensions.NetStandard.DependencyInjection/Configuration/LiveUpdateableOptionsWrapper.cs delete mode 100644 SystemExtensions.NetStandard.DependencyInjection/Configuration/OptionsResolver.cs delete mode 100644 SystemExtensions.NetStandard.DependencyInjection/Configuration/UpdateableOptionsResolver.cs delete mode 100644 SystemExtensions.NetStandard.DependencyInjection/Configuration/UpdateableOptionsWrapper.cs delete mode 100644 SystemExtensions.NetStandard.DependencyInjection/Logging/CVLogger.cs delete mode 100644 SystemExtensions.NetStandard.DependencyInjection/Logging/CVLoggerProvider.cs delete mode 100644 SystemExtensions.NetStandard.DependencyInjection/Logging/DebugLogsWriter.cs delete mode 100644 SystemExtensions.NetStandard.DependencyInjection/Logging/ICVLoggerProvider.cs delete mode 100644 SystemExtensions.NetStandard.DependencyInjection/Logging/ILogsWriter.cs delete mode 100644 SystemExtensions.NetStandard.DependencyInjection/Logging/LoggerResolver.cs diff --git a/.github/workflows/cd.yaml b/.github/workflows/cd.yaml index 2db9266..d1ed221 100644 --- a/.github/workflows/cd.yaml +++ b/.github/workflows/cd.yaml @@ -33,7 +33,7 @@ jobs: - name: Install .NET Core uses: actions/setup-dotnet@v3 with: - dotnet-version: '6.0.x' + dotnet-version: '10.0.x' - name: Setup MSBuild.exe uses: microsoft/setup-msbuild@v1.0.1 diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index eaa7809..97bceab 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -35,7 +35,7 @@ jobs: - name: Install .NET Core uses: actions/setup-dotnet@v3 with: - dotnet-version: '6.0.x' + dotnet-version: '10.0.x' - name: Setup MSBuild.exe uses: microsoft/setup-msbuild@v1.0.1 diff --git a/SystemExtensions.DependencyInjection.Tests/Configuration/DefaultOptionsManagerTests.cs b/SystemExtensions.DependencyInjection.Tests/Configuration/DefaultOptionsManagerTests.cs deleted file mode 100644 index c42e5cb..0000000 --- a/SystemExtensions.DependencyInjection.Tests/Configuration/DefaultOptionsManagerTests.cs +++ /dev/null @@ -1,25 +0,0 @@ -using FluentAssertions; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System.Configuration; - -namespace SystemExtensions.DependencyInjection.Tests.Configuration; - -[TestClass] -public class DefaultOptionsManagerTests -{ - private readonly DefaultOptionsManager optionsManager = new(); - - [TestMethod] - public void GetOptions_ReturnsDefault() - { - var options = this.optionsManager.GetOptions(); - - options.Should().BeNull(); - } - - [TestMethod] - public void UpdateOptions_Succeeds() - { - this.optionsManager.UpdateOptions(string.Empty); - } -} diff --git a/SystemExtensions.DependencyInjection.Tests/Configuration/DummyOptions.cs b/SystemExtensions.DependencyInjection.Tests/Configuration/DummyOptions.cs deleted file mode 100644 index 13d2d8d..0000000 --- a/SystemExtensions.DependencyInjection.Tests/Configuration/DummyOptions.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace SystemExtensions.DependencyInjection.Tests.Configuration; - -public sealed class DummyOptions -{ -} diff --git a/SystemExtensions.DependencyInjection.Tests/Configuration/LiveOptionsResolverTests.cs b/SystemExtensions.DependencyInjection.Tests/Configuration/LiveOptionsResolverTests.cs deleted file mode 100644 index a384c61..0000000 --- a/SystemExtensions.DependencyInjection.Tests/Configuration/LiveOptionsResolverTests.cs +++ /dev/null @@ -1,66 +0,0 @@ -using FluentAssertions; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using NSubstitute; -using System; -using System.Configuration; - -namespace SystemExtensions.DependencyInjection.Tests.Configuration; - -[TestClass] -public class LiveOptionsResolverTests -{ - private readonly LiveOptionsResolver liveOptionsResolver = new(); - private readonly Slim.IServiceProvider serviceProviderMock = Substitute.For(); - private readonly IOptionsManager optionsManagerMock = Substitute.For(); - - [TestMethod] - public void CanResolve_ILiveOptions_ReturnsTrue() - { - var type = typeof(ILiveOptions); - - var canResolve = this.liveOptionsResolver.CanResolve(type); - - canResolve.Should().BeTrue(); - } - - [TestMethod] - public void CanResolve_AnythingElse_ReturnsFalse() - { - var types = new Type[] { typeof(object), typeof(string), typeof(LiveOptionsResolverTests), typeof(int) }; - - foreach (var type in types) - { - var canResolve = this.liveOptionsResolver.CanResolve(type); - - canResolve.Should().BeFalse(); - } - } - - [TestMethod] - public void Resolve_ILiveOptions_ReturnsILiveOptions() - { - this.SetupServiceProvider(); - - var liveOptions = this.liveOptionsResolver.Resolve(this.serviceProviderMock, typeof(ILiveOptions)); - - liveOptions.Should().BeAssignableTo>(); - } - - [TestMethod] - public void Resolve_AnythingElse_Throws() - { - this.SetupServiceProvider(); - - Action action = new(() => - { - this.liveOptionsResolver.Resolve(this.serviceProviderMock, typeof(string)); - }); - - action.Should().Throw(); - } - - private void SetupServiceProvider() - { - this.serviceProviderMock.GetService().Returns(this.optionsManagerMock); - } -} diff --git a/SystemExtensions.DependencyInjection.Tests/Configuration/LiveUpdateableOptionsResolverTests.cs b/SystemExtensions.DependencyInjection.Tests/Configuration/LiveUpdateableOptionsResolverTests.cs deleted file mode 100644 index 9a864fd..0000000 --- a/SystemExtensions.DependencyInjection.Tests/Configuration/LiveUpdateableOptionsResolverTests.cs +++ /dev/null @@ -1,66 +0,0 @@ -using FluentAssertions; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using NSubstitute; -using System; -using System.Configuration; - -namespace SystemExtensions.DependencyInjection.Tests.Configuration; - -[TestClass] -public class LiveUpdateableOptionsResolverTests -{ - private readonly LiveUpdateableOptionsResolver liveUpdateableOptionsResolver = new(); - private readonly Slim.IServiceProvider serviceProviderMock = Substitute.For(); - private readonly IOptionsManager optionsManagerMock = Substitute.For(); - - [TestMethod] - public void CanResolve_ILiveUpdateableOptions_ReturnsTrue() - { - var type = typeof(ILiveUpdateableOptions); - - var canResolve = this.liveUpdateableOptionsResolver.CanResolve(type); - - canResolve.Should().BeTrue(); - } - - [TestMethod] - public void CanResolve_AnythingElse_ReturnsFalse() - { - var types = new Type[] { typeof(object), typeof(string), typeof(LiveOptionsResolverTests), typeof(int) }; - - foreach (var type in types) - { - var canResolve = this.liveUpdateableOptionsResolver.CanResolve(type); - - canResolve.Should().BeFalse(); - } - } - - [TestMethod] - public void Resolve_ILiveUpdateableOptions_ReturnsILiveUpdateableOptions() - { - this.SetupServiceProvider(); - - var liveOptions = this.liveUpdateableOptionsResolver.Resolve(this.serviceProviderMock, typeof(ILiveUpdateableOptions)); - - liveOptions.Should().BeAssignableTo>(); - } - - [TestMethod] - public void Resolve_AnythingElse_Throws() - { - this.SetupServiceProvider(); - - Action action = new(() => - { - this.liveUpdateableOptionsResolver.Resolve(this.serviceProviderMock, typeof(string)); - }); - - action.Should().Throw(); - } - - private void SetupServiceProvider() - { - this.serviceProviderMock.GetService().Returns(this.optionsManagerMock); - } -} diff --git a/SystemExtensions.DependencyInjection.Tests/Configuration/LiveUpdateableOptionsWrapperTests.cs b/SystemExtensions.DependencyInjection.Tests/Configuration/LiveUpdateableOptionsWrapperTests.cs deleted file mode 100644 index 5844b7e..0000000 --- a/SystemExtensions.DependencyInjection.Tests/Configuration/LiveUpdateableOptionsWrapperTests.cs +++ /dev/null @@ -1,37 +0,0 @@ -using FluentAssertions; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using NSubstitute; -using System.Configuration; - -namespace SystemExtensions.DependencyInjection.Tests.Configuration; - -[TestClass] -public class LiveUpdateableOptionsWrapperTests -{ - private LiveUpdateableOptionsWrapper optionsWrapper; - private readonly IOptionsManager optionsManagerMock = Substitute.For(); - - [TestInitialize] - public void TestInitialize() - { - this.optionsWrapper = new LiveUpdateableOptionsWrapper(this.optionsManagerMock); - } - - [TestMethod] - public void GetValue_ReturnsValue() - { - this.optionsManagerMock.GetOptions().Returns("hello"); - - var value = this.optionsWrapper.Value; - - value.Should().Be("hello"); - } - - [TestMethod] - public void UpdateOption_CallsOptionsManager() - { - this.optionsWrapper.UpdateOption(); - - this.optionsManagerMock.ReceivedWithAnyArgs().UpdateOptions(Arg.Any()); - } -} diff --git a/SystemExtensions.DependencyInjection.Tests/Configuration/OptionsResolverTests.cs b/SystemExtensions.DependencyInjection.Tests/Configuration/OptionsResolverTests.cs deleted file mode 100644 index d106500..0000000 --- a/SystemExtensions.DependencyInjection.Tests/Configuration/OptionsResolverTests.cs +++ /dev/null @@ -1,68 +0,0 @@ -using FluentAssertions; -using Microsoft.Extensions.Options; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using NSubstitute; -using System; -using System.Configuration; - -namespace SystemExtensions.DependencyInjection.Tests.Configuration; - -[TestClass] -public class OptionsResolverTests -{ - private readonly OptionsResolver optionsResolver = new(); - private readonly Slim.IServiceProvider serviceProviderMock = Substitute.For(); - - public IOptionsManager OptionsManagerMock { get; } = Substitute.For(); - - [TestMethod] - public void CanResolve_ILiveOptions_ReturnsTrue() - { - var type = typeof(IOptions); - - var canResolve = this.optionsResolver.CanResolve(type); - - canResolve.Should().BeTrue(); - } - - [TestMethod] - public void CanResolve_AnythingElse_ReturnsFalse() - { - var types = new Type[] { typeof(object), typeof(string), typeof(OptionsResolverTests), typeof(int) }; - - foreach (var type in types) - { - var canResolve = this.optionsResolver.CanResolve(type); - - canResolve.Should().BeFalse(); - } - } - - [TestMethod] - public void Resolve_IOptions_ReturnsIOptions() - { - this.SetupServiceProvider(); - - var liveOptions = this.optionsResolver.Resolve(this.serviceProviderMock, typeof(IOptions)); - - liveOptions.Should().BeAssignableTo>(); - } - - [TestMethod] - public void Resolve_AnythingElse_Throws() - { - this.SetupServiceProvider(); - - Action action = new(() => - { - this.optionsResolver.Resolve(this.serviceProviderMock, typeof(string)); - }); - - action.Should().Throw(); - } - - private void SetupServiceProvider() - { - this.serviceProviderMock.GetService().Returns(this.OptionsManagerMock); - } -} diff --git a/SystemExtensions.DependencyInjection.Tests/Configuration/UpdateableOptionsResolverTests.cs b/SystemExtensions.DependencyInjection.Tests/Configuration/UpdateableOptionsResolverTests.cs deleted file mode 100644 index 72f92d8..0000000 --- a/SystemExtensions.DependencyInjection.Tests/Configuration/UpdateableOptionsResolverTests.cs +++ /dev/null @@ -1,66 +0,0 @@ -using FluentAssertions; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using NSubstitute; -using System; -using System.Configuration; - -namespace SystemExtensions.DependencyInjection.Tests.Configuration; - -[TestClass] -public class UpdateableOptionsResolverTests -{ - private readonly UpdateableOptionsResolver updateableOptionsResolver = new(); - private readonly Slim.IServiceProvider serviceProviderMock = Substitute.For(); - private readonly IOptionsManager optionsManagerMock = Substitute.For(); - - [TestMethod] - public void CanResolve_ILiveOptions_ReturnsTrue() - { - var type = typeof(IUpdateableOptions); - - var canResolve = this.updateableOptionsResolver.CanResolve(type); - - canResolve.Should().BeTrue(); - } - - [TestMethod] - public void CanResolve_AnythingElse_ReturnsFalse() - { - var types = new Type[] { typeof(object), typeof(string), typeof(UpdateableOptionsResolverTests), typeof(int) }; - - foreach (var type in types) - { - var canResolve = this.updateableOptionsResolver.CanResolve(type); - - canResolve.Should().BeFalse(); - } - } - - [TestMethod] - public void Resolve_IUpdateableOptions_ReturnsIUpdateableOptions() - { - this.SetupServiceProvider(); - - var liveOptions = this.updateableOptionsResolver.Resolve(this.serviceProviderMock, typeof(IUpdateableOptions)); - - liveOptions.Should().BeAssignableTo>(); - } - - [TestMethod] - public void Resolve_AnythingElse_Throws() - { - this.SetupServiceProvider(); - - Action action = new(() => - { - this.updateableOptionsResolver.Resolve(this.serviceProviderMock, typeof(string)); - }); - - action.Should().Throw(); - } - - private void SetupServiceProvider() - { - this.serviceProviderMock.GetService().Returns(this.optionsManagerMock); - } -} diff --git a/SystemExtensions.DependencyInjection.Tests/Configuration/UpdateableOptionsWrapperTests.cs b/SystemExtensions.DependencyInjection.Tests/Configuration/UpdateableOptionsWrapperTests.cs deleted file mode 100644 index e65ead8..0000000 --- a/SystemExtensions.DependencyInjection.Tests/Configuration/UpdateableOptionsWrapperTests.cs +++ /dev/null @@ -1,42 +0,0 @@ -using FluentAssertions; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using NSubstitute; -using NSubstitute.ExceptionExtensions; -using System; -using System.Configuration; -using System.Extensions.Configuration; - -namespace SystemExtensions.DependencyInjection.Tests.Configuration; - -[TestClass] -public class UpdateableOptionsWrapperTests -{ - private const string Value = "hello"; - - private UpdateableOptionsWrapper optionsWrapper; - private readonly IOptionsManager optionsManagerMock = Substitute.For(); - - [TestInitialize] - public void TestInitialize() - { - this.optionsWrapper = new UpdateableOptionsWrapper(this.optionsManagerMock, Value); - } - - [TestMethod] - public void GetValue_ReturnsValue() - { - this.optionsManagerMock.GetOptions().Throws(); - - var value = this.optionsWrapper.Value; - - value.Should().Be(Value); - } - - [TestMethod] - public void UpdateOption_CallsOptionsManager() - { - this.optionsWrapper.UpdateOption(); - - this.optionsManagerMock.ReceivedWithAnyArgs().UpdateOptions(Arg.Any()); - } -} diff --git a/SystemExtensions.DependencyInjection.Tests/Logging/CVLoggerProviderTests.cs b/SystemExtensions.DependencyInjection.Tests/Logging/CVLoggerProviderTests.cs deleted file mode 100644 index 3783a26..0000000 --- a/SystemExtensions.DependencyInjection.Tests/Logging/CVLoggerProviderTests.cs +++ /dev/null @@ -1,35 +0,0 @@ -using FluentAssertions; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using NSubstitute; -using System.Logging; - -namespace SystemExtensions.DependencyInjection.Tests.Logging; - -[TestClass] -public class CVLoggerProviderTests -{ - private readonly ILogsWriter logsWriterMock = Substitute.For(); - private CVLoggerProvider cVLoggerProvider; - - [TestInitialize] - public void TestInitialize() - { - this.cVLoggerProvider = new CVLoggerProvider(this.logsWriterMock); - } - - [TestMethod] - public void CreateLogger_CreatesNewLogger() - { - var logger = this.cVLoggerProvider.CreateLogger(string.Empty); - - logger.Should().NotBeNull(); - } - - [TestMethod] - public void LogEntry_CallsLogWriter() - { - this.cVLoggerProvider.LogEntry(new Log()); - - this.logsWriterMock.ReceivedWithAnyArgs().WriteLog(Arg.Any()); - } -} diff --git a/SystemExtensions.DependencyInjection.Tests/Logging/CVLoggerTests.cs b/SystemExtensions.DependencyInjection.Tests/Logging/CVLoggerTests.cs deleted file mode 100644 index 0a5c075..0000000 --- a/SystemExtensions.DependencyInjection.Tests/Logging/CVLoggerTests.cs +++ /dev/null @@ -1,66 +0,0 @@ -using FluentAssertions; -using Microsoft.Extensions.Logging; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using NSubstitute; -using System; -using System.Logging; - -namespace SystemExtensions.DependencyInjection.Tests.Logging; - -[TestClass] -public class CVLoggerTests -{ - private readonly ICVLoggerProvider cvLoggerProviderMock = Substitute.For(); - private CVLogger cVLogger; - - [TestInitialize] - public void TestInitialize() - { - this.cVLogger = new CVLogger(string.Empty, this.cvLoggerProviderMock); - } - - [TestMethod] - public void BeginScope_ReturnsNull() - { - var scope = this.cVLogger.BeginScope(string.Empty); - - scope.Should().BeNull(); - } - - [TestMethod] - [DataRow(LogLevel.Debug)] - [DataRow(LogLevel.Trace)] - [DataRow(LogLevel.Information)] - [DataRow(LogLevel.Warning)] - [DataRow(LogLevel.Error)] - [DataRow(LogLevel.Critical)] - public void IsEnabled_OnAllLogLevels_ReturnsTrue(LogLevel logLevel) - { - var enabled = this.cVLogger.IsEnabled(logLevel); - - enabled.Should().BeTrue(); - } - - [TestMethod] - public void Log_CallsFormatter() - { - var called = false; - Func messageFormatter = new((state, exception) => - { - called = true; - return string.Empty; - }); - - this.cVLogger.Log(LogLevel.Debug, new EventId(), "Some message", new Exception(), messageFormatter); - - called.Should().BeTrue(); - } - - [TestMethod] - public void Log_CallsLogsProvider() - { - this.cVLogger.Log(LogLevel.Debug, new EventId(), "Some message", new Exception(), new Func((s, e) => string.Empty)); - - this.cvLoggerProviderMock.ReceivedWithAnyArgs().LogEntry(Arg.Any()); - } -} diff --git a/SystemExtensions.DependencyInjection.Tests/Logging/DebugLogsWriterTests.cs b/SystemExtensions.DependencyInjection.Tests/Logging/DebugLogsWriterTests.cs deleted file mode 100644 index 26556a8..0000000 --- a/SystemExtensions.DependencyInjection.Tests/Logging/DebugLogsWriterTests.cs +++ /dev/null @@ -1,29 +0,0 @@ -using FluentAssertions; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using System.Logging; - -namespace SystemExtensions.DependencyInjection.Tests.Logging; - -[TestClass] -public class DebugLogsWriterTests -{ - private readonly DebugLogsWriter logsWriter = new(); - - [TestMethod] - public void WriteLog_Succeeds() - { - this.logsWriter.WriteLog(new Log()); - } - - [TestMethod] - public void WriteNullLog_Throws() - { - Action action = new(() => - { - this.logsWriter.WriteLog(null); - }); - - action.Should().Throw(); - } -} diff --git a/SystemExtensions.DependencyInjection.Tests/Logging/LoggerResolverTests.cs b/SystemExtensions.DependencyInjection.Tests/Logging/LoggerResolverTests.cs deleted file mode 100644 index bfb13a7..0000000 --- a/SystemExtensions.DependencyInjection.Tests/Logging/LoggerResolverTests.cs +++ /dev/null @@ -1,103 +0,0 @@ -using FluentAssertions; -using Microsoft.Extensions.Logging; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using NSubstitute; -using System; -using System.Logging; - -namespace SystemExtensions.DependencyInjection.Tests.Logging; - -[TestClass] -public class LoggerResolverTests -{ - private readonly Slim.IServiceProvider serviceProviderMock = Substitute.For(); - private readonly ILoggerFactory loggerFactoryMock = Substitute.For(); - private readonly ILogger loggerMock = Substitute.For(); - private readonly LoggerResolver loggerResolver = new(); - - [TestMethod] - public void CanResolve_ILogger_ReturnsTrue() - { - var type = typeof(ILogger); - - var canResolve = this.loggerResolver.CanResolve(type); - - canResolve.Should().BeTrue(); - } - - [TestMethod] - public void CanResolve_GenericILogger_ReturnsTrue() - { - var type = typeof(ILogger); - - var canResolve = this.loggerResolver.CanResolve(type); - - canResolve.Should().BeTrue(); - } - - [TestMethod] - public void CanResolve_AnythingElse_ReturnsFalse() - { - var types = new Type[] { typeof(CVLogger), typeof(object), typeof(string), typeof(LoggerResolverTests), typeof(int) }; - - foreach(var type in types) - { - var canResolve = this.loggerResolver.CanResolve(type); - - canResolve.Should().BeFalse(); - } - } - - [TestMethod] - public void Resolve_ILogger_ReturnsILogger() - { - this.SetupIServiceProvider(); - - var logger = this.loggerResolver.Resolve(this.serviceProviderMock, typeof(ILogger)); - - logger.Should().BeAssignableTo(); - } - - [TestMethod] - public void Resolve_TypedILogger_ReturnsTypedILogger() - { - this.SetupIServiceProvider(); - - var logger = this.loggerResolver.Resolve(this.serviceProviderMock, typeof(ILogger)); - - logger.Should().BeAssignableTo>(); - } - - [TestMethod] - public void Resolve_RandomType_Throws() - { - this.SetupIServiceProvider(); - - Action action = new(() => - { - this.loggerResolver.Resolve(this.serviceProviderMock, typeof(string)); - }); - - action.Should().Throw(); - } - - [TestMethod] - public void Resolve_NonTypedGeneric_Throws() - { - this.SetupIServiceProvider(); - - Action action = new(() => - { - this.loggerResolver.Resolve(this.serviceProviderMock, typeof(ILogger<>)); - }); - - action.Should().Throw(); - } - - private void SetupIServiceProvider() - { - this.serviceProviderMock.GetService().Returns(this.loggerFactoryMock); - - this.loggerFactoryMock.CreateLogger(Arg.Any()).Returns(this.loggerMock); - } -} diff --git a/SystemExtensions.DependencyInjection.Tests/SystemExtensions.NetStandard.DependencyInjection.Tests.csproj b/SystemExtensions.DependencyInjection.Tests/SystemExtensions.NetStandard.DependencyInjection.Tests.csproj index 2cdb066..bfe465f 100644 --- a/SystemExtensions.DependencyInjection.Tests/SystemExtensions.NetStandard.DependencyInjection.Tests.csproj +++ b/SystemExtensions.DependencyInjection.Tests/SystemExtensions.NetStandard.DependencyInjection.Tests.csproj @@ -1,7 +1,7 @@ - net6.0 + net10.0 false diff --git a/SystemExtensions.NetCore/SystemExtensions.NetCore.csproj b/SystemExtensions.NetCore/SystemExtensions.NetCore.csproj index 07f9d74..944700a 100644 --- a/SystemExtensions.NetCore/SystemExtensions.NetCore.csproj +++ b/SystemExtensions.NetCore/SystemExtensions.NetCore.csproj @@ -1,14 +1,14 @@  - net6.0 + net10.0 enable true enable System LICENSE true - 1.6.12 + 1.7 Alexandru Macocian https://github.com/AlexMacocian/SystemExtensions Extensions for the System namespace diff --git a/SystemExtensions.NetStandard.DependencyInjection/Configuration/DefaultOptionsManager.cs b/SystemExtensions.NetStandard.DependencyInjection/Configuration/DefaultOptionsManager.cs deleted file mode 100644 index 96145a7..0000000 --- a/SystemExtensions.NetStandard.DependencyInjection/Configuration/DefaultOptionsManager.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace System.Configuration; - -public sealed class DefaultOptionsManager : IOptionsManager -{ - public T GetOptions() where T : class - { - return default; - } - - public void UpdateOptions(T value) where T : class - { - } -} diff --git a/SystemExtensions.NetStandard.DependencyInjection/Configuration/ILiveOptions.cs b/SystemExtensions.NetStandard.DependencyInjection/Configuration/ILiveOptions.cs deleted file mode 100644 index e88c193..0000000 --- a/SystemExtensions.NetStandard.DependencyInjection/Configuration/ILiveOptions.cs +++ /dev/null @@ -1,8 +0,0 @@ -using Microsoft.Extensions.Options; - -namespace System.Configuration; - -public interface ILiveOptions : IOptions - where T : class -{ -} diff --git a/SystemExtensions.NetStandard.DependencyInjection/Configuration/ILiveUpdateableOptions.cs b/SystemExtensions.NetStandard.DependencyInjection/Configuration/ILiveUpdateableOptions.cs deleted file mode 100644 index 1d498a8..0000000 --- a/SystemExtensions.NetStandard.DependencyInjection/Configuration/ILiveUpdateableOptions.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace System.Configuration; - -public interface ILiveUpdateableOptions : ILiveOptions, IUpdateableOptions - where T : class -{ -} diff --git a/SystemExtensions.NetStandard.DependencyInjection/Configuration/IOptionsManager.cs b/SystemExtensions.NetStandard.DependencyInjection/Configuration/IOptionsManager.cs deleted file mode 100644 index 5c69a9e..0000000 --- a/SystemExtensions.NetStandard.DependencyInjection/Configuration/IOptionsManager.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace System.Configuration; - -public interface IOptionsManager -{ - T GetOptions() - where T : class; - void UpdateOptions(T value) - where T : class; -} diff --git a/SystemExtensions.NetStandard.DependencyInjection/Configuration/IUpdateableOptions.cs b/SystemExtensions.NetStandard.DependencyInjection/Configuration/IUpdateableOptions.cs deleted file mode 100644 index ce1a7ca..0000000 --- a/SystemExtensions.NetStandard.DependencyInjection/Configuration/IUpdateableOptions.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Microsoft.Extensions.Options; - -namespace System.Configuration; - -public interface IUpdateableOptions : IOptions - where T : class -{ - /// - /// Updates the configuration with the current value stored in . - /// - void UpdateOption(); -} diff --git a/SystemExtensions.NetStandard.DependencyInjection/Configuration/LiveOptionsResolver.cs b/SystemExtensions.NetStandard.DependencyInjection/Configuration/LiveOptionsResolver.cs deleted file mode 100644 index 0b5366e..0000000 --- a/SystemExtensions.NetStandard.DependencyInjection/Configuration/LiveOptionsResolver.cs +++ /dev/null @@ -1,26 +0,0 @@ -using Slim.Resolvers; - -namespace System.Configuration; - -public sealed class LiveOptionsResolver : IDependencyResolver -{ - private static readonly Type optionsType = typeof(LiveUpdateableOptionsWrapper<>); - - public bool CanResolve(Type type) - { - if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(ILiveOptions<>)) - { - return true; - } - - return false; - } - - public object Resolve(Slim.IServiceProvider serviceProvider, Type type) - { - var typedOptionsType = optionsType.MakeGenericType(type.GetGenericArguments()); - var configurationManager = serviceProvider.GetService(); - - return Activator.CreateInstance(typedOptionsType, configurationManager); - } -} diff --git a/SystemExtensions.NetStandard.DependencyInjection/Configuration/LiveUpdateableOptionsResolver.cs b/SystemExtensions.NetStandard.DependencyInjection/Configuration/LiveUpdateableOptionsResolver.cs deleted file mode 100644 index 47032b2..0000000 --- a/SystemExtensions.NetStandard.DependencyInjection/Configuration/LiveUpdateableOptionsResolver.cs +++ /dev/null @@ -1,25 +0,0 @@ -using Slim.Resolvers; - -namespace System.Configuration; - -public sealed class LiveUpdateableOptionsResolver : IDependencyResolver -{ - private static readonly Type optionsType = typeof(LiveUpdateableOptionsWrapper<>); - - public bool CanResolve(Type type) - { - if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(ILiveUpdateableOptions<>)) - { - return true; - } - - return false; - } - - public object Resolve(Slim.IServiceProvider serviceProvider, Type type) - { - var typedOptionsType = optionsType.MakeGenericType(type.GetGenericArguments()); - var configurationManager = serviceProvider.GetService(); - return Activator.CreateInstance(typedOptionsType, configurationManager); - } -} diff --git a/SystemExtensions.NetStandard.DependencyInjection/Configuration/LiveUpdateableOptionsWrapper.cs b/SystemExtensions.NetStandard.DependencyInjection/Configuration/LiveUpdateableOptionsWrapper.cs deleted file mode 100644 index f571dc9..0000000 --- a/SystemExtensions.NetStandard.DependencyInjection/Configuration/LiveUpdateableOptionsWrapper.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System.Extensions; - -namespace System.Configuration; - -public sealed class LiveUpdateableOptionsWrapper : ILiveUpdateableOptions - where T : class -{ - private readonly IOptionsManager configurationManager; - - private T value; - - public T Value - { - get - { - this.value = this.configurationManager.GetOptions(); - return this.value; - } - } - - public LiveUpdateableOptionsWrapper(IOptionsManager configurationManager) - { - this.configurationManager = configurationManager.ThrowIfNull(nameof(configurationManager)); - } - - public void UpdateOption() - { - this.configurationManager.UpdateOptions(this.value); - } -} diff --git a/SystemExtensions.NetStandard.DependencyInjection/Configuration/OptionsResolver.cs b/SystemExtensions.NetStandard.DependencyInjection/Configuration/OptionsResolver.cs deleted file mode 100644 index 61e0073..0000000 --- a/SystemExtensions.NetStandard.DependencyInjection/Configuration/OptionsResolver.cs +++ /dev/null @@ -1,32 +0,0 @@ -using Microsoft.Extensions.Options; -using Slim.Resolvers; - -namespace System.Configuration; - -public sealed class OptionsResolver : IDependencyResolver -{ - private static readonly Type optionsType = typeof(OptionsWrapper<>); - private static readonly Type configurationType = typeof(IOptionsManager); - - public bool CanResolve(Type type) - { - if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(IOptions<>)) - { - return true; - } - - return false; - } - - public object Resolve(Slim.IServiceProvider serviceProvider, Type type) - { - var typedOptionsType = optionsType.MakeGenericType(type.GetGenericArguments()); - var configurationManager = serviceProvider.GetService(); - var optionsValue = configurationType - .GetMethod(nameof(IOptionsManager.GetOptions)) - .MakeGenericMethod(type.GetGenericArguments()) - .Invoke(configurationManager, Array.Empty()); - - return Activator.CreateInstance(typedOptionsType, optionsValue); - } -} diff --git a/SystemExtensions.NetStandard.DependencyInjection/Configuration/UpdateableOptionsResolver.cs b/SystemExtensions.NetStandard.DependencyInjection/Configuration/UpdateableOptionsResolver.cs deleted file mode 100644 index 6554414..0000000 --- a/SystemExtensions.NetStandard.DependencyInjection/Configuration/UpdateableOptionsResolver.cs +++ /dev/null @@ -1,32 +0,0 @@ -using Slim.Resolvers; -using System.Extensions.Configuration; - -namespace System.Configuration; - -public sealed class UpdateableOptionsResolver : IDependencyResolver -{ - private static readonly Type optionsType = typeof(UpdateableOptionsWrapper<>); - private static readonly Type configurationType = typeof(IOptionsManager); - - public bool CanResolve(Type type) - { - if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(IUpdateableOptions<>)) - { - return true; - } - - return false; - } - - public object Resolve(Slim.IServiceProvider serviceProvider, Type type) - { - var typedOptionsType = optionsType.MakeGenericType(type.GetGenericArguments()); - var configurationManager = serviceProvider.GetService(); - var optionsValue = configurationType - .GetMethod(nameof(IOptionsManager.GetOptions)) - .MakeGenericMethod(type.GetGenericArguments()) - .Invoke(configurationManager, Array.Empty()); - - return Activator.CreateInstance(typedOptionsType, configurationManager, optionsValue); - } -} diff --git a/SystemExtensions.NetStandard.DependencyInjection/Configuration/UpdateableOptionsWrapper.cs b/SystemExtensions.NetStandard.DependencyInjection/Configuration/UpdateableOptionsWrapper.cs deleted file mode 100644 index 7efef8b..0000000 --- a/SystemExtensions.NetStandard.DependencyInjection/Configuration/UpdateableOptionsWrapper.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System.Configuration; - -namespace System.Extensions.Configuration; - -public sealed class UpdateableOptionsWrapper : IUpdateableOptions - where T : class -{ - private readonly IOptionsManager configurationManager; - - public T Value { get; } - - public UpdateableOptionsWrapper(IOptionsManager configurationManager, T options) - { - this.configurationManager = configurationManager.ThrowIfNull(nameof(configurationManager)); - this.Value = options; - } - - public void UpdateOption() - { - this.configurationManager.UpdateOptions(this.Value); - } -} diff --git a/SystemExtensions.NetStandard.DependencyInjection/Extensions/ServiceManagerExtensions.cs b/SystemExtensions.NetStandard.DependencyInjection/Extensions/ServiceManagerExtensions.cs index 513851a..d1f57a8 100644 --- a/SystemExtensions.NetStandard.DependencyInjection/Extensions/ServiceManagerExtensions.cs +++ b/SystemExtensions.NetStandard.DependencyInjection/Extensions/ServiceManagerExtensions.cs @@ -1,132 +1,12 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; using Slim; -using System.Configuration; -using System.Logging; using System.Net.Http; namespace System.Extensions; public static class ServiceManagerExtensions { - /// - /// Registers a with the default . - /// This call also registers the resolver that resolves and . - /// - /// . - /// Provided . - public static IServiceProducer RegisterOptionsManager(this IServiceProducer serviceProducer) - { - serviceProducer.ThrowIfNull(nameof(serviceProducer)); - - serviceProducer.RegisterSingleton(); - serviceProducer.RegisterOptionsResolver(); - - return serviceProducer; - } - - /// - /// Registers a . - /// This call also registers the resolver that resolves and . - /// - /// Implementation of . - /// . - /// Provided . - public static IServiceProducer RegisterOptionsManager(this IServiceProducer serviceProducer) - where T : IOptionsManager - { - serviceProducer.ThrowIfNull(nameof(serviceProducer)); - - serviceProducer.RegisterSingleton(); - serviceProducer.RegisterOptionsResolver(); - - return serviceProducer; - } - - /// - /// Registers resolvers for and . - /// Depends on a in order to properly resolve options. - /// - /// . - /// . - public static IServiceProducer RegisterOptionsResolver(this IServiceProducer serviceProducer) - { - serviceProducer.ThrowIfNull(nameof(serviceProducer)); - - serviceProducer.RegisterResolver(new OptionsResolver()); - serviceProducer.RegisterResolver(new UpdateableOptionsResolver()); - serviceProducer.RegisterResolver(new LiveOptionsResolver()); - serviceProducer.RegisterResolver(new LiveUpdateableOptionsResolver()); - - return serviceProducer; - } - - /// - /// Registers a with the default . - /// - /// Implementation of . - /// . - /// Provided . - public static IServiceProducer RegisterLogWriter(this IServiceProducer serviceManager) - where TLogsWriter : ILogsWriter - { - serviceManager.ThrowIfNull(nameof(serviceManager)); - - serviceManager.RegisterSingleton(); - serviceManager.RegisterScoped(sp => - { - var factory = new LoggerFactory(); - factory.AddProvider(new CVLoggerProvider(sp.GetService())); - return factory; - }); - - return serviceManager; - } - - /// - /// Registers a with the default . - /// - /// Interface of . - /// Implementation of . - /// . - /// Provided . - public static IServiceProducer RegisterLogWriter(this IServiceProducer serviceManager) - where TLogsWriter : TILogsWriter - where TILogsWriter : class, ILogsWriter - { - serviceManager.ThrowIfNull(nameof(serviceManager)); - - serviceManager.RegisterSingleton(); - serviceManager.RegisterScoped(sp => - { - var factory = new LoggerFactory(); - factory.AddProvider(new CVLoggerProvider(sp.GetService())); - return factory; - }); - - return serviceManager; - } - - /// - /// Register a with a . - /// - /// - /// - public static IServiceProducer RegisterCVLoggerFactory(this IServiceProducer serviceProducer) - { - serviceProducer.ThrowIfNull(nameof(serviceProducer)); - - serviceProducer.RegisterScoped(sp => - { - LoggerFactory loggerFactory = new(); - loggerFactory.AddProvider(new CVLoggerProvider(sp.GetService())); - return loggerFactory; - }); - - return serviceProducer; - } - /// /// Registers a . /// @@ -141,19 +21,6 @@ public static class ServiceManagerExtensions return serviceProducer; } - /// - /// Registers a with a that writes to . - /// - /// . - /// - public static IServiceProducer RegisterDebugLoggerFactory(this IServiceProducer serviceProducer) - { - serviceProducer.ThrowIfNull(nameof(serviceProducer)); - - serviceProducer.RegisterLogWriter(); - return serviceProducer; - } - /// /// Register a scoped to be used by the DI engine. /// diff --git a/SystemExtensions.NetStandard.DependencyInjection/Logging/CVLogger.cs b/SystemExtensions.NetStandard.DependencyInjection/Logging/CVLogger.cs deleted file mode 100644 index 89e40b7..0000000 --- a/SystemExtensions.NetStandard.DependencyInjection/Logging/CVLogger.cs +++ /dev/null @@ -1,43 +0,0 @@ -using Microsoft.Extensions.Logging; -using System.Extensions; - -namespace System.Logging; - -public sealed class CVLogger : ILogger -{ - private readonly string category; - private readonly ICVLoggerProvider cvLoggerProvider; - - public CVLogger(string category, ICVLoggerProvider cvLoggerProvider) - { - this.category = category; - this.cvLoggerProvider = cvLoggerProvider.ThrowIfNull(nameof(cvLoggerProvider)); - } - - public IDisposable BeginScope(TState state) - { - return null; - } - - public bool IsEnabled(LogLevel logLevel) - { - return true; - } - - public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) - { - var message = formatter(state, exception); - - var log = new Log - { - Exception = exception, - LogLevel = logLevel, - EventId = eventId.Name, - Message = message, - Category = category, - LogTime = DateTime.Now - }; - - this.cvLoggerProvider.LogEntry(log); - } -} diff --git a/SystemExtensions.NetStandard.DependencyInjection/Logging/CVLoggerProvider.cs b/SystemExtensions.NetStandard.DependencyInjection/Logging/CVLoggerProvider.cs deleted file mode 100644 index 6d8f5e2..0000000 --- a/SystemExtensions.NetStandard.DependencyInjection/Logging/CVLoggerProvider.cs +++ /dev/null @@ -1,38 +0,0 @@ -using Microsoft.CorrelationVector; -using Microsoft.Extensions.Logging; -using System.Extensions; - -namespace System.Logging; - -public sealed class CVLoggerProvider : ICVLoggerProvider -{ - private readonly ILogsWriter logsManager; - private readonly CorrelationVector correlationVector; - - public CVLoggerProvider(ILogsWriter logsWriter) - { - this.logsManager = logsWriter.ThrowIfNull(nameof(logsWriter)); - this.correlationVector = new CorrelationVector(); - } - - public void LogEntry(Log log) - { - if (this.correlationVector is not null) - { - log.CorrelationVector = this.correlationVector.Value.ToString(); - this.correlationVector.Increment(); - } - - this.logsManager.WriteLog(log); - } - - public ILogger CreateLogger(string categoryName) - { - return new CVLogger(categoryName, this); - } - - public void Dispose() - { - throw new System.NotImplementedException(); - } -} diff --git a/SystemExtensions.NetStandard.DependencyInjection/Logging/DebugLogsWriter.cs b/SystemExtensions.NetStandard.DependencyInjection/Logging/DebugLogsWriter.cs deleted file mode 100644 index 8717d99..0000000 --- a/SystemExtensions.NetStandard.DependencyInjection/Logging/DebugLogsWriter.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Diagnostics; - -namespace System.Logging; - -public sealed class DebugLogsWriter : ILogsWriter -{ - public void WriteLog(Log log) - { - Debug.WriteLine($"{log.LogTime} - {log.Category} - {log.EventId} - {log.CorrelationVector} - {log.LogLevel} - {log.Message}{Environment.NewLine}{log.Exception}"); - } -} diff --git a/SystemExtensions.NetStandard.DependencyInjection/Logging/ICVLoggerProvider.cs b/SystemExtensions.NetStandard.DependencyInjection/Logging/ICVLoggerProvider.cs deleted file mode 100644 index 4d9799c..0000000 --- a/SystemExtensions.NetStandard.DependencyInjection/Logging/ICVLoggerProvider.cs +++ /dev/null @@ -1,8 +0,0 @@ -using Microsoft.Extensions.Logging; - -namespace System.Logging; - -public interface ICVLoggerProvider : ILoggerProvider -{ - void LogEntry(Log log); -} diff --git a/SystemExtensions.NetStandard.DependencyInjection/Logging/ILogsWriter.cs b/SystemExtensions.NetStandard.DependencyInjection/Logging/ILogsWriter.cs deleted file mode 100644 index c8caaa7..0000000 --- a/SystemExtensions.NetStandard.DependencyInjection/Logging/ILogsWriter.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace System.Logging; - -public interface ILogsWriter -{ - void WriteLog(Log log); -} diff --git a/SystemExtensions.NetStandard.DependencyInjection/Logging/LoggerResolver.cs b/SystemExtensions.NetStandard.DependencyInjection/Logging/LoggerResolver.cs deleted file mode 100644 index a8b8fc6..0000000 --- a/SystemExtensions.NetStandard.DependencyInjection/Logging/LoggerResolver.cs +++ /dev/null @@ -1,49 +0,0 @@ -using Microsoft.Extensions.Logging; -using Slim.Resolvers; -using System.Linq; - -namespace System.Logging; - -public sealed class LoggerResolver : IDependencyResolver -{ - public bool CanResolve(Type type) - { - if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(ILogger<>) || - type == typeof(ILogger)) - { - return true; - } - - return false; - } - - public object Resolve(Slim.IServiceProvider serviceProvider, Type type) - { - if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(ILogger<>)) - { - return ResolveScopedLogger(serviceProvider, type); - } - else if (type == typeof(ILogger)) - { - return ResolveLogger(serviceProvider); - } - else - { - throw new InvalidOperationException($"{nameof(LoggerResolver)} cannot resolve an object of type {type.Name}"); - } - } - - private static object ResolveScopedLogger(Slim.IServiceProvider serviceProvider, Type type) - { - var loggerFactory = serviceProvider.GetService(); - var categoryTypes = type.GetGenericArguments(); - var createLoggerMethod = typeof(LoggerFactoryExtensions).GetMethods().Where(m => m.IsGenericMethodDefinition && m.Name == nameof(LoggerFactoryExtensions.CreateLogger)).First(); - return createLoggerMethod.MakeGenericMethod(categoryTypes.First()).Invoke(null, new object[] { loggerFactory }); - } - - private static object ResolveLogger(Slim.IServiceProvider serviceProvider) - { - var loggerFactory = serviceProvider.GetService(); - return loggerFactory.CreateLogger(string.Empty); - } -} diff --git a/SystemExtensions.NetStandard.DependencyInjection/SystemExtensions.NetStandard.DependencyInjection.csproj b/SystemExtensions.NetStandard.DependencyInjection/SystemExtensions.NetStandard.DependencyInjection.csproj index 02f5813..14e3b89 100644 --- a/SystemExtensions.NetStandard.DependencyInjection/SystemExtensions.NetStandard.DependencyInjection.csproj +++ b/SystemExtensions.NetStandard.DependencyInjection/SystemExtensions.NetStandard.DependencyInjection.csproj @@ -6,7 +6,7 @@ LICENSE true latest - 1.6.9 + 1.7 Alexandru Macocian https://github.com/AlexMacocian/SystemExtensions Extensions for the Slim Dependency Injection engine diff --git a/SystemExtensions.NetStandard.Security.Tests/SystemExtensions.NetStandard.Security.Tests.csproj b/SystemExtensions.NetStandard.Security.Tests/SystemExtensions.NetStandard.Security.Tests.csproj index d7dd3ef..87eeaa7 100644 --- a/SystemExtensions.NetStandard.Security.Tests/SystemExtensions.NetStandard.Security.Tests.csproj +++ b/SystemExtensions.NetStandard.Security.Tests/SystemExtensions.NetStandard.Security.Tests.csproj @@ -1,7 +1,7 @@ - net6.0 + net10.0 false diff --git a/SystemExtensions.NetStandard/SystemExtensions.NetStandard.csproj b/SystemExtensions.NetStandard/SystemExtensions.NetStandard.csproj index 575c8a0..7315f27 100644 --- a/SystemExtensions.NetStandard/SystemExtensions.NetStandard.csproj +++ b/SystemExtensions.NetStandard/SystemExtensions.NetStandard.csproj @@ -7,7 +7,7 @@ LICENSE true System - 1.6.12 + 1.7 Alexandru Macocian https://github.com/AlexMacocian/SystemExtensions Extensions for the System namespace diff --git a/SystemExtensions.Tests/Collections/AVLTreeTests.cs b/SystemExtensions.Tests/Collections/AVLTreeTests.cs index e46af26..c616e96 100644 --- a/SystemExtensions.Tests/Collections/AVLTreeTests.cs +++ b/SystemExtensions.Tests/Collections/AVLTreeTests.cs @@ -124,36 +124,4 @@ public class AVLTreeTests _ = this.avlTree.ToArray(); } - - [TestMethod()] - public void Serialize() - { - var avlTree2 = new AVLTree(); - for (var i = 0; i < 100; i++) - { - this.avlTree.Add(i); - } - - var serializer = new BinaryFormatter(); - using (var stream = new MemoryStream()) - { - serializer.Serialize(stream, this.avlTree); - stream.Position = 0; - avlTree2 = (AVLTree)serializer.Deserialize(stream); - } - - var avlTreeEnum = this.avlTree.GetEnumerator(); - var avlTree2Enum = avlTree2.GetEnumerator(); - - for(var i = 0; i < 100; i++) - { - if(avlTreeEnum.Current != avlTree2Enum.Current) - { - Assert.Fail(); - } - - avlTreeEnum.MoveNext(); - avlTree2Enum.MoveNext(); - } - } } \ No newline at end of file diff --git a/SystemExtensions.Tests/Collections/BinaryHeapTests.cs b/SystemExtensions.Tests/Collections/BinaryHeapTests.cs index a32e9cc..51d79fc 100644 --- a/SystemExtensions.Tests/Collections/BinaryHeapTests.cs +++ b/SystemExtensions.Tests/Collections/BinaryHeapTests.cs @@ -179,35 +179,4 @@ public class BinaryHeapTests Assert.Fail(); } - - [TestMethod()] - public void Serialize() - { - var binaryHeap2 = new BinaryHeap(); - for (var i = 0; i < 100; i++) - { - this.binaryHeap.Add(i); - } - - var serializer = new BinaryFormatter(); - using (var stream = new MemoryStream()) { - serializer.Serialize(stream, this.binaryHeap); - stream.Position = 0; - binaryHeap2 = (BinaryHeap)serializer.Deserialize(stream); - } - - var binaryHeapEnum = this.binaryHeap.GetEnumerator(); - var binaryHeapEnum2 = binaryHeap2.GetEnumerator(); - - for (var i = 0; i < 100; i++) - { - if (binaryHeapEnum.Current != binaryHeapEnum2.Current) - { - Assert.Fail(); - } - - binaryHeapEnum.MoveNext(); - binaryHeapEnum2.MoveNext(); - } - } } \ No newline at end of file diff --git a/SystemExtensions.Tests/Collections/FibonacciHeapTests.cs b/SystemExtensions.Tests/Collections/FibonacciHeapTests.cs index 036eaf5..5f5ac9a 100644 --- a/SystemExtensions.Tests/Collections/FibonacciHeapTests.cs +++ b/SystemExtensions.Tests/Collections/FibonacciHeapTests.cs @@ -177,36 +177,4 @@ public class FibonacciHeapTests Assert.Fail(); } - - [TestMethod()] - public void Serialize() - { - var fibonacciHeap2 = new FibonacciHeap(); - for (var i = 0; i < 100; i++) - { - this.fibonacciHeap.Add(i); - } - - var serializer = new BinaryFormatter(); - using (var stream = new MemoryStream()) - { - serializer.Serialize(stream, this.fibonacciHeap); - stream.Position = 0; - fibonacciHeap2 = (FibonacciHeap)serializer.Deserialize(stream); - } - - var enum1 = this.fibonacciHeap.GetEnumerator(); - var enum2 = fibonacciHeap2.GetEnumerator(); - - for (var i = 0; i < 100; i++) - { - if (enum1.Current != enum2.Current) - { - Assert.Fail(); - } - - enum1.MoveNext(); - enum2.MoveNext(); - } - } } \ No newline at end of file diff --git a/SystemExtensions.Tests/Collections/PriorityQueueTests.cs b/SystemExtensions.Tests/Collections/PriorityQueueTests.cs index 9fb1a31..87bf1ec 100644 --- a/SystemExtensions.Tests/Collections/PriorityQueueTests.cs +++ b/SystemExtensions.Tests/Collections/PriorityQueueTests.cs @@ -81,36 +81,4 @@ public class PriorityQueueTests Assert.Fail(); } } - - [TestMethod()] - public void Serialize() - { - var priorityQueue2 = new PriorityQueue(); - for (var i = 0; i < 100; i++) - { - this.priorityQueue.Enqueue(i); - } - - var serializer = new BinaryFormatter(); - using (var stream = new MemoryStream()) - { - serializer.Serialize(stream, this.priorityQueue); - stream.Position = 0; - priorityQueue2 = (PriorityQueue)serializer.Deserialize(stream); - } - - var enum1 = this.priorityQueue.GetEnumerator(); - var enum2 = priorityQueue2.GetEnumerator(); - - for (var i = 0; i < 100; i++) - { - if (enum1.Current != enum2.Current) - { - Assert.Fail(); - } - - enum1.MoveNext(); - enum2.MoveNext(); - } - } } \ No newline at end of file diff --git a/SystemExtensions.Tests/Collections/SkipListTests.cs b/SystemExtensions.Tests/Collections/SkipListTests.cs index ba93f7b..f808458 100644 --- a/SystemExtensions.Tests/Collections/SkipListTests.cs +++ b/SystemExtensions.Tests/Collections/SkipListTests.cs @@ -125,37 +125,4 @@ public class SkipListTests Assert.Fail(); } } - - [TestMethod()] - [Ignore("Binary serialization is obsolete and should not be used anymore")] - public void Serialize() - { - var skipList2 = new SkipList(); - for (var i = 0; i < 100; i++) - { - this.skipList.Add(i); - } - - var serializer = new BinaryFormatter(); - using (var stream = new MemoryStream()) - { - serializer.Serialize(stream, this.skipList); - stream.Position = 0; - skipList2 = (SkipList)serializer.Deserialize(stream); - } - - var enum1 = this.skipList.GetEnumerator(); - var enum2 = skipList2.GetEnumerator(); - - for (var i = 0; i < 100; i++) - { - if (enum1.Current != enum2.Current) - { - Assert.Fail(); - } - - enum1.MoveNext(); - enum2.MoveNext(); - } - } } \ No newline at end of file diff --git a/SystemExtensions.Tests/Collections/TreapTests.cs b/SystemExtensions.Tests/Collections/TreapTests.cs index 542c578..0677001 100644 --- a/SystemExtensions.Tests/Collections/TreapTests.cs +++ b/SystemExtensions.Tests/Collections/TreapTests.cs @@ -109,37 +109,4 @@ public class TreapTests Assert.Fail(); } - - [TestMethod()] - [Ignore("Binary serialization is obsolete and should not be used anymore")] - public void Serialize() - { - var treap2 = new Treap(); - for (var i = 0; i < 100; i++) - { - this.treap.Add(i); - } - - var serializer = new BinaryFormatter(); - using (var stream = new MemoryStream()) - { - serializer.Serialize(stream, this.treap); - stream.Position = 0; - treap2 = (Treap)serializer.Deserialize(stream); - } - - var enum1 = this.treap.GetEnumerator(); - var enum2 = treap2.GetEnumerator(); - - for (var i = 0; i < 100; i++) - { - if (enum1.Current != enum2.Current) - { - Assert.Fail(); - } - - enum1.MoveNext(); - enum2.MoveNext(); - } - } } \ No newline at end of file diff --git a/SystemExtensions.Tests/SystemExtensions.NetStandard.Tests.csproj b/SystemExtensions.Tests/SystemExtensions.NetStandard.Tests.csproj index 34aa5db..13e21f1 100644 --- a/SystemExtensions.Tests/SystemExtensions.NetStandard.Tests.csproj +++ b/SystemExtensions.Tests/SystemExtensions.NetStandard.Tests.csproj @@ -1,7 +1,7 @@  - net6.0 + net10.0 enable false