From 94126fffb1bea73bf1cdf3dd486cb86222d3cb28 Mon Sep 17 00:00:00 2001 From: Lukas Angerer Date: Wed, 19 Aug 2026 12:58:32 +0200 Subject: [PATCH 1/5] Enforcing code style rules in build with warnings --- src/Directory.Build.props | 11 ++++++ ...KeyedDependencyInjectionComplianceTests.cs | 4 +- ...nject.Web.AspNetCore.ComplianceTest.csproj | 3 ++ .../Fakes/FakeActivationCacheAccessor.cs | 2 +- .../Fakes/MoritaAssaultRifle.cs | 2 +- .../Ninject.Web.AspNetCore.Test.csproj | 3 ++ .../Regression/NinjectBugsRegressionTest.cs | 2 +- .../ServiceProviderReferenceTest.cs | 6 +-- .../Unit/ActivationCacheTest.cs | 39 +++++++++++-------- .../Unit/DisposalManagerConcurrencyTest.cs | 6 ++- .../Unit/GenericConstraintValidtorTest.cs | 11 ++++-- .../IndexedBindingPrecedenceComparerTest.cs | 2 +- .../Unit/ServiceProviderResolutionRootTest.cs | 2 +- .../AspNetCoreModule.cs | 6 +-- src/Ninject.Web.AspNetCore/BindingIndex.cs | 2 +- ...uctorReflectionStrategyWithKeyedSupport.cs | 4 +- .../Components/DisposalManager.cs | 19 ++++----- .../Hosting/AspNetCoreHost.cs | 2 + .../Hosting/DefaultWebHostConfiguration.cs | 10 ++++- .../NinjectServiceProvider.cs | 4 +- .../NinjectServiceProviderFactory.cs | 2 +- .../ParameterTargetWithKeyedSupport.cs | 7 ++-- src/Ninject.Web.AspNetCore/RequestScope.cs | 2 + .../ServiceCollectionAdapter.cs | 5 +-- .../ServiceProviderScopeParameter.cs | 4 +- .../Controllers/HomeController.cs | 5 ++- src/SampleApplication/Program.cs | 2 +- .../Service/ChatBot/ChatBotService.cs | 5 ++- ...lerFromInterfaceApplicationModelAdapter.cs | 2 +- 29 files changed, 105 insertions(+), 69 deletions(-) create mode 100644 src/Directory.Build.props diff --git a/src/Directory.Build.props b/src/Directory.Build.props new file mode 100644 index 0000000..6f7f2fd --- /dev/null +++ b/src/Directory.Build.props @@ -0,0 +1,11 @@ + + + + true + latest + Recommended + true + CA1805,CA1822 + + + diff --git a/src/Ninject.Web.AspNetCore.ComplianceTest/KeyedDependencyInjectionComplianceTests.cs b/src/Ninject.Web.AspNetCore.ComplianceTest/KeyedDependencyInjectionComplianceTests.cs index 934d3e3..0d98da0 100644 --- a/src/Ninject.Web.AspNetCore.ComplianceTest/KeyedDependencyInjectionComplianceTests.cs +++ b/src/Ninject.Web.AspNetCore.ComplianceTest/KeyedDependencyInjectionComplianceTests.cs @@ -12,14 +12,14 @@ namespace Ninject.Web.AspNetCore.ComplianceTest; /// public class KeyedDependencyInjectionComplianceTests : Microsoft.Extensions.DependencyInjection.Specification.KeyedDependencyInjectionSpecificationTests { - protected override IServiceProvider CreateServiceProvider(IServiceCollection serviceCollection) + protected override IServiceProvider CreateServiceProvider(IServiceCollection collection) { var kernel = new AspNetCoreKernel(); // remove autobinding as CreateServiceWithKeyedParameter e.g. tests that no autobinding happens. kernel.Components.Remove(); var factory = new NinjectServiceProviderFactory(kernel); - return factory.CreateBuilder(serviceCollection).Build(); + return factory.CreateBuilder(collection).Build(); } #pragma warning disable xUnit1024, xUnit1026 diff --git a/src/Ninject.Web.AspNetCore.ComplianceTest/Ninject.Web.AspNetCore.ComplianceTest.csproj b/src/Ninject.Web.AspNetCore.ComplianceTest/Ninject.Web.AspNetCore.ComplianceTest.csproj index 61851cf..5d30a1a 100644 --- a/src/Ninject.Web.AspNetCore.ComplianceTest/Ninject.Web.AspNetCore.ComplianceTest.csproj +++ b/src/Ninject.Web.AspNetCore.ComplianceTest/Ninject.Web.AspNetCore.ComplianceTest.csproj @@ -3,6 +3,9 @@ net10.0 false + + CA1707,CA1822,CA2263 + diff --git a/src/Ninject.Web.AspNetCore.Test/Fakes/FakeActivationCacheAccessor.cs b/src/Ninject.Web.AspNetCore.Test/Fakes/FakeActivationCacheAccessor.cs index 2b58dad..023aa1b 100644 --- a/src/Ninject.Web.AspNetCore.Test/Fakes/FakeActivationCacheAccessor.cs +++ b/src/Ninject.Web.AspNetCore.Test/Fakes/FakeActivationCacheAccessor.cs @@ -7,7 +7,7 @@ namespace Ninject.Web.AspNetCore.Test.Fakes { - public class FakeActivationCacheAccessor : IActivationCache, IActivationCacheAccessor + public sealed class FakeActivationCacheAccessor : IActivationCache, IActivationCacheAccessor { private readonly ConditionalWeakTable _trackedInstances = new ConditionalWeakTable(); diff --git a/src/Ninject.Web.AspNetCore.Test/Fakes/MoritaAssaultRifle.cs b/src/Ninject.Web.AspNetCore.Test/Fakes/MoritaAssaultRifle.cs index 8d5472c..efb3173 100644 --- a/src/Ninject.Web.AspNetCore.Test/Fakes/MoritaAssaultRifle.cs +++ b/src/Ninject.Web.AspNetCore.Test/Fakes/MoritaAssaultRifle.cs @@ -2,7 +2,7 @@ namespace Ninject.Web.AspNetCore.Test.Fakes { - public class MoritaAssaultRifle : IWeapon, IDisposable + public sealed class MoritaAssaultRifle : IWeapon, IDisposable { public bool IsDisposed { get; private set; } diff --git a/src/Ninject.Web.AspNetCore.Test/Ninject.Web.AspNetCore.Test.csproj b/src/Ninject.Web.AspNetCore.Test/Ninject.Web.AspNetCore.Test.csproj index e3af28d..372e59c 100644 --- a/src/Ninject.Web.AspNetCore.Test/Ninject.Web.AspNetCore.Test.csproj +++ b/src/Ninject.Web.AspNetCore.Test/Ninject.Web.AspNetCore.Test.csproj @@ -3,6 +3,9 @@ net10.0 false + + CA1707,CA1822,CA2263 + diff --git a/src/Ninject.Web.AspNetCore.Test/Regression/NinjectBugsRegressionTest.cs b/src/Ninject.Web.AspNetCore.Test/Regression/NinjectBugsRegressionTest.cs index b7330be..63a61ba 100644 --- a/src/Ninject.Web.AspNetCore.Test/Regression/NinjectBugsRegressionTest.cs +++ b/src/Ninject.Web.AspNetCore.Test/Regression/NinjectBugsRegressionTest.cs @@ -27,7 +27,7 @@ public void KernelTryGetWithConstraint_WithMultipleMatchingBindings_ThrowsExcept service.Should().BeNull(); } - private IKernel CreateKernel() + private AspNetCoreKernel CreateKernel() { var settings = new NinjectSettings(); var kernel = new AspNetCoreKernel(settings); diff --git a/src/Ninject.Web.AspNetCore.Test/ServiceProviderReference/ServiceProviderReferenceTest.cs b/src/Ninject.Web.AspNetCore.Test/ServiceProviderReference/ServiceProviderReferenceTest.cs index 2e0d4b2..610dd61 100644 --- a/src/Ninject.Web.AspNetCore.Test/ServiceProviderReference/ServiceProviderReferenceTest.cs +++ b/src/Ninject.Web.AspNetCore.Test/ServiceProviderReference/ServiceProviderReferenceTest.cs @@ -105,7 +105,7 @@ public void ServiceProvider_ScopedServiceResolveServiceProvider_ReturnsScopedSer } } - private IServiceProvider CreateServiceProvider(Action serviceConfig = null) + private ServiceProvider CreateServiceProvider(Action serviceConfig = null) { var collection = new ServiceCollection(); @@ -120,7 +120,7 @@ private IServiceProvider CreateServiceProvider(Action service return collection.BuildServiceProvider(); } - private IList CreateInstances(IServiceProvider provider) + private List CreateInstances(IServiceProvider provider) { var instances = new List(); @@ -139,7 +139,7 @@ private IList CreateInstances(IServiceProvider provider) return instances; } - private static IList NinjaNames = new List + private static readonly List NinjaNames = new List { "Shadow", "Scorpion", diff --git a/src/Ninject.Web.AspNetCore.Test/Unit/ActivationCacheTest.cs b/src/Ninject.Web.AspNetCore.Test/Unit/ActivationCacheTest.cs index fc199d7..0007bea 100644 --- a/src/Ninject.Web.AspNetCore.Test/Unit/ActivationCacheTest.cs +++ b/src/Ninject.Web.AspNetCore.Test/Unit/ActivationCacheTest.cs @@ -10,19 +10,19 @@ namespace Ninject.Web.AspNetCore.Test.Unit /// Copy of the ActivationCacheTests from the Ninject core library to ensure that the replacement /// activation cache still behaves as Ninject expects it to. /// - public class ActivationCacheTests + public sealed class ActivationCacheTests : IDisposable { - private readonly WeakTableActivationCache testee; + private readonly WeakTableActivationCache _testee; public ActivationCacheTests() { - testee = new WeakTableActivationCache(); + _testee = new WeakTableActivationCache(); } [Fact] public void IsActivatedReturnsFalseForObjectsNotInTheActivationCache() { - var activated = testee.IsActivated(new object()); + var activated = _testee.IsActivated(new object()); activated.Should().BeFalse(); } @@ -32,9 +32,9 @@ public void IsActivatedReturnsTrueForObjectsInTheActivationCache() { var instance = new TestObject(42); - testee.AddActivatedInstance(instance); - var activated = testee.IsActivated(instance); - var activatedObjectCount = testee.ActivatedObjectCount; + _testee.AddActivatedInstance(instance); + var activated = _testee.IsActivated(instance); + var activatedObjectCount = _testee.ActivatedObjectCount; activated.Should().BeTrue(); activatedObjectCount.Should().Be(1); @@ -43,7 +43,7 @@ public void IsActivatedReturnsTrueForObjectsInTheActivationCache() [Fact] public void IsDeactivatedReturnsFalseForObjectsNotInTheDeactivationCache() { - var activated = testee.IsDeactivated(new object()); + var activated = _testee.IsDeactivated(new object()); activated.Should().BeFalse(); } @@ -53,9 +53,9 @@ public void IsDeactivatedReturnsTrueForObjectsInTheDeactivationCache() { var instance = new TestObject(42); - testee.AddDeactivatedInstance(instance); - var deactivated = testee.IsDeactivated(instance); - var deactivatedObjectCount = testee.DeactivatedObjectCount; + _testee.AddDeactivatedInstance(instance); + var deactivated = _testee.IsDeactivated(instance); + var deactivatedObjectCount = _testee.DeactivatedObjectCount; deactivated.Should().BeTrue(); deactivatedObjectCount.Should().Be(1); @@ -64,16 +64,16 @@ public void IsDeactivatedReturnsTrueForObjectsInTheDeactivationCache() [Fact] public void DeadObjectsAreRemoved() { - CreateCollectableInstances(testee); + CreateCollectableInstances(_testee); GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); - testee.Prune(); + _testee.Prune(); - var activatedObjectCount = testee.ActivatedObjectCount; - var deactivatedObjectCount = testee.DeactivatedObjectCount; + var activatedObjectCount = _testee.ActivatedObjectCount; + var deactivatedObjectCount = _testee.DeactivatedObjectCount; activatedObjectCount.Should().Be(0); deactivatedObjectCount.Should().Be(0); @@ -84,9 +84,9 @@ public void ImplementationDoesNotRelyOnObjectHashCode() { var instance = new TestObject(42); - testee.AddActivatedInstance(instance); + _testee.AddActivatedInstance(instance); instance.ChangeHashCode(43); - var isActivated = testee.IsActivated(instance); + var isActivated = _testee.IsActivated(instance); isActivated.Should().BeTrue(); } @@ -108,5 +108,10 @@ private void CreateCollectableInstances(WeakTableActivationCache activationCache activationCache.AddActivatedInstance(new TestObject(42)); activationCache.AddDeactivatedInstance(new TestObject(42)); } + + public void Dispose() + { + _testee?.Dispose(); + } } } \ No newline at end of file diff --git a/src/Ninject.Web.AspNetCore.Test/Unit/DisposalManagerConcurrencyTest.cs b/src/Ninject.Web.AspNetCore.Test/Unit/DisposalManagerConcurrencyTest.cs index b4bda63..d3c54b1 100644 --- a/src/Ninject.Web.AspNetCore.Test/Unit/DisposalManagerConcurrencyTest.cs +++ b/src/Ninject.Web.AspNetCore.Test/Unit/DisposalManagerConcurrencyTest.cs @@ -1,4 +1,6 @@ -using AwesomeAssertions; +using System; +using System.Globalization; +using AwesomeAssertions; using Ninject.Web.AspNetCore.Components; using Ninject.Web.AspNetCore.Test.Fakes; using System.Linq; @@ -34,7 +36,7 @@ public async Task CreateArea_FromDifferentConcurrentThreads_ShouldCreateSeparate var results = (await Task.WhenAll(tasks)).ToList(); results.Count.Should().Be(2); - results.All(r => r.StartsWith("OrderedAggregateDisposalArea")).Should().BeTrue(); + results.All(r => r.StartsWith("OrderedAggregateDisposalArea", StringComparison.InvariantCulture)).Should().BeTrue(); results[0].Should().NotBe(results[1]); } diff --git a/src/Ninject.Web.AspNetCore.Test/Unit/GenericConstraintValidtorTest.cs b/src/Ninject.Web.AspNetCore.Test/Unit/GenericConstraintValidtorTest.cs index a14589e..697241d 100644 --- a/src/Ninject.Web.AspNetCore.Test/Unit/GenericConstraintValidtorTest.cs +++ b/src/Ninject.Web.AspNetCore.Test/Unit/GenericConstraintValidtorTest.cs @@ -6,7 +6,7 @@ namespace Ninject.Web.AspNetCore.Test.Unit { - public class GenericConstraintValidtorTest + public sealed class GenericConstraintValidtorTest : IDisposable { private readonly ConstrainedGenericBindingResolver _resolver = new ConstrainedGenericBindingResolver(); @@ -50,15 +50,20 @@ public void AdvancedConstrainedGeneric_WithNonMatchingType_Fails() result.Should().BeFalse(); } - private class SimpleConstrainedType + private sealed class SimpleConstrainedType where T : Exception { } - private class AdvancedConstrainedType + private sealed class AdvancedConstrainedType where TContainer : IEnumerable where T : class { } + + public void Dispose() + { + _resolver?.Dispose(); + } } } diff --git a/src/Ninject.Web.AspNetCore.Test/Unit/IndexedBindingPrecedenceComparerTest.cs b/src/Ninject.Web.AspNetCore.Test/Unit/IndexedBindingPrecedenceComparerTest.cs index 7c7ecfc..76e1081 100644 --- a/src/Ninject.Web.AspNetCore.Test/Unit/IndexedBindingPrecedenceComparerTest.cs +++ b/src/Ninject.Web.AspNetCore.Test/Unit/IndexedBindingPrecedenceComparerTest.cs @@ -72,7 +72,7 @@ private IEnumerable BindingVariants() yield return new DummyBinding { Service = typeof(Predicate<>), IsImplicit = true }; } - private class DummyBinding : IBinding + private sealed class DummyBinding : IBinding { public Type Service { get; set; } public bool IsImplicit { get; set; } diff --git a/src/Ninject.Web.AspNetCore.Test/Unit/ServiceProviderResolutionRootTest.cs b/src/Ninject.Web.AspNetCore.Test/Unit/ServiceProviderResolutionRootTest.cs index 1bb7415..81b6c67 100644 --- a/src/Ninject.Web.AspNetCore.Test/Unit/ServiceProviderResolutionRootTest.cs +++ b/src/Ninject.Web.AspNetCore.Test/Unit/ServiceProviderResolutionRootTest.cs @@ -52,7 +52,7 @@ private ServiceProviderScopeResolutionRoot CreateScopeResolutionRoot() return new ServiceProviderScopeResolutionRoot(kernel, scope); } - private IKernel CreateKernel() + private AspNetCoreKernel CreateKernel() { var kernel = new AspNetCoreKernel(new NinjectSettings { LoadExtensions = false }); diff --git a/src/Ninject.Web.AspNetCore/AspNetCoreModule.cs b/src/Ninject.Web.AspNetCore/AspNetCoreModule.cs index 398c870..d4da0d5 100644 --- a/src/Ninject.Web.AspNetCore/AspNetCoreModule.cs +++ b/src/Ninject.Web.AspNetCore/AspNetCoreModule.cs @@ -13,11 +13,11 @@ public class AspNetCoreModule : NinjectModule { public override void Load() { - Kernel.Components.Add(); // provides the scope object for InRequestScope bindings - Kernel.Bind().ToConstant(Kernel as IServiceScopeFactory); + Kernel!.Components.Add(); // provides the scope object for InRequestScope bindings + Kernel.Bind().ToConstant((Kernel as IServiceScopeFactory)!); // FixServicesForPublicatonAdapter can only work when it is used through the AspNetCoreHostConfiguration mechanism which is not always used // like for example in the context of a Blazor application. - Kernel.Bind().To().When(request => Kernel.GetBindings(typeof(AspNetCoreHostConfiguration)).Count() > 0); + Kernel.Bind().To().When(request => Kernel.GetBindings(typeof(AspNetCoreHostConfiguration)).Any()); } } } diff --git a/src/Ninject.Web.AspNetCore/BindingIndex.cs b/src/Ninject.Web.AspNetCore/BindingIndex.cs index 6afbc3e..5f8e1b3 100644 --- a/src/Ninject.Web.AspNetCore/BindingIndex.cs +++ b/src/Ninject.Web.AspNetCore/BindingIndex.cs @@ -21,7 +21,7 @@ private UnkeyedIndexKey() public override string ToString() => nameof(UnkeyedIndexKey); } - private readonly IDictionary _bindingIndexMap = new Dictionary(); + private readonly Dictionary _bindingIndexMap = new Dictionary(); public int Count { get; private set; } diff --git a/src/Ninject.Web.AspNetCore/Components/ConstructorReflectionStrategyWithKeyedSupport.cs b/src/Ninject.Web.AspNetCore/Components/ConstructorReflectionStrategyWithKeyedSupport.cs index 15172e8..85d0c45 100644 --- a/src/Ninject.Web.AspNetCore/Components/ConstructorReflectionStrategyWithKeyedSupport.cs +++ b/src/Ninject.Web.AspNetCore/Components/ConstructorReflectionStrategyWithKeyedSupport.cs @@ -54,8 +54,8 @@ public void Execute(IPlan plan) foreach (ConstructorInfo constructor in constructors) { - var hasInjectAttribute = constructor.HasAttribute(Settings.InjectAttribute); - var hasObsoleteAttribute = constructor.HasAttribute(typeof(ObsoleteAttribute)); + var hasInjectAttribute = constructor.HasAttribute(Settings!.InjectAttribute); + var hasObsoleteAttribute = constructor.HasAttribute(); var directive = new ConstructorInjectionDirectiveWithKeyedSupport(constructor, InjectorFactory.Create(constructor)) { HasInjectAttribute = hasInjectAttribute, diff --git a/src/Ninject.Web.AspNetCore/Components/DisposalManager.cs b/src/Ninject.Web.AspNetCore/Components/DisposalManager.cs index 9ef50db..97be70e 100644 --- a/src/Ninject.Web.AspNetCore/Components/DisposalManager.cs +++ b/src/Ninject.Web.AspNetCore/Components/DisposalManager.cs @@ -27,17 +27,14 @@ public class DisposalManager : NinjectComponent, IDisposalManager public DisposalManager(IActivationCache activationCache) { - if (activationCache == null) - { - throw new ArgumentNullException(nameof(activationCache)); - } + ArgumentNullException.ThrowIfNull(activationCache); - if (!(activationCache is IActivationCacheAccessor)) + if (!(activationCache is IActivationCacheAccessor cache)) { - throw new ArgumentException(nameof(activationCache), "DisposalManager expects the activation cache to also implement IActivationCacheAccessor"); + throw new ArgumentException("DisposalManager expects the activation cache to also implement IActivationCacheAccessor", nameof(activationCache)); } - _cacheAccessor = activationCache as IActivationCacheAccessor; + _cacheAccessor = cache; } public void RemoveInstance(InstanceReference instanceReference) @@ -74,10 +71,10 @@ public IDisposalCollectorArea CreateArea() /// it goes through the active service instances in reverse and disposed all the services that are "marked" /// for disposal. /// - private class OrderedAggregateDisposalArea : IDisposalCollectorArea + private sealed class OrderedAggregateDisposalArea : IDisposalCollectorArea { private readonly DisposalManager _manager; - private IList _disposals = new List(); + private List _disposals = new List(); public OrderedAggregateDisposalArea(DisposalManager manager) { @@ -112,7 +109,7 @@ public void Register(IActivationEntry activationEntry) /// /// If there is no active disposal collection area, we just immediately dispose as Ninject does normally. /// - private class ImmediateDisposal : IDisposalCollector + private sealed class ImmediateDisposal : IDisposalCollector { public static ImmediateDisposal Instance { get; } = new ImmediateDisposal(); @@ -127,7 +124,7 @@ public void Register(IActivationEntry activationEntry) /// and services are only disposed with the disposal of the outermost /// because only there do we know all the services that need to be disposed. /// - private class InnerDisposalArea : IDisposalCollectorArea + private sealed class InnerDisposalArea : IDisposalCollectorArea { private readonly IDisposalCollectorArea _parent; diff --git a/src/Ninject.Web.AspNetCore/Hosting/AspNetCoreHost.cs b/src/Ninject.Web.AspNetCore/Hosting/AspNetCoreHost.cs index ca7a78b..19ab15a 100644 --- a/src/Ninject.Web.AspNetCore/Hosting/AspNetCoreHost.cs +++ b/src/Ninject.Web.AspNetCore/Hosting/AspNetCoreHost.cs @@ -28,7 +28,9 @@ public void Start() .ConfigureServices(s => { s.AddNinject(_kernel); }); _configuration.Apply(builder); +#pragma warning disable ASPDEPR008 var host = builder.Build(); +#pragma warning restore ASPDEPR008 if (_configuration == null || _configuration.BlockOnStart) { diff --git a/src/Ninject.Web.AspNetCore/Hosting/DefaultWebHostConfiguration.cs b/src/Ninject.Web.AspNetCore/Hosting/DefaultWebHostConfiguration.cs index 5ab2d7a..a81afc8 100644 --- a/src/Ninject.Web.AspNetCore/Hosting/DefaultWebHostConfiguration.cs +++ b/src/Ninject.Web.AspNetCore/Hosting/DefaultWebHostConfiguration.cs @@ -24,7 +24,9 @@ namespace Ninject.Web.AspNetCore.Hosting public class DefaultWebHostConfiguration { private readonly string[] _cliArgs; +#pragma warning disable ASPDEPR004 private readonly WebHostBuilder _builder = new WebHostBuilder(); +#pragma warning restore ASPDEPR004 public DefaultWebHostConfiguration(string[] cliArgs) { @@ -105,8 +107,8 @@ public DefaultWebHostConfiguration ConfigureAllowedHosts() { if (options.AllowedHosts == null || options.AllowedHosts.Count == 0) { - string[] array = hostingContext.Configuration["AllowedHosts"]?.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); - options.AllowedHosts = ((array != null && array.Length != 0) ? array : new string[] { "*" }); + string[] array = hostingContext.Configuration["AllowedHosts"]?.Split([';'], StringSplitOptions.RemoveEmptyEntries); + options.AllowedHosts = ((array != null && array.Length != 0) ? array : ["*"]); } }); services.AddSingleton((IOptionsChangeTokenSource)new ConfigurationChangeTokenSource(hostingContext.Configuration)); @@ -124,7 +126,11 @@ public DefaultWebHostConfiguration ConfigureForwardedHeaders() services.Configure((ForwardedHeadersOptions options) => { options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto; +#if NET10_0_OR_GREATER + options.KnownIPNetworks.Clear(); +#else options.KnownNetworks.Clear(); +#endif options.KnownProxies.Clear(); }); services.AddTransient(); diff --git a/src/Ninject.Web.AspNetCore/NinjectServiceProvider.cs b/src/Ninject.Web.AspNetCore/NinjectServiceProvider.cs index a4bdf21..293d05e 100644 --- a/src/Ninject.Web.AspNetCore/NinjectServiceProvider.cs +++ b/src/Ninject.Web.AspNetCore/NinjectServiceProvider.cs @@ -27,7 +27,7 @@ namespace Ninject.Web.AspNetCore /// instances that are associated with the root scope. This is why we implement and this is why /// we pass an constructor argument when creating the root service provider. /// - public class NinjectServiceProvider : IServiceProvider, ISupportRequiredService, IDisposable + public sealed class NinjectServiceProvider : IServiceProvider, ISupportRequiredService, IDisposable #if NET8_0_OR_GREATER , IKeyedServiceProvider #endif @@ -149,7 +149,7 @@ private T ResolveKeyedService(Type serviceType, object serviceKey, bool isUni var result = _resolutionRoot.Resolve(keyedRequest); if (isUnique) { - return (result as object[]).FirstOrDefault() as T; + return (result as object[])!.FirstOrDefault() as T; } else { diff --git a/src/Ninject.Web.AspNetCore/NinjectServiceProviderFactory.cs b/src/Ninject.Web.AspNetCore/NinjectServiceProviderFactory.cs index c56d795..8c85216 100644 --- a/src/Ninject.Web.AspNetCore/NinjectServiceProviderFactory.cs +++ b/src/Ninject.Web.AspNetCore/NinjectServiceProviderFactory.cs @@ -24,7 +24,7 @@ public NinjectServiceProviderBuilder CreateBuilder(IServiceCollection services) public IServiceProvider CreateServiceProvider(NinjectServiceProviderBuilder containerBuilder) { - if (containerBuilder == null) throw new ArgumentNullException(nameof(containerBuilder)); + ArgumentNullException.ThrowIfNull(containerBuilder); return containerBuilder.Build(); } diff --git a/src/Ninject.Web.AspNetCore/Planning/ParameterTargetWithKeyedSupport.cs b/src/Ninject.Web.AspNetCore/Planning/ParameterTargetWithKeyedSupport.cs index 3b025cd..50728fa 100644 --- a/src/Ninject.Web.AspNetCore/Planning/ParameterTargetWithKeyedSupport.cs +++ b/src/Ninject.Web.AspNetCore/Planning/ParameterTargetWithKeyedSupport.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using System.Reflection; using Microsoft.Extensions.DependencyInjection; @@ -135,19 +136,19 @@ private object ResolveServiceKeyValue(IContext parent) { try { - result = Convert.ChangeType(asConvertible, this.Type); + result = Convert.ChangeType(asConvertible, Type, CultureInfo.InvariantCulture); } catch (InvalidCastException) { // we have to throw and InvalidOperationException in this case, a InvalidCastException // is not passing the tests - throw new InvalidOperationException("Cannot convert " + asConvertible + " to " + this.Type); + throw new InvalidOperationException("Cannot convert " + asConvertible + " to " + Type); } } if (result != null && !this.Type.IsAssignableFrom(result.GetType())) { - throw new InvalidOperationException("Cannot convert " + result + " to " + this.Type); + throw new InvalidOperationException("Cannot convert " + result + " to " + Type); } return result; diff --git a/src/Ninject.Web.AspNetCore/RequestScope.cs b/src/Ninject.Web.AspNetCore/RequestScope.cs index 816650f..30080ac 100644 --- a/src/Ninject.Web.AspNetCore/RequestScope.cs +++ b/src/Ninject.Web.AspNetCore/RequestScope.cs @@ -17,7 +17,9 @@ public RequestScope() } else { +#pragma warning disable CA2201 throw new ApplicationException("Nesting of RequestScope is not allowed."); +#pragma warning restore CA2201 } } diff --git a/src/Ninject.Web.AspNetCore/ServiceCollectionAdapter.cs b/src/Ninject.Web.AspNetCore/ServiceCollectionAdapter.cs index 908b89a..dfd4aa0 100644 --- a/src/Ninject.Web.AspNetCore/ServiceCollectionAdapter.cs +++ b/src/Ninject.Web.AspNetCore/ServiceCollectionAdapter.cs @@ -13,10 +13,7 @@ public class ServiceCollectionAdapter public void Populate(IKernel kernel, IServiceCollection serviceCollection) { - if (serviceCollection == null) - { - throw new ArgumentNullException(nameof(serviceCollection)); - } + ArgumentNullException.ThrowIfNull(serviceCollection); var adapters = kernel.GetAll().ToList(); var bindingIndex = new BindingIndex(); diff --git a/src/Ninject.Web.AspNetCore/ServiceProviderScopeParameter.cs b/src/Ninject.Web.AspNetCore/ServiceProviderScopeParameter.cs index 8aa938f..4a48ecd 100644 --- a/src/Ninject.Web.AspNetCore/ServiceProviderScopeParameter.cs +++ b/src/Ninject.Web.AspNetCore/ServiceProviderScopeParameter.cs @@ -8,7 +8,7 @@ namespace Ninject.Web.AspNetCore public class ServiceProviderScopeParameter : Parameter { private readonly NinjectServiceScope _scope; - private readonly IList _children = new List(); + private readonly List _children = new List(); public IServiceProvider SourceServiceProvider => _scope.ServiceProvider; @@ -32,7 +32,7 @@ public DisposableObject DeriveTransientScope() return child; } - private class TransientScope : DisposableObject + private sealed class TransientScope : DisposableObject { } } diff --git a/src/SampleApplication/Controllers/HomeController.cs b/src/SampleApplication/Controllers/HomeController.cs index 7843bff..ac181f7 100644 --- a/src/SampleApplication/Controllers/HomeController.cs +++ b/src/SampleApplication/Controllers/HomeController.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Globalization; using System.Linq; using System.Reflection; using Microsoft.AspNetCore.Hosting.Server; @@ -58,8 +59,8 @@ public IActionResult Memory() ViewData["ServiceReferences"] = new Dictionary { - ["Alive"] = alive.Count.ToString(), - ["Dead"] = dead.Count.ToString(), + ["Alive"] = alive.Count.ToString(CultureInfo.InvariantCulture), + ["Dead"] = dead.Count.ToString(CultureInfo.InvariantCulture), }; return View(); diff --git a/src/SampleApplication/Program.cs b/src/SampleApplication/Program.cs index fc5be7e..da45278 100644 --- a/src/SampleApplication/Program.cs +++ b/src/SampleApplication/Program.cs @@ -24,7 +24,7 @@ public static void Main(string[] args) // setting the variable in IIS. var model = Environment.GetEnvironmentVariable("SERVER_HOSTING_MODEL"); // Command line arguments have higher precedence than environment variables - model = args.FirstOrDefault(arg => arg.StartsWith("--use"))?.Substring(5) ?? model; + model = args.FirstOrDefault(arg => arg.StartsWith("--use", StringComparison.InvariantCulture))?.Substring(5) ?? model; var hostConfiguration = new AspNetCoreHostConfiguration(args) .UseStartup() diff --git a/src/SampleApplication/Service/ChatBot/ChatBotService.cs b/src/SampleApplication/Service/ChatBot/ChatBotService.cs index 7bc8a89..48ada56 100644 --- a/src/SampleApplication/Service/ChatBot/ChatBotService.cs +++ b/src/SampleApplication/Service/ChatBot/ChatBotService.cs @@ -1,11 +1,12 @@ using System; using System.Collections.Generic; +using System.Globalization; namespace SampleApplication.Service.ChatBot { public class ChatBotService : IChatBotService { - private static readonly IDictionary _messageTemplates = new Dictionary + private static readonly Dictionary MessageTemplates = new Dictionary { [HelloType.Normal] = "Hello {0}.", [HelloType.Casual] = "Hey {0}, what up?", @@ -21,7 +22,7 @@ public HelloResponse SayHello(HelloRequest request) return new HelloResponse { - HelloMessage = String.Format(_messageTemplates[request.Type], request.Name), + HelloMessage = string.Format(CultureInfo.InvariantCulture, MessageTemplates[request.Type], request.Name), From = "ChatBot 1.0" }; } diff --git a/src/SampleApplication/Service/ControllerFromInterfaceApplicationModelAdapter.cs b/src/SampleApplication/Service/ControllerFromInterfaceApplicationModelAdapter.cs index 0c112d5..7e87c2a 100644 --- a/src/SampleApplication/Service/ControllerFromInterfaceApplicationModelAdapter.cs +++ b/src/SampleApplication/Service/ControllerFromInterfaceApplicationModelAdapter.cs @@ -55,7 +55,7 @@ private ControllerModel CreateControllerModel() return controllerModel; } - private ActionModel CreateActionModel(PublishInstruction publication, MethodInfo methodInfo) + private static ActionModel CreateActionModel(PublishInstruction publication, MethodInfo methodInfo) { var result = new ActionModel(methodInfo, new List()); result.ActionName = methodInfo.Name; From 78e1bac3b4a4192105076bf320532a2982152e9b Mon Sep 17 00:00:00 2001 From: Lukas Angerer Date: Wed, 19 Aug 2026 13:04:04 +0200 Subject: [PATCH 2/5] Migrated solution to the new slnx format --- .github/workflows/ci.yml | 4 +- doc/release-process.md | 4 +- src/Ninject.Web.AspNetCore.sln | 69 --------------------------------- src/Ninject.Web.AspNetCore.slnx | 18 +++++++++ 4 files changed, 22 insertions(+), 73 deletions(-) delete mode 100644 src/Ninject.Web.AspNetCore.sln create mode 100644 src/Ninject.Web.AspNetCore.slnx diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 38612ea..469289e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,6 +14,6 @@ jobs: dotnet-version: '10.0.x' - name: Build - run: dotnet build src/Ninject.Web.AspNetCore.sln -c Release + run: dotnet build src/Ninject.Web.AspNetCore.slnx -c Release - name: Test - run: dotnet test src/Ninject.Web.AspNetCore.sln -c Release + run: dotnet test src/Ninject.Web.AspNetCore.slnx -c Release diff --git a/doc/release-process.md b/doc/release-process.md index f7a163a..c512b57 100644 --- a/doc/release-process.md +++ b/doc/release-process.md @@ -3,8 +3,8 @@ Build and package the project with the _Release_ configuration. ``` $version = "5.1.x" -dotnet build .\src\Ninject.Web.AspNetCore.sln -c Release -p:Version="$version" -dotnet pack .\src\Ninject.Web.AspNetCore.sln -c Release --include-symbols -p:SymbolPackageFormat=snupkg -p:Version="$version" +dotnet build .\src\Ninject.Web.AspNetCore.slnx -c Release -p:Version="$version" +dotnet pack .\src\Ninject.Web.AspNetCore.slnx -c Release --include-symbols -p:SymbolPackageFormat=snupkg -p:Version="$version" ``` Publish all three packages with the `publish.ps1` script, replacing the API key and versions as needed. diff --git a/src/Ninject.Web.AspNetCore.sln b/src/Ninject.Web.AspNetCore.sln deleted file mode 100644 index 5a8d338..0000000 --- a/src/Ninject.Web.AspNetCore.sln +++ /dev/null @@ -1,69 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.0.31521.260 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ninject.Web.AspNetCore", "Ninject.Web.AspNetCore\Ninject.Web.AspNetCore.csproj", "{C54EEE23-AAF5-459D-A235-E5507811CBD7}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ninject.Web.AspNetCore.HttpSys", "Ninject.Web.AspNetCore.Httpsys\Ninject.Web.AspNetCore.HttpSys.csproj", "{2E8666BD-C364-43D7-92E4-623021E63085}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ninject.Web.AspNetCore.IIS", "Ninject.Web.AspNetCore.IIS\Ninject.Web.AspNetCore.IIS.csproj", "{5D9455D9-FE35-4E0B-B621-3A6D810ECF6A}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleApplication", "SampleApplication\SampleApplication.csproj", "{BE382F5B-43A9-4F5E-BCD0-AE885E122657}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ninject.Web.AspNetCore.Test", "Ninject.Web.AspNetCore.Test\Ninject.Web.AspNetCore.Test.csproj", "{7DB7F499-E11E-4B45-BDFD-1883BC8C224D}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Files", "Solution Files", "{63A11E71-677A-4052-9944-32A9156B0505}" - ProjectSection(SolutionItems) = preProject - ..\.editorconfig = ..\.editorconfig - ..\.gitignore = ..\.gitignore - ..\CHANGELOG = ..\CHANGELOG - ..\LICENSE = ..\LICENSE - ..\README.md = ..\README.md - EndProjectSection -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ninject.Web.AspNetCore.ComplianceTest", "Ninject.Web.AspNetCore.ComplianceTest\Ninject.Web.AspNetCore.ComplianceTest.csproj", "{238FACAF-E2C4-445A-9C63-C3A0AC59B098}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleBlazorApplication", "SampleBlazorApplication\SampleBlazorApplication.csproj", "{50A0305B-72C1-418C-8515-A7193F7FEA5E}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {C54EEE23-AAF5-459D-A235-E5507811CBD7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {C54EEE23-AAF5-459D-A235-E5507811CBD7}.Debug|Any CPU.Build.0 = Debug|Any CPU - {C54EEE23-AAF5-459D-A235-E5507811CBD7}.Release|Any CPU.ActiveCfg = Release|Any CPU - {C54EEE23-AAF5-459D-A235-E5507811CBD7}.Release|Any CPU.Build.0 = Release|Any CPU - {2E8666BD-C364-43D7-92E4-623021E63085}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {2E8666BD-C364-43D7-92E4-623021E63085}.Debug|Any CPU.Build.0 = Debug|Any CPU - {2E8666BD-C364-43D7-92E4-623021E63085}.Release|Any CPU.ActiveCfg = Release|Any CPU - {2E8666BD-C364-43D7-92E4-623021E63085}.Release|Any CPU.Build.0 = Release|Any CPU - {5D9455D9-FE35-4E0B-B621-3A6D810ECF6A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {5D9455D9-FE35-4E0B-B621-3A6D810ECF6A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {5D9455D9-FE35-4E0B-B621-3A6D810ECF6A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {5D9455D9-FE35-4E0B-B621-3A6D810ECF6A}.Release|Any CPU.Build.0 = Release|Any CPU - {BE382F5B-43A9-4F5E-BCD0-AE885E122657}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {BE382F5B-43A9-4F5E-BCD0-AE885E122657}.Debug|Any CPU.Build.0 = Debug|Any CPU - {BE382F5B-43A9-4F5E-BCD0-AE885E122657}.Release|Any CPU.ActiveCfg = Release|Any CPU - {7DB7F499-E11E-4B45-BDFD-1883BC8C224D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {7DB7F499-E11E-4B45-BDFD-1883BC8C224D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {7DB7F499-E11E-4B45-BDFD-1883BC8C224D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {7DB7F499-E11E-4B45-BDFD-1883BC8C224D}.Release|Any CPU.Build.0 = Release|Any CPU - {238FACAF-E2C4-445A-9C63-C3A0AC59B098}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {238FACAF-E2C4-445A-9C63-C3A0AC59B098}.Debug|Any CPU.Build.0 = Debug|Any CPU - {238FACAF-E2C4-445A-9C63-C3A0AC59B098}.Release|Any CPU.ActiveCfg = Release|Any CPU - {238FACAF-E2C4-445A-9C63-C3A0AC59B098}.Release|Any CPU.Build.0 = Release|Any CPU - {50A0305B-72C1-418C-8515-A7193F7FEA5E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {50A0305B-72C1-418C-8515-A7193F7FEA5E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {50A0305B-72C1-418C-8515-A7193F7FEA5E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {50A0305B-72C1-418C-8515-A7193F7FEA5E}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {941ED31F-9580-4CA2-BB00-089C5871B095} - EndGlobalSection -EndGlobal diff --git a/src/Ninject.Web.AspNetCore.slnx b/src/Ninject.Web.AspNetCore.slnx new file mode 100644 index 0000000..6e5c922 --- /dev/null +++ b/src/Ninject.Web.AspNetCore.slnx @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + From a519a4678ea639b103eb78173b5e54e8cd3fc35b Mon Sep 17 00:00:00 2001 From: Lukas Angerer Date: Wed, 19 Aug 2026 13:47:03 +0200 Subject: [PATCH 3/5] New CI/CD pipelines with automated publishing (NuGet trusted publishing) --- .github/workflows/build.yml | 41 +++++++++++++++++++++++ .github/workflows/ci.yml | 19 ----------- .github/workflows/publish.yml | 61 +++++++++++++++++++++++++++++++++++ README.md | 2 +- doc/publish.ps1 | 16 --------- doc/release-process.md | 21 ++++++------ 6 files changed, 112 insertions(+), 48 deletions(-) create mode 100644 .github/workflows/build.yml delete mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/publish.yml delete mode 100644 doc/publish.ps1 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..b7c24de --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,41 @@ +name: .NET Build + +on: + push: + branches: [ "**" ] + pull_request: + branches: [ "main" ] + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +permissions: + contents: read + +env: + SOLUTION_FILE: src/Ninject.Web.AspNetCore.slnx + +jobs: + build: + runs-on: ubuntu-latest + name: Build and Test + steps: + # Checkout the repository + - name: Checkout code + uses: actions/checkout@v5 + + # Setup .NET Core SDK + - name: Setup .NET + uses: actions/setup-dotnet@v5 + with: + dotnet-version: 10.0.x + + - name: Restore dependencies + run: dotnet restore $SOLUTION_FILE + + - name: Build + run: dotnet build --no-restore $SOLUTION_FILE + + - name: Test + run: dotnet test --no-build $SOLUTION_FILE diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index 469289e..0000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: .NET 10 CI -on: [push] - -jobs: - build: - runs-on: ubuntu-latest - name: Build and Test - steps: - - uses: actions/checkout@v5 - - - uses: actions/setup-dotnet@v5 - name: Setup .NET SDK - with: - dotnet-version: '10.0.x' - - - name: Build - run: dotnet build src/Ninject.Web.AspNetCore.slnx -c Release - - name: Test - run: dotnet test src/Ninject.Web.AspNetCore.slnx -c Release diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..7e95662 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,61 @@ +name: NuGet Package Release + +on: + push: + tags: + - 'v*.*.*' + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: false + +permissions: + contents: read + +env: + SOLUTION_FILE: src/Ninject.Web.AspNetCore.slnx + +jobs: + build: + runs-on: ubuntu-latest + permissions: + id-token: write # required so the job can request a GitHub OIDC token for NuGet Trusted Publishing + + steps: + # Checkout the repository + - name: Checkout code + uses: actions/checkout@v5 + + # Setup .NET Core SDK + - name: Setup .NET Core + uses: actions/setup-dotnet@v5 + with: + dotnet-version: 10.0.x + + - name: Restore dependencies + run: dotnet restore $SOLUTION_FILE + + - name: Build + run: dotnet build --no-restore $SOLUTION_FILE + + - name: Test + run: dotnet test --no-build $SOLUTION_FILE + + # Derive the package version from the pushed tag, e.g. refs/tags/v10.0.1 -> 10.0.1 + - name: Extract version from tag + id: version + run: echo "version=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT" + + - name: Pack Ninject.Web.AspNetCore + run: dotnet pack $SOLUTION_FILE -c Release --include-symbols -p:SymbolPackageFormat=snupkg -p:Version=${{ steps.version.outputs.version }} --output ./artifacts + + # Exchange the GitHub OIDC token for a short-lived (1 hour) NuGet API key + - name: NuGet login (OIDC -> temp API key) + uses: NuGet/login@v1 + id: login + with: + user: ${{ secrets.NUGET_USER }} + + # Push the packages to NuGet + - name: Push to NuGet + run: dotnet nuget push ./artifacts/*.nupkg --api-key ${{ steps.login.outputs.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json diff --git a/README.md b/README.md index 0b36fa3..3822074 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![GitHub](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/lord-executor/Ninject.Web.AspNetCore/blob/master/LICENSE) [![.NET 8 CI](https://github.com/lord-executor/Ninject.Web.AspNetCore/actions/workflows/ci.yml/badge.svg)](https://github.com/lord-executor/Ninject.Web.AspNetCore/actions/workflows/ci.yml) +[![GitHub](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/lord-executor/Ninject.Web.AspNetCore/blob/master/LICENSE) [![.NET Build](https://github.com/lord-executor/Ninject.Web.AspNetCore/actions/workflows/build.yml/badge.svg)](https://github.com/lord-executor/Ninject.Web.AspNetCore/actions/workflows/build.yml) # Overview diff --git a/doc/publish.ps1 b/doc/publish.ps1 deleted file mode 100644 index a55769c..0000000 --- a/doc/publish.ps1 +++ /dev/null @@ -1,16 +0,0 @@ -param( - [Parameter(Mandatory=$true)] - [string] $apiKey, - [Parameter(Mandatory=$true)] - [string] $version = $null -) - -$projects = ( - "Ninject.Web.AspNetCore", - "Ninject.Web.AspNetCore.IIS", - "Ninject.Web.AspNetCore.Httpsys" -) - -$projects | ForEach-Object { - dotnet nuget push "src\$_\bin\Release\$_.$version.nupkg" -k $apiKey -s https://api.nuget.org/v3/index.json -} diff --git a/doc/release-process.md b/doc/release-process.md index c512b57..524b6d8 100644 --- a/doc/release-process.md +++ b/doc/release-process.md @@ -1,18 +1,15 @@ # Release Process -Build and package the project with the _Release_ configuration. +Releases are built, packed and published automatically by the [`NuGet Package Release`](../.github/publish.yml) GitHub Actions workflow. +To ship a release, push a tag matching `v*.*.*` (e.g. `v10.0.1`): ``` -$version = "5.1.x" -dotnet build .\src\Ninject.Web.AspNetCore.slnx -c Release -p:Version="$version" -dotnet pack .\src\Ninject.Web.AspNetCore.slnx -c Release --include-symbols -p:SymbolPackageFormat=snupkg -p:Version="$version" +git tag v10.0.1 +git push origin v10.0.1 ``` -Publish all three packages with the `publish.ps1` script, replacing the API key and versions as needed. -``` -.\doc\publish.ps1 -apiKey "NuGet APIKey" -version "$version" -``` +The workflow then: +1. Restores, builds and tests the solution. +2. Derives the package version from the tag name (stripping the leading `v`, e.g. `v10.0.1` -> `10.0.1`) and packs all three packages with that version via `-p:Version`. +3. Exchanges the workflow's GitHub OIDC token for a short-lived NuGet API key ([NuGet Trusted Publishing](https://learn.microsoft.com/en-us/nuget/nuget-org/trusted-publishing)) and pushes the packages to nuget.org. -With the NuGet API key stored in the Windows credential manager, we can do -``` -.\doc\publish.ps1 -apiKey $((Read-CredentialsStore -Target "NuGet:Ninject.Web.AspNetCore:APIKey").GetNetworkCredential().Password) -version "$version" -``` +No manual build, pack or publish steps are required. From af0f40cbacc61848c528335c54dd1bcf985cfb04 Mon Sep 17 00:00:00 2001 From: Lukas Angerer Date: Wed, 19 Aug 2026 13:50:43 +0200 Subject: [PATCH 4/5] Running dotnet format on the entire solution to fix formatting --- .editorconfig | 4 + ...KeyedDependencyInjectionComplianceTests.cs | 82 +++++------ .../AspNetCoreHostConfigurationExtensions.cs | 2 +- .../AspNetCoreHostConfigurationExtensions.cs | 2 +- .../Fakes/FakeActivationCacheAccessor.cs | 2 +- .../Fakes/IKeyedWeaponStorage.cs | 6 +- .../Fakes/IWarrior.cs | 2 +- .../Fakes/KeyedNinja.cs | 4 +- .../Fakes/KeyedWeaponStorage.cs | 6 +- .../Fakes/Knight.cs | 2 +- .../Fakes/Lance.cs | 2 +- .../Fakes/Longsword.cs | 2 +- .../Fakes/MobileInfantry.cs | 2 +- .../Fakes/MoritaAssaultRifle.cs | 2 +- .../Fakes/Ninja.cs | 2 +- .../Fakes/NinjaWithKeyedWeapon.cs | 2 +- .../Fakes/NotifiesWhenDisposed.cs | 2 +- .../Fakes/Samurai.cs | 2 +- .../Fakes/TestObject.cs | 2 +- .../Regression/NinjectBugsRegressionTest.cs | 2 +- .../ServiceProviderReferenceTest.cs | 7 +- .../Unit/ActivationCacheTest.cs | 4 +- .../Unit/AspNetCoreApplicationPluginTest.cs | 8 +- .../Unit/ControllerActivatorTest.cs | 2 +- .../Unit/DisposalManagerConcurrencyTest.cs | 5 +- .../Unit/DuplicateDescriptorTest.cs | 2 +- .../Unit/GenericConstraintValidtorTest.cs | 2 +- .../IndexedBindingPrecedenceComparerTest.cs | 2 +- .../Unit/PopulateFromServiceCollectionTest.cs | 6 +- .../Unit/RequestScopeDisposalTest.cs | 4 +- .../Unit/RequestScopeMiddlewareTest.cs | 2 +- .../Unit/ServiceProviderKeyedTest.cs | 22 +-- .../Unit/ServiceProviderResolutionRootTest.cs | 2 +- .../Unit/ServiceProviderScopeTest.cs | 134 +++++++++--------- .../Unit/ServiceProviderTest.cs | 16 +-- .../Unit/TestKernelContext.cs | 2 +- .../AspNetCoreApplicationPlugin.cs | 2 +- .../AspNetCoreKernel.cs | 5 +- .../AspNetCoreModule.cs | 2 +- src/Ninject.Web.AspNetCore/BindingIndex.cs | 6 +- .../Components/ActivationEntry.cs | 2 +- .../ConstrainedGenericBindingResolver.cs | 5 +- ...uctorReflectionStrategyWithKeyedSupport.cs | 84 +++++------ .../Components/DisposalManager.cs | 4 +- .../Components/IActivationCacheAccessor.cs | 2 +- .../Components/IDisposalManager.cs | 2 +- .../IndexedBindingPrecedenceComparer.cs | 2 +- .../Components/OrderedDisposalStrategy.cs | 2 +- .../Components/WeakTableActivationCache.cs | 4 +- .../ContextExtensions.cs | 42 +++--- .../ControllerActivationAdapter.cs | 4 +- .../DefaultDescriptorAdapter.cs | 2 +- .../Hosting/AspNetCoreHost.cs | 2 +- .../Hosting/AspNetCoreHostConfiguration.cs | 2 +- .../AspNetCoreHostConfigurationExtensions.cs | 5 +- .../Hosting/AspNetCoreHostingModule.cs | 2 +- .../Hosting/AspNetCoreStartupBase.cs | 10 +- .../Hosting/DefaultWebHostConfiguration.cs | 2 +- .../Hosting/EmptyStartup.cs | 2 +- .../Hosting/ForwardedHeadersStartupFilter.cs | 2 +- .../Hosting/HostFilteringStartupFilter.cs | 2 +- .../Hosting/IAspNetCoreHostConfiguration.cs | 2 +- .../Hosting/RequestScopeMiddleware.cs | 2 +- .../Hosting/RequestScopeStartupFilter.cs | 2 +- .../IDescriptorAdapter.cs | 4 +- .../IPopulateAdapter.cs | 2 +- .../KeyedDescriptorAdapter.cs | 2 +- .../NinjectServiceProvider.cs | 12 +- .../NinjectServiceProviderBuilder.cs | 5 +- .../NinjectServiceProviderFactory.cs | 2 +- .../NinjectServiceProviderIsService.cs | 2 +- .../NinjectServiceScope.cs | 2 +- .../Parameters/ServiceKeyParameter.cs | 2 +- ...uctorInjectionDirectiveWithKeyedSupport.cs | 4 +- .../Planning/KeyedServiceAnyKeyResolver.cs | 12 +- .../KeyedServicesMetaDataExtensions.cs | 2 +- .../ParameterTargetWithKeyedSupport.cs | 8 +- .../RequestActivation/KeyedRequest.cs | 4 +- .../KeyedRequestExtensions.cs | 4 +- src/Ninject.Web.AspNetCore/RequestScope.cs | 2 +- .../ServiceCollectionAdapter.cs | 8 +- .../ServiceCollectionExtensions.cs | 2 +- src/Ninject.Web.AspNetCore/ServiceKey.cs | 2 +- .../ServiceProviderScopeParameter.cs | 2 +- .../ServiceProviderScopeResolutionRoot.cs | 2 +- .../Controllers/HomeController.cs | 2 +- .../Models/ErrorViewModel.cs | 12 +- src/SampleApplication/Program.cs | 2 +- .../Service/ChatBot/ChatBotModule.cs | 2 +- .../Service/ChatBot/ChatBotService.cs | 2 +- .../Service/ChatBot/HelloRequest.cs | 2 +- .../Service/ChatBot/HelloResponse.cs | 2 +- .../Service/ChatBot/HelloType.cs | 2 +- .../Service/ChatBot/IChatBotService.cs | 2 +- ...lerFromInterfaceApplicationModelAdapter.cs | 2 +- .../Service/IApplicationModelAdapter.cs | 2 +- .../Service/PublishInstruction.cs | 2 +- ...nstructionApplicationModelConfiguration.cs | 2 +- ...shInstructionApplicationModelConvention.cs | 5 +- src/SampleApplication/Startup.cs | 2 +- .../ChatClient/IChatClient.cs | 2 +- .../ChatClient/StronglyTypedChatHub.cs | 2 +- .../Data/WeatherForecast.cs | 16 +-- .../Data/WeatherForecastService.cs | 30 ++-- .../Pages/Error.cshtml.cs | 36 ++--- src/SampleBlazorApplication/Program.cs | 2 +- 106 files changed, 393 insertions(+), 380 deletions(-) diff --git a/.editorconfig b/.editorconfig index 20e9dc9..ab32471 100644 --- a/.editorconfig +++ b/.editorconfig @@ -2,3 +2,7 @@ root = true [*.cs] indent_style = tab +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true diff --git a/src/Ninject.Web.AspNetCore.ComplianceTest/KeyedDependencyInjectionComplianceTests.cs b/src/Ninject.Web.AspNetCore.ComplianceTest/KeyedDependencyInjectionComplianceTests.cs index 0d98da0..cf9821a 100644 --- a/src/Ninject.Web.AspNetCore.ComplianceTest/KeyedDependencyInjectionComplianceTests.cs +++ b/src/Ninject.Web.AspNetCore.ComplianceTest/KeyedDependencyInjectionComplianceTests.cs @@ -1,41 +1,41 @@ -using System; -using Microsoft.Extensions.DependencyInjection; -using Ninject.Planning.Bindings.Resolvers; -using Xunit; - -namespace Ninject.Web.AspNetCore.ComplianceTest; - -/// -/// See https://github.com/dotnet/runtime/tree/main/src/libraries/Microsoft.Extensions.DependencyInjection.Specification.Tests/src - the dotnet/runtime -/// project which contains the dependency injection library code also contains a set of "compliance tests" that can be run against a potential alternative -/// implementation to check if it is compliant. This class is running the dedicated specification tests for KEYED services. -/// -public class KeyedDependencyInjectionComplianceTests : Microsoft.Extensions.DependencyInjection.Specification.KeyedDependencyInjectionSpecificationTests -{ - protected override IServiceProvider CreateServiceProvider(IServiceCollection collection) - { - var kernel = new AspNetCoreKernel(); - // remove autobinding as CreateServiceWithKeyedParameter e.g. tests that no autobinding happens. - kernel.Components.Remove(); - var factory = new NinjectServiceProviderFactory(kernel); - - return factory.CreateBuilder(collection).Build(); - } - -#pragma warning disable xUnit1024, xUnit1026 - - [Theory(Skip = "Wrong implementation of the test, should use Assert.Equal and not Assert.Same")] - [InlineData(true)] - [InlineData(false)] - public new void ResolveWithAnyKeyQuery_Constructor(bool anyKeyQueryBeforeSingletonQueries) - { - } - - [Theory(Skip = "Wrong implementation, should use Assert.Equal and not Assert.Same")] - [InlineData(true)] - [InlineData(false)] - public new void ResolveWithAnyKeyQuery_Constructor_Duplicates(bool anyKeyQueryBeforeSingletonQueries) - { - } -#pragma warning restore xUnit1024, xUnit1026 -} +using System; +using Microsoft.Extensions.DependencyInjection; +using Ninject.Planning.Bindings.Resolvers; +using Xunit; + +namespace Ninject.Web.AspNetCore.ComplianceTest; + +/// +/// See https://github.com/dotnet/runtime/tree/main/src/libraries/Microsoft.Extensions.DependencyInjection.Specification.Tests/src - the dotnet/runtime +/// project which contains the dependency injection library code also contains a set of "compliance tests" that can be run against a potential alternative +/// implementation to check if it is compliant. This class is running the dedicated specification tests for KEYED services. +/// +public class KeyedDependencyInjectionComplianceTests : Microsoft.Extensions.DependencyInjection.Specification.KeyedDependencyInjectionSpecificationTests +{ + protected override IServiceProvider CreateServiceProvider(IServiceCollection collection) + { + var kernel = new AspNetCoreKernel(); + // remove autobinding as CreateServiceWithKeyedParameter e.g. tests that no autobinding happens. + kernel.Components.Remove(); + var factory = new NinjectServiceProviderFactory(kernel); + + return factory.CreateBuilder(collection).Build(); + } + +#pragma warning disable xUnit1024, xUnit1026 + + [Theory(Skip = "Wrong implementation of the test, should use Assert.Equal and not Assert.Same")] + [InlineData(true)] + [InlineData(false)] + public new void ResolveWithAnyKeyQuery_Constructor(bool anyKeyQueryBeforeSingletonQueries) + { + } + + [Theory(Skip = "Wrong implementation, should use Assert.Equal and not Assert.Same")] + [InlineData(true)] + [InlineData(false)] + public new void ResolveWithAnyKeyQuery_Constructor_Duplicates(bool anyKeyQueryBeforeSingletonQueries) + { + } +#pragma warning restore xUnit1024, xUnit1026 +} diff --git a/src/Ninject.Web.AspNetCore.Httpsys/Hosting/AspNetCoreHostConfigurationExtensions.cs b/src/Ninject.Web.AspNetCore.Httpsys/Hosting/AspNetCoreHostConfigurationExtensions.cs index 09624fe..58d3b4f 100644 --- a/src/Ninject.Web.AspNetCore.Httpsys/Hosting/AspNetCoreHostConfigurationExtensions.cs +++ b/src/Ninject.Web.AspNetCore.Httpsys/Hosting/AspNetCoreHostConfigurationExtensions.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Server.HttpSys; using System; using System.Runtime.Versioning; diff --git a/src/Ninject.Web.AspNetCore.IIS/Hosting/AspNetCoreHostConfigurationExtensions.cs b/src/Ninject.Web.AspNetCore.IIS/Hosting/AspNetCoreHostConfigurationExtensions.cs index 1fd0971..c99bd11 100644 --- a/src/Ninject.Web.AspNetCore.IIS/Hosting/AspNetCoreHostConfigurationExtensions.cs +++ b/src/Ninject.Web.AspNetCore.IIS/Hosting/AspNetCoreHostConfigurationExtensions.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Hosting; namespace Ninject.Web.AspNetCore.Hosting { diff --git a/src/Ninject.Web.AspNetCore.Test/Fakes/FakeActivationCacheAccessor.cs b/src/Ninject.Web.AspNetCore.Test/Fakes/FakeActivationCacheAccessor.cs index 023aa1b..8774c34 100644 --- a/src/Ninject.Web.AspNetCore.Test/Fakes/FakeActivationCacheAccessor.cs +++ b/src/Ninject.Web.AspNetCore.Test/Fakes/FakeActivationCacheAccessor.cs @@ -1,4 +1,4 @@ -using Ninject.Activation.Caching; +using Ninject.Activation.Caching; using Ninject.Web.AspNetCore.Components; using System; using System.Collections.Generic; diff --git a/src/Ninject.Web.AspNetCore.Test/Fakes/IKeyedWeaponStorage.cs b/src/Ninject.Web.AspNetCore.Test/Fakes/IKeyedWeaponStorage.cs index 08c5bfd..b11da0b 100644 --- a/src/Ninject.Web.AspNetCore.Test/Fakes/IKeyedWeaponStorage.cs +++ b/src/Ninject.Web.AspNetCore.Test/Fakes/IKeyedWeaponStorage.cs @@ -1,9 +1,9 @@ namespace Ninject.Web.AspNetCore.Test.Fakes { -#if NET8_0_OR_GREATER +#if NET8_0_OR_GREATER public interface IKeyedWeaponStorage { IWeapon Weapon { get; } } -#endif -} \ No newline at end of file +#endif +} diff --git a/src/Ninject.Web.AspNetCore.Test/Fakes/IWarrior.cs b/src/Ninject.Web.AspNetCore.Test/Fakes/IWarrior.cs index 47b9b7d..a8c3029 100644 --- a/src/Ninject.Web.AspNetCore.Test/Fakes/IWarrior.cs +++ b/src/Ninject.Web.AspNetCore.Test/Fakes/IWarrior.cs @@ -1,4 +1,4 @@ -namespace Ninject.Web.AspNetCore.Test.Fakes +namespace Ninject.Web.AspNetCore.Test.Fakes { public interface IWarrior { diff --git a/src/Ninject.Web.AspNetCore.Test/Fakes/KeyedNinja.cs b/src/Ninject.Web.AspNetCore.Test/Fakes/KeyedNinja.cs index a520a6e..3effc88 100644 --- a/src/Ninject.Web.AspNetCore.Test/Fakes/KeyedNinja.cs +++ b/src/Ninject.Web.AspNetCore.Test/Fakes/KeyedNinja.cs @@ -5,7 +5,7 @@ namespace Ninject.Web.AspNetCore.Test.Fakes #if NET8_0_OR_GREATER public class KeyedNinja : IWarrior { - public object Key {get; private set;} + public object Key { get; private set; } public KeyedNinja([ServiceKey] object key) { @@ -15,4 +15,4 @@ public KeyedNinja([ServiceKey] object key) public string Name => nameof(KeyedNinja); } #endif -} \ No newline at end of file +} diff --git a/src/Ninject.Web.AspNetCore.Test/Fakes/KeyedWeaponStorage.cs b/src/Ninject.Web.AspNetCore.Test/Fakes/KeyedWeaponStorage.cs index 7665c2b..f727999 100644 --- a/src/Ninject.Web.AspNetCore.Test/Fakes/KeyedWeaponStorage.cs +++ b/src/Ninject.Web.AspNetCore.Test/Fakes/KeyedWeaponStorage.cs @@ -2,7 +2,7 @@ namespace Ninject.Web.AspNetCore.Test.Fakes { -#if NET8_0_OR_GREATER +#if NET8_0_OR_GREATER public class KeyedWeaponStorage : IKeyedWeaponStorage { public IWeapon Weapon { get; private set; } @@ -11,5 +11,5 @@ public KeyedWeaponStorage([FromKeyedServices("Lance")] IWeapon lance) Weapon = lance; } } -#endif -} \ No newline at end of file +#endif +} diff --git a/src/Ninject.Web.AspNetCore.Test/Fakes/Knight.cs b/src/Ninject.Web.AspNetCore.Test/Fakes/Knight.cs index 4147a42..7a3a902 100644 --- a/src/Ninject.Web.AspNetCore.Test/Fakes/Knight.cs +++ b/src/Ninject.Web.AspNetCore.Test/Fakes/Knight.cs @@ -1,4 +1,4 @@ -namespace Ninject.Web.AspNetCore.Test.Fakes +namespace Ninject.Web.AspNetCore.Test.Fakes { public class Knight : IWarrior { diff --git a/src/Ninject.Web.AspNetCore.Test/Fakes/Lance.cs b/src/Ninject.Web.AspNetCore.Test/Fakes/Lance.cs index 2468268..a3b1c4e 100644 --- a/src/Ninject.Web.AspNetCore.Test/Fakes/Lance.cs +++ b/src/Ninject.Web.AspNetCore.Test/Fakes/Lance.cs @@ -1,4 +1,4 @@ -namespace Ninject.Web.AspNetCore.Test.Fakes +namespace Ninject.Web.AspNetCore.Test.Fakes { public class Lance : IWeapon { diff --git a/src/Ninject.Web.AspNetCore.Test/Fakes/Longsword.cs b/src/Ninject.Web.AspNetCore.Test/Fakes/Longsword.cs index 772e838..2a33b36 100644 --- a/src/Ninject.Web.AspNetCore.Test/Fakes/Longsword.cs +++ b/src/Ninject.Web.AspNetCore.Test/Fakes/Longsword.cs @@ -1,4 +1,4 @@ -namespace Ninject.Web.AspNetCore.Test.Fakes +namespace Ninject.Web.AspNetCore.Test.Fakes { public class Longsword : IWeapon { diff --git a/src/Ninject.Web.AspNetCore.Test/Fakes/MobileInfantry.cs b/src/Ninject.Web.AspNetCore.Test/Fakes/MobileInfantry.cs index 0bb9cf2..9653e1c 100644 --- a/src/Ninject.Web.AspNetCore.Test/Fakes/MobileInfantry.cs +++ b/src/Ninject.Web.AspNetCore.Test/Fakes/MobileInfantry.cs @@ -1,4 +1,4 @@ -namespace Ninject.Web.AspNetCore.Test.Fakes +namespace Ninject.Web.AspNetCore.Test.Fakes { public class MobileInfantry : IWarrior { diff --git a/src/Ninject.Web.AspNetCore.Test/Fakes/MoritaAssaultRifle.cs b/src/Ninject.Web.AspNetCore.Test/Fakes/MoritaAssaultRifle.cs index efb3173..fd5bd44 100644 --- a/src/Ninject.Web.AspNetCore.Test/Fakes/MoritaAssaultRifle.cs +++ b/src/Ninject.Web.AspNetCore.Test/Fakes/MoritaAssaultRifle.cs @@ -1,4 +1,4 @@ -using System; +using System; namespace Ninject.Web.AspNetCore.Test.Fakes { diff --git a/src/Ninject.Web.AspNetCore.Test/Fakes/Ninja.cs b/src/Ninject.Web.AspNetCore.Test/Fakes/Ninja.cs index a15c55f..d15df55 100644 --- a/src/Ninject.Web.AspNetCore.Test/Fakes/Ninja.cs +++ b/src/Ninject.Web.AspNetCore.Test/Fakes/Ninja.cs @@ -1,4 +1,4 @@ -namespace Ninject.Web.AspNetCore.Test.Fakes +namespace Ninject.Web.AspNetCore.Test.Fakes { public class Ninja : IWarrior { diff --git a/src/Ninject.Web.AspNetCore.Test/Fakes/NinjaWithKeyedWeapon.cs b/src/Ninject.Web.AspNetCore.Test/Fakes/NinjaWithKeyedWeapon.cs index 1eb4e18..d6b4a8c 100644 --- a/src/Ninject.Web.AspNetCore.Test/Fakes/NinjaWithKeyedWeapon.cs +++ b/src/Ninject.Web.AspNetCore.Test/Fakes/NinjaWithKeyedWeapon.cs @@ -19,4 +19,4 @@ public NinjaWithKeyedWeapon([FromKeyedServices("Longsword")] IWeapon weapon, [Fr } #endif -} \ No newline at end of file +} diff --git a/src/Ninject.Web.AspNetCore.Test/Fakes/NotifiesWhenDisposed.cs b/src/Ninject.Web.AspNetCore.Test/Fakes/NotifiesWhenDisposed.cs index e927958..f13c8f0 100644 --- a/src/Ninject.Web.AspNetCore.Test/Fakes/NotifiesWhenDisposed.cs +++ b/src/Ninject.Web.AspNetCore.Test/Fakes/NotifiesWhenDisposed.cs @@ -1,4 +1,4 @@ -using Ninject.Infrastructure.Disposal; +using Ninject.Infrastructure.Disposal; namespace Ninject.Web.AspNetCore.Test.Fakes { diff --git a/src/Ninject.Web.AspNetCore.Test/Fakes/Samurai.cs b/src/Ninject.Web.AspNetCore.Test/Fakes/Samurai.cs index 3278dac..6622bf2 100644 --- a/src/Ninject.Web.AspNetCore.Test/Fakes/Samurai.cs +++ b/src/Ninject.Web.AspNetCore.Test/Fakes/Samurai.cs @@ -1,4 +1,4 @@ -namespace Ninject.Web.AspNetCore.Test.Fakes +namespace Ninject.Web.AspNetCore.Test.Fakes { public class Samurai : IWarrior { diff --git a/src/Ninject.Web.AspNetCore.Test/Fakes/TestObject.cs b/src/Ninject.Web.AspNetCore.Test/Fakes/TestObject.cs index 62854f2..be1c356 100644 --- a/src/Ninject.Web.AspNetCore.Test/Fakes/TestObject.cs +++ b/src/Ninject.Web.AspNetCore.Test/Fakes/TestObject.cs @@ -1,4 +1,4 @@ -namespace Ninject.Web.AspNetCore.Test.Fakes +namespace Ninject.Web.AspNetCore.Test.Fakes { public class TestObject { diff --git a/src/Ninject.Web.AspNetCore.Test/Regression/NinjectBugsRegressionTest.cs b/src/Ninject.Web.AspNetCore.Test/Regression/NinjectBugsRegressionTest.cs index 63a61ba..1f3b894 100644 --- a/src/Ninject.Web.AspNetCore.Test/Regression/NinjectBugsRegressionTest.cs +++ b/src/Ninject.Web.AspNetCore.Test/Regression/NinjectBugsRegressionTest.cs @@ -1,4 +1,4 @@ -using AwesomeAssertions; +using AwesomeAssertions; using Ninject.Web.AspNetCore.Test.Fakes; using Xunit; diff --git a/src/Ninject.Web.AspNetCore.Test/ServiceProviderReference/ServiceProviderReferenceTest.cs b/src/Ninject.Web.AspNetCore.Test/ServiceProviderReference/ServiceProviderReferenceTest.cs index 610dd61..dc3daeb 100644 --- a/src/Ninject.Web.AspNetCore.Test/ServiceProviderReference/ServiceProviderReferenceTest.cs +++ b/src/Ninject.Web.AspNetCore.Test/ServiceProviderReference/ServiceProviderReferenceTest.cs @@ -1,4 +1,4 @@ -using AwesomeAssertions; +using AwesomeAssertions; using Microsoft.Extensions.DependencyInjection; using Moq; using Ninject.Web.AspNetCore.Test.Fakes; @@ -16,7 +16,8 @@ public void ServiceProvider_ProvideServiceScopeFactory_HasNoEffect() { var scopeFactoryMock = new Mock(); - var provider = CreateServiceProvider(collection => { + var provider = CreateServiceProvider(collection => + { collection.AddSingleton(scopeFactoryMock.Object); }); @@ -26,7 +27,7 @@ public void ServiceProvider_ProvideServiceScopeFactory_HasNoEffect() // * ServiceProviderEngine.ServiceProviderEngine constructor // * ServiceProviderServiceExtensions.CreateScope var factory = provider.GetRequiredService(); - + factory.Should().NotBeNull().And.NotBe(scopeFactoryMock.Object); factory.GetType().Name.Should().Contain("ServiceProviderEngine"); } diff --git a/src/Ninject.Web.AspNetCore.Test/Unit/ActivationCacheTest.cs b/src/Ninject.Web.AspNetCore.Test/Unit/ActivationCacheTest.cs index 0007bea..077e7c6 100644 --- a/src/Ninject.Web.AspNetCore.Test/Unit/ActivationCacheTest.cs +++ b/src/Ninject.Web.AspNetCore.Test/Unit/ActivationCacheTest.cs @@ -1,4 +1,4 @@ -using AwesomeAssertions; +using AwesomeAssertions; using Ninject.Web.AspNetCore.Components; using Ninject.Web.AspNetCore.Test.Fakes; using System; @@ -114,4 +114,4 @@ public void Dispose() _testee?.Dispose(); } } -} \ No newline at end of file +} diff --git a/src/Ninject.Web.AspNetCore.Test/Unit/AspNetCoreApplicationPluginTest.cs b/src/Ninject.Web.AspNetCore.Test/Unit/AspNetCoreApplicationPluginTest.cs index 4402eb4..b6bac31 100644 --- a/src/Ninject.Web.AspNetCore.Test/Unit/AspNetCoreApplicationPluginTest.cs +++ b/src/Ninject.Web.AspNetCore.Test/Unit/AspNetCoreApplicationPluginTest.cs @@ -1,4 +1,4 @@ -using AwesomeAssertions; +using AwesomeAssertions; using Microsoft.Extensions.DependencyInjection; using Moq; using Ninject.Activation; @@ -13,7 +13,7 @@ namespace Ninject.Web.AspNetCore.Test.Unit { public class AspNetCoreApplicationPluginTest : TestKernelContext { - + [Fact] public void ComponentsOfKernel_ContainsApplicationPlugin() { @@ -29,7 +29,7 @@ public void GetRequestScope_WitnNewRequestScope_ResolvesToRequestScope() (var applicationPlugin, var context, _) = GetApplicationPluginContext(); using (var requestScope = new RequestScope()) - { + { var scope = applicationPlugin.GetRequestScope(context); scope.Should().NotBeNull().And.Be(requestScope); } @@ -39,7 +39,7 @@ public void GetRequestScope_WitnNewRequestScope_ResolvesToRequestScope() public void GetRequestScope_WithoutRequestScope_ThrowsException() { (var applicationPlugin, var context, _) = GetApplicationPluginContext(); - + Action action = () => applicationPlugin.GetRequestScope(context); action.Should().Throw(); } diff --git a/src/Ninject.Web.AspNetCore.Test/Unit/ControllerActivatorTest.cs b/src/Ninject.Web.AspNetCore.Test/Unit/ControllerActivatorTest.cs index c7f563e..354baf0 100644 --- a/src/Ninject.Web.AspNetCore.Test/Unit/ControllerActivatorTest.cs +++ b/src/Ninject.Web.AspNetCore.Test/Unit/ControllerActivatorTest.cs @@ -1,4 +1,4 @@ -using AwesomeAssertions; +using AwesomeAssertions; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Controllers; using Microsoft.Extensions.DependencyInjection; diff --git a/src/Ninject.Web.AspNetCore.Test/Unit/DisposalManagerConcurrencyTest.cs b/src/Ninject.Web.AspNetCore.Test/Unit/DisposalManagerConcurrencyTest.cs index d3c54b1..9ddbd3f 100644 --- a/src/Ninject.Web.AspNetCore.Test/Unit/DisposalManagerConcurrencyTest.cs +++ b/src/Ninject.Web.AspNetCore.Test/Unit/DisposalManagerConcurrencyTest.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Globalization; using AwesomeAssertions; using Ninject.Web.AspNetCore.Components; @@ -23,7 +23,8 @@ public async Task CreateArea_FromDifferentConcurrentThreads_ShouldCreateSeparate IDisposalCollectorArea area = null; barrier.SignalAndWait(); - lock (disposalManager) { + lock (disposalManager) + { // make sure the two tasks are creating the area one after the other area = disposalManager.CreateArea(); } diff --git a/src/Ninject.Web.AspNetCore.Test/Unit/DuplicateDescriptorTest.cs b/src/Ninject.Web.AspNetCore.Test/Unit/DuplicateDescriptorTest.cs index cedbe1d..be86d23 100644 --- a/src/Ninject.Web.AspNetCore.Test/Unit/DuplicateDescriptorTest.cs +++ b/src/Ninject.Web.AspNetCore.Test/Unit/DuplicateDescriptorTest.cs @@ -1,4 +1,4 @@ -using AwesomeAssertions; +using AwesomeAssertions; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using Ninject.Web.AspNetCore.Test.Fakes; diff --git a/src/Ninject.Web.AspNetCore.Test/Unit/GenericConstraintValidtorTest.cs b/src/Ninject.Web.AspNetCore.Test/Unit/GenericConstraintValidtorTest.cs index 697241d..b8f352d 100644 --- a/src/Ninject.Web.AspNetCore.Test/Unit/GenericConstraintValidtorTest.cs +++ b/src/Ninject.Web.AspNetCore.Test/Unit/GenericConstraintValidtorTest.cs @@ -1,4 +1,4 @@ -using AwesomeAssertions; +using AwesomeAssertions; using Ninject.Web.AspNetCore.Components; using System; using System.Collections.Generic; diff --git a/src/Ninject.Web.AspNetCore.Test/Unit/IndexedBindingPrecedenceComparerTest.cs b/src/Ninject.Web.AspNetCore.Test/Unit/IndexedBindingPrecedenceComparerTest.cs index 76e1081..bf2da0a 100644 --- a/src/Ninject.Web.AspNetCore.Test/Unit/IndexedBindingPrecedenceComparerTest.cs +++ b/src/Ninject.Web.AspNetCore.Test/Unit/IndexedBindingPrecedenceComparerTest.cs @@ -1,4 +1,4 @@ -using AwesomeAssertions; +using AwesomeAssertions; using Ninject.Activation; using Ninject.Parameters; using Ninject.Planning.Bindings; diff --git a/src/Ninject.Web.AspNetCore.Test/Unit/PopulateFromServiceCollectionTest.cs b/src/Ninject.Web.AspNetCore.Test/Unit/PopulateFromServiceCollectionTest.cs index c0e5e81..f67d254 100644 --- a/src/Ninject.Web.AspNetCore.Test/Unit/PopulateFromServiceCollectionTest.cs +++ b/src/Ninject.Web.AspNetCore.Test/Unit/PopulateFromServiceCollectionTest.cs @@ -1,4 +1,4 @@ -using AwesomeAssertions; +using AwesomeAssertions; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using Ninject.Web.AspNetCore.Test.Fakes; @@ -10,7 +10,7 @@ namespace Ninject.Web.AspNetCore.Test.Unit { public class PopulateFromServiceCollectionTest : TestKernelContext { - + [Fact] public void InstancesAreConvertedToConstants() { @@ -47,7 +47,7 @@ public void TransientRegistrationIsConvertedToTransient() var first = kernel.Get(); var second = kernel.Get(); first.Should().NotBeSameAs(second).And.BeOfType(typeof(Samurai)); - } + } [Fact] public void ScopedRegistrationIsConvertedToInRequestScope() diff --git a/src/Ninject.Web.AspNetCore.Test/Unit/RequestScopeDisposalTest.cs b/src/Ninject.Web.AspNetCore.Test/Unit/RequestScopeDisposalTest.cs index a77c2f1..a0aecce 100644 --- a/src/Ninject.Web.AspNetCore.Test/Unit/RequestScopeDisposalTest.cs +++ b/src/Ninject.Web.AspNetCore.Test/Unit/RequestScopeDisposalTest.cs @@ -1,4 +1,4 @@ -using AwesomeAssertions; +using AwesomeAssertions; using Ninject.Parameters; using Ninject.Web.AspNetCore.Test.Fakes; using System.Linq; @@ -68,7 +68,7 @@ public void DisposalDoesNotCascadeThroughScopesThatAreNotINotifyWhenDisposed() var kernel = new StandardKernel(new NinjectSettings() { LoadExtensions = false }); kernel.Bind().To().InScope(ctx => RequestScope.Current).WithParameter(new Parameter("scope", scope, true)); kernel.Bind().To().InScope(ctx => ((Parameter)ctx.Parameters.First()).ValueCallback(ctx, null)); - + using (new RequestScope()) { rico = (MobileInfantry)kernel.Get(); diff --git a/src/Ninject.Web.AspNetCore.Test/Unit/RequestScopeMiddlewareTest.cs b/src/Ninject.Web.AspNetCore.Test/Unit/RequestScopeMiddlewareTest.cs index 135baec..3eb21ed 100644 --- a/src/Ninject.Web.AspNetCore.Test/Unit/RequestScopeMiddlewareTest.cs +++ b/src/Ninject.Web.AspNetCore.Test/Unit/RequestScopeMiddlewareTest.cs @@ -1,4 +1,4 @@ -using AwesomeAssertions; +using AwesomeAssertions; using Microsoft.AspNetCore.Http; using Moq; using Ninject.Web.AspNetCore.Hosting; diff --git a/src/Ninject.Web.AspNetCore.Test/Unit/ServiceProviderKeyedTest.cs b/src/Ninject.Web.AspNetCore.Test/Unit/ServiceProviderKeyedTest.cs index da93fa7..725c8fc 100644 --- a/src/Ninject.Web.AspNetCore.Test/Unit/ServiceProviderKeyedTest.cs +++ b/src/Ninject.Web.AspNetCore.Test/Unit/ServiceProviderKeyedTest.cs @@ -1,4 +1,4 @@ -using AwesomeAssertions; +using AwesomeAssertions; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using Ninject.Web.AspNetCore.Test.Fakes; @@ -19,7 +19,7 @@ public class ServiceProviderKeyedTest public void OptionalExising_ServiceKeyNullResolvedAsUnkeyed() { var collection = new ServiceCollection(); - collection.Add(new ServiceDescriptor(typeof(IWarrior),null, typeof(Samurai), ServiceLifetime.Transient)); + collection.Add(new ServiceDescriptor(typeof(IWarrior), null, typeof(Samurai), ServiceLifetime.Transient)); var kernel = CreateTestKernel(collection); var provider = CreateServiceProvider(kernel); @@ -60,9 +60,9 @@ public void OptionalExisingWithKeyedChildren_SingleServiceResolved() public void OptionalKeyedServiceCollectionExisting_CorrectServiceResolved() { var collection = new ServiceCollection(); - collection.Add(new ServiceDescriptor(typeof(IWarrior),"Samurai", typeof(Samurai), ServiceLifetime.Transient)); + collection.Add(new ServiceDescriptor(typeof(IWarrior), "Samurai", typeof(Samurai), ServiceLifetime.Transient)); collection.Add(new ServiceDescriptor(typeof(IWarrior), "Ninja1", new Ninja("test"))); - collection.Add(new ServiceDescriptor(typeof(IWarrior),"Ninja2", + collection.Add(new ServiceDescriptor(typeof(IWarrior), "Ninja2", (provider, key) => new Ninja("test:" + key.ToString()), ServiceLifetime.Transient)); var kernel = CreateTestKernel(collection); var provider = CreateServiceProvider(kernel); @@ -104,7 +104,7 @@ public void OptionalKeyedNonExisting_SingleServiceResolvedToNull() public void OptionalExistingMultipleKeydServices_ResolvedQueriedAsList() { var kernel = CreateTestKernel(); - kernel.Bind().To().WithMetadata(nameof(ServiceKey), new ServiceKey("Warrior"));; + kernel.Bind().To().WithMetadata(nameof(ServiceKey), new ServiceKey("Warrior")); kernel.Bind().ToConstant(new Ninja("test")).WithMetadata(nameof(ServiceKey), new ServiceKey("Warrior")); var provider = CreateServiceProvider(kernel); @@ -121,7 +121,7 @@ public void OptionalExistingMultipleKeydServices_ResolvedQueriedAsList() public void OptionalExistingMultipleKeydServices_NotResolvedAsListNonKeyed() { var kernel = CreateTestKernel(); - kernel.Bind().To().WithMetadata(nameof(ServiceKey), new ServiceKey("Samurai"));; + kernel.Bind().To().WithMetadata(nameof(ServiceKey), new ServiceKey("Samurai")); kernel.Bind().ToConstant(new Ninja("test")).WithMetadata(nameof(ServiceKey), new ServiceKey("Ninja")); var provider = CreateServiceProvider(kernel); @@ -136,7 +136,7 @@ public void OptionalExistingMultipleKeydServices_NotResolvedAsListNonKeyed() public void ExistingMultipleServices_ResolvesNonKeyedToNull() { var kernel = CreateTestKernel(); - kernel.Bind().To().WithMetadata(nameof(ServiceKey), new ServiceKey("Samurai"));; + kernel.Bind().To().WithMetadata(nameof(ServiceKey), new ServiceKey("Samurai")); kernel.Bind().ToConstant(new Ninja("test")).WithMetadata(nameof(ServiceKey), new ServiceKey("Ninja")); var provider = CreateServiceProvider(kernel); @@ -147,7 +147,7 @@ public void ExistingMultipleServices_ResolvesNonKeyedToNull() public void RequiredKeyedServiceCollectionExisting_CorrectServiceResolved() { var collection = new ServiceCollection(); - collection.Add(new ServiceDescriptor(typeof(IWarrior),"Samurai", typeof(Samurai), ServiceLifetime.Transient)); + collection.Add(new ServiceDescriptor(typeof(IWarrior), "Samurai", typeof(Samurai), ServiceLifetime.Transient)); collection.Add(new ServiceDescriptor(typeof(IWarrior), "Ninja", new Ninja("test"))); var kernel = CreateTestKernel(collection); var provider = CreateServiceProvider(kernel); @@ -183,7 +183,7 @@ public void RequiredKeyedNonExisting_SingleServiceResolvedToException() public void RequiredExistingMultipleKeydServices_ResolvedQueriedAsList() { var kernel = CreateTestKernel(); - kernel.Bind().To().WithMetadata(nameof(ServiceKey), new ServiceKey("Warrior"));; + kernel.Bind().To().WithMetadata(nameof(ServiceKey), new ServiceKey("Warrior")); kernel.Bind().ToConstant(new Ninja("test")).WithMetadata(nameof(ServiceKey), new ServiceKey("Warrior")); var provider = CreateServiceProvider(kernel); @@ -200,7 +200,7 @@ public void RequiredExistingMultipleKeydServices_ResolvedQueriedAsList() public void RequiredExistingMultipleKeydServices_NotResolvedAsListNonKeyed() { var kernel = CreateTestKernel(); - kernel.Bind().To().WithMetadata(nameof(ServiceKey), new ServiceKey("Samurai"));; + kernel.Bind().To().WithMetadata(nameof(ServiceKey), new ServiceKey("Samurai")); kernel.Bind().ToConstant(new Ninja("test")).WithMetadata(nameof(ServiceKey), new ServiceKey("Ninja")); var provider = CreateServiceProvider(kernel); @@ -215,7 +215,7 @@ public void RequiredExistingMultipleKeydServices_NotResolvedAsListNonKeyed() public void ExistingMultipleServices_ResolvesNonKeyedToException() { var kernel = CreateTestKernel(); - kernel.Bind().To().WithMetadata(nameof(ServiceKey), new ServiceKey("Samurai"));; + kernel.Bind().To().WithMetadata(nameof(ServiceKey), new ServiceKey("Samurai")); kernel.Bind().ToConstant(new Ninja("test")).WithMetadata(nameof(ServiceKey), new ServiceKey("Ninja")); var provider = CreateServiceProvider(kernel); diff --git a/src/Ninject.Web.AspNetCore.Test/Unit/ServiceProviderResolutionRootTest.cs b/src/Ninject.Web.AspNetCore.Test/Unit/ServiceProviderResolutionRootTest.cs index 81b6c67..dc2c7d4 100644 --- a/src/Ninject.Web.AspNetCore.Test/Unit/ServiceProviderResolutionRootTest.cs +++ b/src/Ninject.Web.AspNetCore.Test/Unit/ServiceProviderResolutionRootTest.cs @@ -1,4 +1,4 @@ -using AwesomeAssertions; +using AwesomeAssertions; using Moq; using Ninject.Parameters; using Ninject.Syntax; diff --git a/src/Ninject.Web.AspNetCore.Test/Unit/ServiceProviderScopeTest.cs b/src/Ninject.Web.AspNetCore.Test/Unit/ServiceProviderScopeTest.cs index 20f4251..cf86a1d 100644 --- a/src/Ninject.Web.AspNetCore.Test/Unit/ServiceProviderScopeTest.cs +++ b/src/Ninject.Web.AspNetCore.Test/Unit/ServiceProviderScopeTest.cs @@ -1,67 +1,67 @@ -using System; -using AwesomeAssertions; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.DependencyInjection.Extensions; -using Ninject.Web.AspNetCore.Test.Fakes; -using Xunit; - -namespace Ninject.Web.AspNetCore.Test.Unit; - -public class ServiceProviderScopeTest : TestKernelContext -{ - [Theory] - [MemberData(nameof(ServiceConfigurations))] - public void ScopedServices_ResolvedInScope_ShouldBeDifferent(ServiceCollection serviceCollection) - { - var kernel = CreateKernel(serviceCollection); - var provider = kernel.Get(); - - var rootKnight = provider.GetRequiredService(); - - using (var scope = provider.CreateScope()) - { - // The IWeapon instantiated inside of this scope should also be tied to this scope when created through - // a ServiceDescriptor.ImplementationFactory - var levelOneKnight = scope.ServiceProvider.GetRequiredService(); - AssertNotSameKnightAndWeapon(levelOneKnight, rootKnight); - - var levelOneKnight2 = scope.ServiceProvider.GetRequiredService(); - AssertSameKnightAndWeapon(levelOneKnight2, levelOneKnight); - } - - var rootKnight2 = provider.GetRequiredService(); - AssertSameKnightAndWeapon(rootKnight2, rootKnight); - } - - private void AssertSameKnightAndWeapon(Knight value, Knight expected) - { - value.Should().BeSameAs(expected); - value.Weapon.Should().BeSameAs(expected.Weapon); - } - - private void AssertNotSameKnightAndWeapon(Knight value, Knight expected) - { - value.Should().NotBeSameAs(expected); - value.Weapon.Should().NotBeSameAs(expected.Weapon); - } - - public static TheoryData ServiceConfigurations => new TheoryData - { - { - new ServiceCollection() { - new ServiceDescriptor(typeof(Knight), typeof(Knight), ServiceLifetime.Scoped), - new ServiceDescriptor(typeof(IWeapon), typeof(Longsword), ServiceLifetime.Scoped) - } - }, - { - new ServiceCollection() { - new ServiceDescriptor(typeof(Knight), typeof(Knight), ServiceLifetime.Scoped), - new ServiceDescriptor(typeof(Longsword), typeof(Longsword), ServiceLifetime.Scoped), - // See https://github.com/lord-executor/Ninject.Web.AspNetCore/issues/12 - // The difference here is the use of a descriptor with an implementation factory where the implementation - // must make sure that the correct _scoped_ IServiceProvider instance is passed to the factory - new ServiceDescriptor(typeof(IWeapon),serviceProvider => serviceProvider.GetService(), ServiceLifetime.Scoped) - } - }, - }; -} \ No newline at end of file +using System; +using AwesomeAssertions; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection.Extensions; +using Ninject.Web.AspNetCore.Test.Fakes; +using Xunit; + +namespace Ninject.Web.AspNetCore.Test.Unit; + +public class ServiceProviderScopeTest : TestKernelContext +{ + [Theory] + [MemberData(nameof(ServiceConfigurations))] + public void ScopedServices_ResolvedInScope_ShouldBeDifferent(ServiceCollection serviceCollection) + { + var kernel = CreateKernel(serviceCollection); + var provider = kernel.Get(); + + var rootKnight = provider.GetRequiredService(); + + using (var scope = provider.CreateScope()) + { + // The IWeapon instantiated inside of this scope should also be tied to this scope when created through + // a ServiceDescriptor.ImplementationFactory + var levelOneKnight = scope.ServiceProvider.GetRequiredService(); + AssertNotSameKnightAndWeapon(levelOneKnight, rootKnight); + + var levelOneKnight2 = scope.ServiceProvider.GetRequiredService(); + AssertSameKnightAndWeapon(levelOneKnight2, levelOneKnight); + } + + var rootKnight2 = provider.GetRequiredService(); + AssertSameKnightAndWeapon(rootKnight2, rootKnight); + } + + private void AssertSameKnightAndWeapon(Knight value, Knight expected) + { + value.Should().BeSameAs(expected); + value.Weapon.Should().BeSameAs(expected.Weapon); + } + + private void AssertNotSameKnightAndWeapon(Knight value, Knight expected) + { + value.Should().NotBeSameAs(expected); + value.Weapon.Should().NotBeSameAs(expected.Weapon); + } + + public static TheoryData ServiceConfigurations => new TheoryData + { + { + new ServiceCollection() { + new ServiceDescriptor(typeof(Knight), typeof(Knight), ServiceLifetime.Scoped), + new ServiceDescriptor(typeof(IWeapon), typeof(Longsword), ServiceLifetime.Scoped) + } + }, + { + new ServiceCollection() { + new ServiceDescriptor(typeof(Knight), typeof(Knight), ServiceLifetime.Scoped), + new ServiceDescriptor(typeof(Longsword), typeof(Longsword), ServiceLifetime.Scoped), + // See https://github.com/lord-executor/Ninject.Web.AspNetCore/issues/12 + // The difference here is the use of a descriptor with an implementation factory where the implementation + // must make sure that the correct _scoped_ IServiceProvider instance is passed to the factory + new ServiceDescriptor(typeof(IWeapon),serviceProvider => serviceProvider.GetService(), ServiceLifetime.Scoped) + } + }, + }; +} diff --git a/src/Ninject.Web.AspNetCore.Test/Unit/ServiceProviderTest.cs b/src/Ninject.Web.AspNetCore.Test/Unit/ServiceProviderTest.cs index e7b66fa..01d155a 100644 --- a/src/Ninject.Web.AspNetCore.Test/Unit/ServiceProviderTest.cs +++ b/src/Ninject.Web.AspNetCore.Test/Unit/ServiceProviderTest.cs @@ -1,4 +1,4 @@ -using AwesomeAssertions; +using AwesomeAssertions; using Microsoft.Extensions.DependencyInjection; using Ninject.Web.AspNetCore.Test.Fakes; using System; @@ -10,7 +10,7 @@ namespace Ninject.Web.AspNetCore.Test.Unit { public class ServiceProviderTest { - + [Fact] public void ServiceProvider_CreatedSuccessfully() { @@ -18,9 +18,9 @@ public void ServiceProvider_CreatedSuccessfully() NinjectServiceProviderBuilder builder = CreateServiceProviderBuilder(kernel); var provider = builder.Build(); - + provider.Should().NotBeNull().And.BeOfType(typeof(NinjectServiceProvider)); - } + } [Fact] public void OptionalExisting_SingleServiceResolved() @@ -28,7 +28,7 @@ public void OptionalExisting_SingleServiceResolved() var kernel = CreateTestKernel(); kernel.Bind().To(); var provider = CreateServiceProvider(kernel); - + provider.GetService(typeof(IWarrior)).Should().NotBeNull().And.BeOfType(typeof(Samurai)); } @@ -37,7 +37,7 @@ public void OptionalNonExisting_SingleServiceResolvedToNull() { var kernel = CreateTestKernel(); var provider = CreateServiceProvider(kernel); - + provider.GetService(typeof(IWarrior)).Should().BeNull(); } @@ -48,9 +48,9 @@ public void OptionalExistingMultipleServices_ResolvedQueriedAsList() kernel.Bind().To(); kernel.Bind().ToConstant(new Ninja("test")); var provider = CreateServiceProvider(kernel); - + var result = provider.GetService(typeof(IList)) as IEnumerable; - + result.Should().NotBeNull(); var resultList = result.ToList(); resultList.Should().HaveCount(2); diff --git a/src/Ninject.Web.AspNetCore.Test/Unit/TestKernelContext.cs b/src/Ninject.Web.AspNetCore.Test/Unit/TestKernelContext.cs index 0a1e320..5fcec3e 100644 --- a/src/Ninject.Web.AspNetCore.Test/Unit/TestKernelContext.cs +++ b/src/Ninject.Web.AspNetCore.Test/Unit/TestKernelContext.cs @@ -1,4 +1,4 @@ -using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; using Ninject.Web.AspNetCore.Hosting; using System; diff --git a/src/Ninject.Web.AspNetCore/AspNetCoreApplicationPlugin.cs b/src/Ninject.Web.AspNetCore/AspNetCoreApplicationPlugin.cs index 6d56c45..4330ae3 100644 --- a/src/Ninject.Web.AspNetCore/AspNetCoreApplicationPlugin.cs +++ b/src/Ninject.Web.AspNetCore/AspNetCoreApplicationPlugin.cs @@ -1,4 +1,4 @@ -using Ninject.Activation; +using Ninject.Activation; using Ninject.Components; using Ninject.Web.Common; using System.Linq; diff --git a/src/Ninject.Web.AspNetCore/AspNetCoreKernel.cs b/src/Ninject.Web.AspNetCore/AspNetCoreKernel.cs index 8a2e056..d6f2e24 100644 --- a/src/Ninject.Web.AspNetCore/AspNetCoreKernel.cs +++ b/src/Ninject.Web.AspNetCore/AspNetCoreKernel.cs @@ -1,4 +1,4 @@ -using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; using Ninject.Activation; using Ninject.Activation.Caching; using Ninject.Activation.Strategies; @@ -34,7 +34,8 @@ public AspNetCoreKernel(INinjectSettings settings, params INinjectModule[] modul protected override Func SatifiesRequest(IRequest request) { - return binding => { + return binding => + { var latest = true; if (request.IsUnique) { diff --git a/src/Ninject.Web.AspNetCore/AspNetCoreModule.cs b/src/Ninject.Web.AspNetCore/AspNetCoreModule.cs index d4da0d5..eabbe9f 100644 --- a/src/Ninject.Web.AspNetCore/AspNetCoreModule.cs +++ b/src/Ninject.Web.AspNetCore/AspNetCoreModule.cs @@ -1,4 +1,4 @@ -using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; using Ninject.Modules; using Ninject.Web.AspNetCore.Hosting; using Ninject.Web.Common; diff --git a/src/Ninject.Web.AspNetCore/BindingIndex.cs b/src/Ninject.Web.AspNetCore/BindingIndex.cs index 5f8e1b3..583ca18 100644 --- a/src/Ninject.Web.AspNetCore/BindingIndex.cs +++ b/src/Ninject.Web.AspNetCore/BindingIndex.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using Microsoft.Extensions.DependencyInjection; @@ -54,7 +54,7 @@ public class Item public int TotalIndex { get; } public int TypeIndex { get; } public object IndexKey { get; } - + public int Precedence => _root.Count - TotalIndex; public Item(BindingIndex root, Type serviceType, object indexKey, int totalIndex, int typeIndex) @@ -65,7 +65,7 @@ public Item(BindingIndex root, Type serviceType, object indexKey, int totalIndex TypeIndex = typeIndex; IndexKey = indexKey; } - + public bool IsLatest => _root.IsLatest(_serviceType, IndexKey, this); } diff --git a/src/Ninject.Web.AspNetCore/Components/ActivationEntry.cs b/src/Ninject.Web.AspNetCore/Components/ActivationEntry.cs index 250da01..610106b 100644 --- a/src/Ninject.Web.AspNetCore/Components/ActivationEntry.cs +++ b/src/Ninject.Web.AspNetCore/Components/ActivationEntry.cs @@ -1,4 +1,4 @@ -using Ninject.Infrastructure; +using Ninject.Infrastructure; using System.Threading; namespace Ninject.Web.AspNetCore.Components diff --git a/src/Ninject.Web.AspNetCore/Components/ConstrainedGenericBindingResolver.cs b/src/Ninject.Web.AspNetCore/Components/ConstrainedGenericBindingResolver.cs index 98afef9..fd925a0 100644 --- a/src/Ninject.Web.AspNetCore/Components/ConstrainedGenericBindingResolver.cs +++ b/src/Ninject.Web.AspNetCore/Components/ConstrainedGenericBindingResolver.cs @@ -1,4 +1,4 @@ -using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; using Ninject.Components; using Ninject.Infrastructure; using Ninject.Planning.Bindings; @@ -26,7 +26,8 @@ public IEnumerable Resolve(Multimap bindings, Type ser // We don't need to do any caching here since the resolved bindings are automatically placed in the binding cache of Ninject so // that the next request for the same service type doesn't need to resolve this again. - return bindings[service.GetGenericTypeDefinition()].Where(binding => { + return bindings[service.GetGenericTypeDefinition()].Where(binding => + { // If the binding has a ServiceDescriptor in its metadata, then we if (binding.Target == BindingTarget.Type && binding.Metadata.Has(nameof(IDescriptorAdapter))) { diff --git a/src/Ninject.Web.AspNetCore/Components/ConstructorReflectionStrategyWithKeyedSupport.cs b/src/Ninject.Web.AspNetCore/Components/ConstructorReflectionStrategyWithKeyedSupport.cs index 85d0c45..55d0704 100644 --- a/src/Ninject.Web.AspNetCore/Components/ConstructorReflectionStrategyWithKeyedSupport.cs +++ b/src/Ninject.Web.AspNetCore/Components/ConstructorReflectionStrategyWithKeyedSupport.cs @@ -19,51 +19,51 @@ public class ConstructorReflectionStrategyWithKeyedSupport : NinjectComponent, IPlanningStrategy { /// - /// Initializes a new instance of the class. - /// - /// The selector component. - /// The injector factory component. - public ConstructorReflectionStrategyWithKeyedSupport(ISelector selector, IInjectorFactory injectorFactory) - { - Selector = selector; - InjectorFactory = injectorFactory; - } + /// Initializes a new instance of the class. + /// + /// The selector component. + /// The injector factory component. + public ConstructorReflectionStrategyWithKeyedSupport(ISelector selector, IInjectorFactory injectorFactory) + { + Selector = selector; + InjectorFactory = injectorFactory; + } - /// - /// Gets the selector component. - /// - public ISelector Selector { get; } + /// + /// Gets the selector component. + /// + public ISelector Selector { get; } - /// - /// Gets or sets the injector factory component. - /// - public IInjectorFactory InjectorFactory { get; } + /// + /// Gets or sets the injector factory component. + /// + public IInjectorFactory InjectorFactory { get; } - /// - /// Adds a to the plan for the constructor - /// that should be injected. - /// - /// The plan that is being generated. - public void Execute(IPlan plan) - { - var constructors = Selector.SelectConstructorsForInjection(plan.Type); - if (constructors == null) - { - return; - } + /// + /// Adds a to the plan for the constructor + /// that should be injected. + /// + /// The plan that is being generated. + public void Execute(IPlan plan) + { + var constructors = Selector.SelectConstructorsForInjection(plan.Type); + if (constructors == null) + { + return; + } - foreach (ConstructorInfo constructor in constructors) - { - var hasInjectAttribute = constructor.HasAttribute(Settings!.InjectAttribute); - var hasObsoleteAttribute = constructor.HasAttribute(); - var directive = new ConstructorInjectionDirectiveWithKeyedSupport(constructor, InjectorFactory.Create(constructor)) - { - HasInjectAttribute = hasInjectAttribute, - HasObsoleteAttribute = hasObsoleteAttribute, - }; + foreach (ConstructorInfo constructor in constructors) + { + var hasInjectAttribute = constructor.HasAttribute(Settings!.InjectAttribute); + var hasObsoleteAttribute = constructor.HasAttribute(); + var directive = new ConstructorInjectionDirectiveWithKeyedSupport(constructor, InjectorFactory.Create(constructor)) + { + HasInjectAttribute = hasInjectAttribute, + HasObsoleteAttribute = hasObsoleteAttribute, + }; - plan.Add(directive); - } - } + plan.Add(directive); + } + } } -} \ No newline at end of file +} diff --git a/src/Ninject.Web.AspNetCore/Components/DisposalManager.cs b/src/Ninject.Web.AspNetCore/Components/DisposalManager.cs index 97be70e..32a2806 100644 --- a/src/Ninject.Web.AspNetCore/Components/DisposalManager.cs +++ b/src/Ninject.Web.AspNetCore/Components/DisposalManager.cs @@ -1,4 +1,4 @@ -using Ninject.Activation; +using Ninject.Activation; using Ninject.Activation.Caching; using Ninject.Components; using Ninject.Infrastructure; @@ -82,7 +82,7 @@ public OrderedAggregateDisposalArea(DisposalManager manager) } public void Dispose() -{ + { if (_disposals == null || _disposals.Count == 0) { return; diff --git a/src/Ninject.Web.AspNetCore/Components/IActivationCacheAccessor.cs b/src/Ninject.Web.AspNetCore/Components/IActivationCacheAccessor.cs index 4555c28..b977338 100644 --- a/src/Ninject.Web.AspNetCore/Components/IActivationCacheAccessor.cs +++ b/src/Ninject.Web.AspNetCore/Components/IActivationCacheAccessor.cs @@ -1,4 +1,4 @@ -using Ninject.Infrastructure; +using Ninject.Infrastructure; using System.Collections.Generic; namespace Ninject.Web.AspNetCore.Components diff --git a/src/Ninject.Web.AspNetCore/Components/IDisposalManager.cs b/src/Ninject.Web.AspNetCore/Components/IDisposalManager.cs index 5ab4afd..42335bb 100644 --- a/src/Ninject.Web.AspNetCore/Components/IDisposalManager.cs +++ b/src/Ninject.Web.AspNetCore/Components/IDisposalManager.cs @@ -1,4 +1,4 @@ -using Ninject.Activation; +using Ninject.Activation; using Ninject.Components; using System; diff --git a/src/Ninject.Web.AspNetCore/Components/IndexedBindingPrecedenceComparer.cs b/src/Ninject.Web.AspNetCore/Components/IndexedBindingPrecedenceComparer.cs index 4a6981c..2b9505c 100644 --- a/src/Ninject.Web.AspNetCore/Components/IndexedBindingPrecedenceComparer.cs +++ b/src/Ninject.Web.AspNetCore/Components/IndexedBindingPrecedenceComparer.cs @@ -1,4 +1,4 @@ -using Ninject.Components; +using Ninject.Components; using Ninject.Planning.Bindings; using System; using System.Collections.Generic; diff --git a/src/Ninject.Web.AspNetCore/Components/OrderedDisposalStrategy.cs b/src/Ninject.Web.AspNetCore/Components/OrderedDisposalStrategy.cs index 86b4869..41153f6 100644 --- a/src/Ninject.Web.AspNetCore/Components/OrderedDisposalStrategy.cs +++ b/src/Ninject.Web.AspNetCore/Components/OrderedDisposalStrategy.cs @@ -1,4 +1,4 @@ -using Ninject.Activation; +using Ninject.Activation; using Ninject.Activation.Strategies; using Ninject.Components; diff --git a/src/Ninject.Web.AspNetCore/Components/WeakTableActivationCache.cs b/src/Ninject.Web.AspNetCore/Components/WeakTableActivationCache.cs index 95c416c..34a41c4 100644 --- a/src/Ninject.Web.AspNetCore/Components/WeakTableActivationCache.cs +++ b/src/Ninject.Web.AspNetCore/Components/WeakTableActivationCache.cs @@ -1,4 +1,4 @@ -using Ninject.Activation.Caching; +using Ninject.Activation.Caching; using Ninject.Components; using System.Collections.Generic; using System.Linq; @@ -120,4 +120,4 @@ public IEnumerable GetAllEntries() return _trackedInstances.Select(kvp => kvp.Value); } } -} \ No newline at end of file +} diff --git a/src/Ninject.Web.AspNetCore/ContextExtensions.cs b/src/Ninject.Web.AspNetCore/ContextExtensions.cs index 1dbb039..75b1e7d 100644 --- a/src/Ninject.Web.AspNetCore/ContextExtensions.cs +++ b/src/Ninject.Web.AspNetCore/ContextExtensions.cs @@ -1,21 +1,21 @@ -using System.Linq; -using Ninject.Activation; - -namespace Ninject.Web.AspNetCore -{ - /// - /// Extension methods on to simplify dealing with the - /// - public static class ContextExtensions - { - /// - /// Gets the from the context parameters. - /// - /// The resolution context from which to retrieve the scope parameter - /// The scope from which the request originated or null if there is none - public static ServiceProviderScopeParameter GetServiceProviderScopeParameter(this IContext context) - { - return context.Parameters.OfType().SingleOrDefault(); - } - } -} \ No newline at end of file +using System.Linq; +using Ninject.Activation; + +namespace Ninject.Web.AspNetCore +{ + /// + /// Extension methods on to simplify dealing with the + /// + public static class ContextExtensions + { + /// + /// Gets the from the context parameters. + /// + /// The resolution context from which to retrieve the scope parameter + /// The scope from which the request originated or null if there is none + public static ServiceProviderScopeParameter GetServiceProviderScopeParameter(this IContext context) + { + return context.Parameters.OfType().SingleOrDefault(); + } + } +} diff --git a/src/Ninject.Web.AspNetCore/ControllerActivationAdapter.cs b/src/Ninject.Web.AspNetCore/ControllerActivationAdapter.cs index 3958a0d..d996efa 100644 --- a/src/Ninject.Web.AspNetCore/ControllerActivationAdapter.cs +++ b/src/Ninject.Web.AspNetCore/ControllerActivationAdapter.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.Mvc.Controllers; +using Microsoft.AspNetCore.Mvc.Controllers; using Microsoft.Extensions.DependencyInjection; using Ninject.Web.AspNetCore.Hosting; @@ -16,7 +16,7 @@ public ControllerActivationAdapter(AspNetCoreHostConfiguration configuration) public void AdaptAfterPopulate(IKernel kernel) { var controllerActivatorType = (_configuration.CustomControllerActivator != null) ? _configuration.CustomControllerActivator : typeof(ServiceBasedControllerActivator); - + // AddControllersAsServices would replace the IControllerActivator by ServiceBasedControllerActivator, which is needed that Ninject can instantiate controllers // as we don't need the autobinding of the controllers, we should not call it during startup. Instead we will replace in Ninject the ControllerActivator. kernel.Rebind().To(controllerActivatorType).InTransientScope(); diff --git a/src/Ninject.Web.AspNetCore/DefaultDescriptorAdapter.cs b/src/Ninject.Web.AspNetCore/DefaultDescriptorAdapter.cs index 9928d34..0ef98ea 100644 --- a/src/Ninject.Web.AspNetCore/DefaultDescriptorAdapter.cs +++ b/src/Ninject.Web.AspNetCore/DefaultDescriptorAdapter.cs @@ -26,4 +26,4 @@ public object InstantiateFromServiceFactory(IServiceProvider provider, IContext } public ServiceLifetime Lifetime => _descriptor.Lifetime; } -} \ No newline at end of file +} diff --git a/src/Ninject.Web.AspNetCore/Hosting/AspNetCoreHost.cs b/src/Ninject.Web.AspNetCore/Hosting/AspNetCoreHost.cs index 19ab15a..2fa8843 100644 --- a/src/Ninject.Web.AspNetCore/Hosting/AspNetCoreHost.cs +++ b/src/Ninject.Web.AspNetCore/Hosting/AspNetCoreHost.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Hosting; using Ninject.Web.Common.SelfHost; diff --git a/src/Ninject.Web.AspNetCore/Hosting/AspNetCoreHostConfiguration.cs b/src/Ninject.Web.AspNetCore/Hosting/AspNetCoreHostConfiguration.cs index 6f38560..a683a33 100644 --- a/src/Ninject.Web.AspNetCore/Hosting/AspNetCoreHostConfiguration.cs +++ b/src/Ninject.Web.AspNetCore/Hosting/AspNetCoreHostConfiguration.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Hosting; using System; using System.Threading; diff --git a/src/Ninject.Web.AspNetCore/Hosting/AspNetCoreHostConfigurationExtensions.cs b/src/Ninject.Web.AspNetCore/Hosting/AspNetCoreHostConfigurationExtensions.cs index e585853..9c23ab5 100644 --- a/src/Ninject.Web.AspNetCore/Hosting/AspNetCoreHostConfigurationExtensions.cs +++ b/src/Ninject.Web.AspNetCore/Hosting/AspNetCoreHostConfigurationExtensions.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Server.Kestrel.Core; using System; using System.Threading; @@ -43,7 +43,8 @@ public static T UseKestrel(this T config, Action config { config.ConfigureHostingModel(builder => { - builder.UseKestrel((builderContext, options) => { + builder.UseKestrel((builderContext, options) => + { // Defaults from Microsoft.AspNetCore.WebHost.CreateDefaultBuilder options.Configure(builderContext.Configuration.GetSection("Kestrel")); configureAction(options); diff --git a/src/Ninject.Web.AspNetCore/Hosting/AspNetCoreHostingModule.cs b/src/Ninject.Web.AspNetCore/Hosting/AspNetCoreHostingModule.cs index 3974db5..ad79ac0 100644 --- a/src/Ninject.Web.AspNetCore/Hosting/AspNetCoreHostingModule.cs +++ b/src/Ninject.Web.AspNetCore/Hosting/AspNetCoreHostingModule.cs @@ -1,4 +1,4 @@ -using Ninject.Modules; +using Ninject.Modules; using Ninject.Web.Common.SelfHost; namespace Ninject.Web.AspNetCore.Hosting diff --git a/src/Ninject.Web.AspNetCore/Hosting/AspNetCoreStartupBase.cs b/src/Ninject.Web.AspNetCore/Hosting/AspNetCoreStartupBase.cs index fb61f52..61a0983 100644 --- a/src/Ninject.Web.AspNetCore/Hosting/AspNetCoreStartupBase.cs +++ b/src/Ninject.Web.AspNetCore/Hosting/AspNetCoreStartupBase.cs @@ -1,14 +1,14 @@ -using System; +using System; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.DependencyInjection; namespace Ninject.Web.AspNetCore.Hosting { - /// - /// Ninject customized startup class similar to Microsoft.AspNetCore.Hosting.StartupBase of TBuilder. - /// - public abstract class AspNetCoreStartupBase : IStartup + /// + /// Ninject customized startup class similar to Microsoft.AspNetCore.Hosting.StartupBase of TBuilder. + /// + public abstract class AspNetCoreStartupBase : IStartup { private readonly IServiceProviderFactory _providerFactory; diff --git a/src/Ninject.Web.AspNetCore/Hosting/DefaultWebHostConfiguration.cs b/src/Ninject.Web.AspNetCore/Hosting/DefaultWebHostConfiguration.cs index a81afc8..e43f512 100644 --- a/src/Ninject.Web.AspNetCore/Hosting/DefaultWebHostConfiguration.cs +++ b/src/Ninject.Web.AspNetCore/Hosting/DefaultWebHostConfiguration.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.HostFiltering; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting.StaticWebAssets; diff --git a/src/Ninject.Web.AspNetCore/Hosting/EmptyStartup.cs b/src/Ninject.Web.AspNetCore/Hosting/EmptyStartup.cs index 36e532c..d5f77a6 100644 --- a/src/Ninject.Web.AspNetCore/Hosting/EmptyStartup.cs +++ b/src/Ninject.Web.AspNetCore/Hosting/EmptyStartup.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; namespace Ninject.Web.AspNetCore.Hosting diff --git a/src/Ninject.Web.AspNetCore/Hosting/ForwardedHeadersStartupFilter.cs b/src/Ninject.Web.AspNetCore/Hosting/ForwardedHeadersStartupFilter.cs index 5ca10f2..568e0ee 100644 --- a/src/Ninject.Web.AspNetCore/Hosting/ForwardedHeadersStartupFilter.cs +++ b/src/Ninject.Web.AspNetCore/Hosting/ForwardedHeadersStartupFilter.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using System; diff --git a/src/Ninject.Web.AspNetCore/Hosting/HostFilteringStartupFilter.cs b/src/Ninject.Web.AspNetCore/Hosting/HostFilteringStartupFilter.cs index c0a15c7..360e939 100644 --- a/src/Ninject.Web.AspNetCore/Hosting/HostFilteringStartupFilter.cs +++ b/src/Ninject.Web.AspNetCore/Hosting/HostFilteringStartupFilter.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using System; diff --git a/src/Ninject.Web.AspNetCore/Hosting/IAspNetCoreHostConfiguration.cs b/src/Ninject.Web.AspNetCore/Hosting/IAspNetCoreHostConfiguration.cs index 44ad675..bd9e3e2 100644 --- a/src/Ninject.Web.AspNetCore/Hosting/IAspNetCoreHostConfiguration.cs +++ b/src/Ninject.Web.AspNetCore/Hosting/IAspNetCoreHostConfiguration.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Hosting; using System; using System.Threading; diff --git a/src/Ninject.Web.AspNetCore/Hosting/RequestScopeMiddleware.cs b/src/Ninject.Web.AspNetCore/Hosting/RequestScopeMiddleware.cs index 077b037..7f7f423 100644 --- a/src/Ninject.Web.AspNetCore/Hosting/RequestScopeMiddleware.cs +++ b/src/Ninject.Web.AspNetCore/Hosting/RequestScopeMiddleware.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http; using System.Threading.Tasks; namespace Ninject.Web.AspNetCore.Hosting diff --git a/src/Ninject.Web.AspNetCore/Hosting/RequestScopeStartupFilter.cs b/src/Ninject.Web.AspNetCore/Hosting/RequestScopeStartupFilter.cs index a518e11..c67a1e3 100644 --- a/src/Ninject.Web.AspNetCore/Hosting/RequestScopeStartupFilter.cs +++ b/src/Ninject.Web.AspNetCore/Hosting/RequestScopeStartupFilter.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using System; diff --git a/src/Ninject.Web.AspNetCore/IDescriptorAdapter.cs b/src/Ninject.Web.AspNetCore/IDescriptorAdapter.cs index a407dc1..f2c9a10 100644 --- a/src/Ninject.Web.AspNetCore/IDescriptorAdapter.cs +++ b/src/Ninject.Web.AspNetCore/IDescriptorAdapter.cs @@ -33,6 +33,6 @@ public interface IDescriptorAdapter /// /// The lifetime coonfigured for the service descriptor /// - ServiceLifetime Lifetime { get; } + ServiceLifetime Lifetime { get; } } -} \ No newline at end of file +} diff --git a/src/Ninject.Web.AspNetCore/IPopulateAdapter.cs b/src/Ninject.Web.AspNetCore/IPopulateAdapter.cs index 9dba4c1..ba3cb2e 100644 --- a/src/Ninject.Web.AspNetCore/IPopulateAdapter.cs +++ b/src/Ninject.Web.AspNetCore/IPopulateAdapter.cs @@ -1,4 +1,4 @@ -using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; namespace Ninject.Web.AspNetCore { diff --git a/src/Ninject.Web.AspNetCore/KeyedDescriptorAdapter.cs b/src/Ninject.Web.AspNetCore/KeyedDescriptorAdapter.cs index 3d98976..806bc82 100644 --- a/src/Ninject.Web.AspNetCore/KeyedDescriptorAdapter.cs +++ b/src/Ninject.Web.AspNetCore/KeyedDescriptorAdapter.cs @@ -37,4 +37,4 @@ public object InstantiateFromServiceFactory(IServiceProvider provider, IContext public ServiceLifetime Lifetime => _descriptor.Lifetime; } #endif -} \ No newline at end of file +} diff --git a/src/Ninject.Web.AspNetCore/NinjectServiceProvider.cs b/src/Ninject.Web.AspNetCore/NinjectServiceProvider.cs index 293d05e..e92439d 100644 --- a/src/Ninject.Web.AspNetCore/NinjectServiceProvider.cs +++ b/src/Ninject.Web.AspNetCore/NinjectServiceProvider.cs @@ -1,4 +1,4 @@ -using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; using Ninject.Syntax; using System; using System.Collections; @@ -162,7 +162,7 @@ private void EnsureNotAnyKey(object serviceKey, Type serviceType) if (serviceKey == KeyedService.AnyKey) { throw new InvalidOperationException($"Not allowed to resolve a service {serviceType} with the KeyedService.AnyKey. " + - $"That's only supported when resolving collections of services."); + $"That's only supported when resolving collections of services."); } } @@ -184,8 +184,8 @@ private static bool IsListType(Type type, out Type elementType) { Type genericTypeDefinition = type.GetGenericTypeDefinition(); if (genericTypeDefinition == typeof(IEnumerable<>) || - genericTypeDefinition == typeof(List<>) || genericTypeDefinition == typeof(IList<>) || - genericTypeDefinition == typeof(ICollection<>)) + genericTypeDefinition == typeof(List<>) || genericTypeDefinition == typeof(IList<>) || + genericTypeDefinition == typeof(ICollection<>)) { elementType = type.GenericTypeArguments[0]; return true; @@ -195,7 +195,7 @@ private static bool IsListType(Type type, out Type elementType) elementType = null; return false; } - + private static object ConvertToTypedEnumerable(Type elementType, IEnumerable objectList) { var castMethod = EnumerableCastMethod.MakeGenericMethod(elementType); @@ -203,6 +203,6 @@ private static object ConvertToTypedEnumerable(Type elementType, IEnumerable().ToMethod(context => { + _kernel.Bind().ToMethod(context => + { // Another interesting quirk of the Microsoft DI framework is that injecting the IServiceProvider injects a different // instance depending on the context. EXCEPT if the service provider is injected into a singleton in which case the // root service provider is used... diff --git a/src/Ninject.Web.AspNetCore/NinjectServiceProviderFactory.cs b/src/Ninject.Web.AspNetCore/NinjectServiceProviderFactory.cs index 8c85216..310852f 100644 --- a/src/Ninject.Web.AspNetCore/NinjectServiceProviderFactory.cs +++ b/src/Ninject.Web.AspNetCore/NinjectServiceProviderFactory.cs @@ -1,4 +1,4 @@ -using System; +using System; using Microsoft.Extensions.DependencyInjection; namespace Ninject.Web.AspNetCore diff --git a/src/Ninject.Web.AspNetCore/NinjectServiceProviderIsService.cs b/src/Ninject.Web.AspNetCore/NinjectServiceProviderIsService.cs index 32f9c2f..3672cb0 100644 --- a/src/Ninject.Web.AspNetCore/NinjectServiceProviderIsService.cs +++ b/src/Ninject.Web.AspNetCore/NinjectServiceProviderIsService.cs @@ -1,4 +1,4 @@ -using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; using System; using System.Collections.Generic; using Ninject.Web.AspNetCore.Planning; diff --git a/src/Ninject.Web.AspNetCore/NinjectServiceScope.cs b/src/Ninject.Web.AspNetCore/NinjectServiceScope.cs index 14d9e8b..9d476a3 100644 --- a/src/Ninject.Web.AspNetCore/NinjectServiceScope.cs +++ b/src/Ninject.Web.AspNetCore/NinjectServiceScope.cs @@ -1,4 +1,4 @@ -using System; +using System; using Microsoft.Extensions.DependencyInjection; using Ninject.Infrastructure.Disposal; using Ninject.Web.AspNetCore.Components; diff --git a/src/Ninject.Web.AspNetCore/Parameters/ServiceKeyParameter.cs b/src/Ninject.Web.AspNetCore/Parameters/ServiceKeyParameter.cs index 4a5d0d7..3f04cf0 100644 --- a/src/Ninject.Web.AspNetCore/Parameters/ServiceKeyParameter.cs +++ b/src/Ninject.Web.AspNetCore/Parameters/ServiceKeyParameter.cs @@ -12,4 +12,4 @@ public ServiceKeyParameter(object value) : base(nameof(ServiceKeyParameter), val public object ServiceKey { get; } } -} \ No newline at end of file +} diff --git a/src/Ninject.Web.AspNetCore/Planning/ConstructorInjectionDirectiveWithKeyedSupport.cs b/src/Ninject.Web.AspNetCore/Planning/ConstructorInjectionDirectiveWithKeyedSupport.cs index d962f91..1f688c0 100644 --- a/src/Ninject.Web.AspNetCore/Planning/ConstructorInjectionDirectiveWithKeyedSupport.cs +++ b/src/Ninject.Web.AspNetCore/Planning/ConstructorInjectionDirectiveWithKeyedSupport.cs @@ -17,8 +17,8 @@ public ConstructorInjectionDirectiveWithKeyedSupport(ConstructorInfo constructor protected override ITarget[] CreateTargetsFromParameters(ConstructorInfo method) { return method.GetParameters(). - Select((Func) (parameter => new ParameterTargetWithKeyedSupport(method, parameter))). + Select((Func)(parameter => new ParameterTargetWithKeyedSupport(method, parameter))). ToArray(); } } -} \ No newline at end of file +} diff --git a/src/Ninject.Web.AspNetCore/Planning/KeyedServiceAnyKeyResolver.cs b/src/Ninject.Web.AspNetCore/Planning/KeyedServiceAnyKeyResolver.cs index d6d70ed..a1ccc93 100644 --- a/src/Ninject.Web.AspNetCore/Planning/KeyedServiceAnyKeyResolver.cs +++ b/src/Ninject.Web.AspNetCore/Planning/KeyedServiceAnyKeyResolver.cs @@ -11,7 +11,7 @@ namespace Ninject.Web.AspNetCore.Planning { -#if NET8_0_OR_GREATER +#if NET8_0_OR_GREATER /// /// This class is used to handle keyed services registrations with service key equal to /// KeyedService.AnyKey. @@ -28,8 +28,8 @@ public IEnumerable Resolve(Multimap bindings, IRequest // this ensures that we e.g. can have a singleton binding with anykey, but instantiate one singleton // per servicekey. var keyedRequest = request as KeyedRequest; - if (keyedRequest != null && keyedRequest.ServiceKey != null && keyedRequest.ServiceKey != KeyedService.AnyKey - && keyedRequest.IsUnique) + if (keyedRequest != null && keyedRequest.ServiceKey != null && keyedRequest.ServiceKey != KeyedService.AnyKey + && keyedRequest.IsUnique) { var service = request.Service; var matchingBindings = bindings.Where(x => x.Key == service); @@ -44,8 +44,8 @@ public IEnumerable Resolve(Multimap bindings, IRequest foreach (var binding in bindingGroup.Value) { if (binding.Metadata.HasServiceKeyMetadata() && Object.Equals(binding.Metadata.GetServiceKey(), KeyedService.AnyKey) - && (binding.Metadata.Get(nameof(BindingIndex))?.IsLatest ?? true) - ) + && (binding.Metadata.Get(nameof(BindingIndex))?.IsLatest ?? true) + ) { matchingAnyBinding = binding; break; @@ -80,4 +80,4 @@ public IEnumerable Resolve(Multimap bindings, IRequest } } #endif -} \ No newline at end of file +} diff --git a/src/Ninject.Web.AspNetCore/Planning/KeyedServicesMetaDataExtensions.cs b/src/Ninject.Web.AspNetCore/Planning/KeyedServicesMetaDataExtensions.cs index dfed78d..50e58cf 100644 --- a/src/Ninject.Web.AspNetCore/Planning/KeyedServicesMetaDataExtensions.cs +++ b/src/Ninject.Web.AspNetCore/Planning/KeyedServicesMetaDataExtensions.cs @@ -37,4 +37,4 @@ internal static bool HasServiceKeyMetadata(this IBindingMetadata metadata) return metadata.Has(nameof(ServiceKey)); } } -} \ No newline at end of file +} diff --git a/src/Ninject.Web.AspNetCore/Planning/ParameterTargetWithKeyedSupport.cs b/src/Ninject.Web.AspNetCore/Planning/ParameterTargetWithKeyedSupport.cs index 50728fa..7d8bf1b 100644 --- a/src/Ninject.Web.AspNetCore/Planning/ParameterTargetWithKeyedSupport.cs +++ b/src/Ninject.Web.AspNetCore/Planning/ParameterTargetWithKeyedSupport.cs @@ -52,11 +52,11 @@ public override bool HasDefaultValue object ITarget.ResolveWithin(IContext parent) { #if NET8_0_OR_GREATER - if (_serviceKeyAttribute.Value != null) + if (_serviceKeyAttribute.Value != null) { return ResolveServiceKeyValue(parent); } - + if (_fromKeyedServicesAttribute.Value != null) { return ResolveFromKeyedService(parent, _fromKeyedServicesAttribute.Value); @@ -74,7 +74,7 @@ private ServiceKeyAttribute ReadServiceKeyAttribute() private FromKeyedServicesAttribute ReadFromKeyedServicesAttribute() { - var keyedattributes = GetCustomAttributes(typeof (FromKeyedServicesAttribute), true) as FromKeyedServicesAttribute[]; + var keyedattributes = GetCustomAttributes(typeof(FromKeyedServicesAttribute), true) as FromKeyedServicesAttribute[]; return keyedattributes?.Length > 0 ? keyedattributes[0] : null; } @@ -155,4 +155,4 @@ private object ResolveServiceKeyValue(IContext parent) } #endif } -} \ No newline at end of file +} diff --git a/src/Ninject.Web.AspNetCore/RequestActivation/KeyedRequest.cs b/src/Ninject.Web.AspNetCore/RequestActivation/KeyedRequest.cs index 9624ca6..d6b6c1e 100644 --- a/src/Ninject.Web.AspNetCore/RequestActivation/KeyedRequest.cs +++ b/src/Ninject.Web.AspNetCore/RequestActivation/KeyedRequest.cs @@ -64,7 +64,7 @@ public KeyedRequest(IContext parentContext, Type service, object serviceKey, ITa foreach (var parameter in parametersToRemove) { Parameters.Remove(parameter); - } + } Parameters.Add(new ServiceKeyParameter(serviceKey)); ScopeCallback = scopeCallback; ActiveBindings = new Stack(this.ParentRequest.ActiveBindings); @@ -187,4 +187,4 @@ public override string ToString() return this.Format(); } } -} \ No newline at end of file +} diff --git a/src/Ninject.Web.AspNetCore/RequestActivation/KeyedRequestExtensions.cs b/src/Ninject.Web.AspNetCore/RequestActivation/KeyedRequestExtensions.cs index d533e4f..14fa9b0 100644 --- a/src/Ninject.Web.AspNetCore/RequestActivation/KeyedRequestExtensions.cs +++ b/src/Ninject.Web.AspNetCore/RequestActivation/KeyedRequestExtensions.cs @@ -16,7 +16,7 @@ public static IRequest CreateKeyedChildRequest(this IRequest parentRequest, Type public static IRequest ToKeyedRequest(this IRequest request, object serviceKey) { - return new KeyedRequest(request.Service, serviceKey, request.Constraint, request.Parameters.ToList(), + return new KeyedRequest(request.Service, serviceKey, request.Constraint, request.Parameters.ToList(), request.GetScope, request.IsOptional, request.IsUnique); } -} \ No newline at end of file +} diff --git a/src/Ninject.Web.AspNetCore/RequestScope.cs b/src/Ninject.Web.AspNetCore/RequestScope.cs index 30080ac..fac80c9 100644 --- a/src/Ninject.Web.AspNetCore/RequestScope.cs +++ b/src/Ninject.Web.AspNetCore/RequestScope.cs @@ -1,4 +1,4 @@ -using Ninject.Infrastructure.Disposal; +using Ninject.Infrastructure.Disposal; using System; using System.Threading; diff --git a/src/Ninject.Web.AspNetCore/ServiceCollectionAdapter.cs b/src/Ninject.Web.AspNetCore/ServiceCollectionAdapter.cs index dfd4aa0..032aca0 100644 --- a/src/Ninject.Web.AspNetCore/ServiceCollectionAdapter.cs +++ b/src/Ninject.Web.AspNetCore/ServiceCollectionAdapter.cs @@ -1,4 +1,4 @@ -using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; using Ninject.Syntax; using Ninject.Web.Common; using System; @@ -122,7 +122,8 @@ private IBindingNamedWithOrOnSyntax ConfigureLifecycle( case ServiceLifetime.Singleton: // Microsoft.Extensions.DependencyInjection expects its singletons to be disposed when the root service scope // and/or the root IServiceProvider is disposed. - return bindingInSyntax.InScope(context => { + return bindingInSyntax.InScope(context => + { return (context.Kernel as AspNetCoreKernel).RootScope; }); case ServiceLifetime.Scoped: @@ -130,7 +131,8 @@ private IBindingNamedWithOrOnSyntax ConfigureLifecycle( case ServiceLifetime.Transient: // Microsoft.Extensions.DependencyInjection expects transient services to be disposed when the IServiceScope // in which they were created is disposed. See the compliance tests for more details. - return bindingInSyntax.InScope(context => { + return bindingInSyntax.InScope(context => + { var scope = context.GetServiceProviderScopeParameter(); return scope?.DeriveTransientScope(); }); diff --git a/src/Ninject.Web.AspNetCore/ServiceCollectionExtensions.cs b/src/Ninject.Web.AspNetCore/ServiceCollectionExtensions.cs index 61a49c3..1b597d6 100644 --- a/src/Ninject.Web.AspNetCore/ServiceCollectionExtensions.cs +++ b/src/Ninject.Web.AspNetCore/ServiceCollectionExtensions.cs @@ -1,4 +1,4 @@ -using System; +using System; using Microsoft.Extensions.DependencyInjection; namespace Ninject.Web.AspNetCore diff --git a/src/Ninject.Web.AspNetCore/ServiceKey.cs b/src/Ninject.Web.AspNetCore/ServiceKey.cs index addbb93..8663ec5 100644 --- a/src/Ninject.Web.AspNetCore/ServiceKey.cs +++ b/src/Ninject.Web.AspNetCore/ServiceKey.cs @@ -17,4 +17,4 @@ public ServiceKey(object key) } } -} \ No newline at end of file +} diff --git a/src/Ninject.Web.AspNetCore/ServiceProviderScopeParameter.cs b/src/Ninject.Web.AspNetCore/ServiceProviderScopeParameter.cs index 4a48ecd..91f6be0 100644 --- a/src/Ninject.Web.AspNetCore/ServiceProviderScopeParameter.cs +++ b/src/Ninject.Web.AspNetCore/ServiceProviderScopeParameter.cs @@ -1,4 +1,4 @@ -using Ninject.Infrastructure.Disposal; +using Ninject.Infrastructure.Disposal; using Ninject.Parameters; using System; using System.Collections.Generic; diff --git a/src/Ninject.Web.AspNetCore/ServiceProviderScopeResolutionRoot.cs b/src/Ninject.Web.AspNetCore/ServiceProviderScopeResolutionRoot.cs index 8fe6b98..a3729fa 100644 --- a/src/Ninject.Web.AspNetCore/ServiceProviderScopeResolutionRoot.cs +++ b/src/Ninject.Web.AspNetCore/ServiceProviderScopeResolutionRoot.cs @@ -1,4 +1,4 @@ -using Ninject.Activation; +using Ninject.Activation; using Ninject.Parameters; using Ninject.Planning.Bindings; using Ninject.Syntax; diff --git a/src/SampleApplication/Controllers/HomeController.cs b/src/SampleApplication/Controllers/HomeController.cs index ac181f7..c5d9365 100644 --- a/src/SampleApplication/Controllers/HomeController.cs +++ b/src/SampleApplication/Controllers/HomeController.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; diff --git a/src/SampleApplication/Models/ErrorViewModel.cs b/src/SampleApplication/Models/ErrorViewModel.cs index fe72a39..bded0dc 100644 --- a/src/SampleApplication/Models/ErrorViewModel.cs +++ b/src/SampleApplication/Models/ErrorViewModel.cs @@ -2,10 +2,10 @@ namespace SampleApplication.Models { - public class ErrorViewModel - { - public string RequestId { get; set; } + public class ErrorViewModel + { + public string RequestId { get; set; } - public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); - } -} \ No newline at end of file + public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); + } +} diff --git a/src/SampleApplication/Program.cs b/src/SampleApplication/Program.cs index da45278..8b1296c 100644 --- a/src/SampleApplication/Program.cs +++ b/src/SampleApplication/Program.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.ModelBinding; using Microsoft.Extensions.Options; diff --git a/src/SampleApplication/Service/ChatBot/ChatBotModule.cs b/src/SampleApplication/Service/ChatBot/ChatBotModule.cs index ce5beca..e4e8992 100644 --- a/src/SampleApplication/Service/ChatBot/ChatBotModule.cs +++ b/src/SampleApplication/Service/ChatBot/ChatBotModule.cs @@ -1,4 +1,4 @@ -using Ninject.Modules; +using Ninject.Modules; using Ninject.Web.Common; namespace SampleApplication.Service.ChatBot diff --git a/src/SampleApplication/Service/ChatBot/ChatBotService.cs b/src/SampleApplication/Service/ChatBot/ChatBotService.cs index 48ada56..1ed9101 100644 --- a/src/SampleApplication/Service/ChatBot/ChatBotService.cs +++ b/src/SampleApplication/Service/ChatBot/ChatBotService.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Globalization; diff --git a/src/SampleApplication/Service/ChatBot/HelloRequest.cs b/src/SampleApplication/Service/ChatBot/HelloRequest.cs index fec50a3..b18ad5c 100644 --- a/src/SampleApplication/Service/ChatBot/HelloRequest.cs +++ b/src/SampleApplication/Service/ChatBot/HelloRequest.cs @@ -1,4 +1,4 @@ -namespace SampleApplication.Service.ChatBot +namespace SampleApplication.Service.ChatBot { public class HelloRequest { diff --git a/src/SampleApplication/Service/ChatBot/HelloResponse.cs b/src/SampleApplication/Service/ChatBot/HelloResponse.cs index 69e6763..a0a0699 100644 --- a/src/SampleApplication/Service/ChatBot/HelloResponse.cs +++ b/src/SampleApplication/Service/ChatBot/HelloResponse.cs @@ -1,4 +1,4 @@ -namespace SampleApplication.Service.ChatBot +namespace SampleApplication.Service.ChatBot { public class HelloResponse { diff --git a/src/SampleApplication/Service/ChatBot/HelloType.cs b/src/SampleApplication/Service/ChatBot/HelloType.cs index d27094e..77a2d9a 100644 --- a/src/SampleApplication/Service/ChatBot/HelloType.cs +++ b/src/SampleApplication/Service/ChatBot/HelloType.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; diff --git a/src/SampleApplication/Service/ChatBot/IChatBotService.cs b/src/SampleApplication/Service/ChatBot/IChatBotService.cs index a670255..c8e9cd5 100644 --- a/src/SampleApplication/Service/ChatBot/IChatBotService.cs +++ b/src/SampleApplication/Service/ChatBot/IChatBotService.cs @@ -1,4 +1,4 @@ -namespace SampleApplication.Service.ChatBot +namespace SampleApplication.Service.ChatBot { public interface IChatBotService { diff --git a/src/SampleApplication/Service/ControllerFromInterfaceApplicationModelAdapter.cs b/src/SampleApplication/Service/ControllerFromInterfaceApplicationModelAdapter.cs index 7e87c2a..9bc1714 100644 --- a/src/SampleApplication/Service/ControllerFromInterfaceApplicationModelAdapter.cs +++ b/src/SampleApplication/Service/ControllerFromInterfaceApplicationModelAdapter.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.Mvc.ApplicationModels; +using Microsoft.AspNetCore.Mvc.ApplicationModels; using Microsoft.AspNetCore.Mvc.ModelBinding; using System.Collections.Generic; using System.Reflection; diff --git a/src/SampleApplication/Service/IApplicationModelAdapter.cs b/src/SampleApplication/Service/IApplicationModelAdapter.cs index c2cb015..79bdb6d 100644 --- a/src/SampleApplication/Service/IApplicationModelAdapter.cs +++ b/src/SampleApplication/Service/IApplicationModelAdapter.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.Mvc.ApplicationModels; +using Microsoft.AspNetCore.Mvc.ApplicationModels; namespace SampleApplication.Service { diff --git a/src/SampleApplication/Service/PublishInstruction.cs b/src/SampleApplication/Service/PublishInstruction.cs index 68c9055..7e45785 100644 --- a/src/SampleApplication/Service/PublishInstruction.cs +++ b/src/SampleApplication/Service/PublishInstruction.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.Mvc.ModelBinding; +using Microsoft.AspNetCore.Mvc.ModelBinding; using System; namespace SampleApplication.Service diff --git a/src/SampleApplication/Service/PublishInstructionApplicationModelConfiguration.cs b/src/SampleApplication/Service/PublishInstructionApplicationModelConfiguration.cs index c7c2fc7..8a1026f 100644 --- a/src/SampleApplication/Service/PublishInstructionApplicationModelConfiguration.cs +++ b/src/SampleApplication/Service/PublishInstructionApplicationModelConfiguration.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; namespace SampleApplication.Service diff --git a/src/SampleApplication/Service/PublishInstructionApplicationModelConvention.cs b/src/SampleApplication/Service/PublishInstructionApplicationModelConvention.cs index 6c69708..df80d98 100644 --- a/src/SampleApplication/Service/PublishInstructionApplicationModelConvention.cs +++ b/src/SampleApplication/Service/PublishInstructionApplicationModelConvention.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.Mvc.ApplicationModels; +using Microsoft.AspNetCore.Mvc.ApplicationModels; using Microsoft.AspNetCore.Mvc.ModelBinding; using System; using System.Collections.Generic; @@ -14,7 +14,8 @@ public PublishInstructionApplicationModelConvention( // this _must_ be injected as Lazy because it does not exist yet when the type is instantiated Lazy modelMetadataProvider, IList apiPublications - ) { + ) + { _modelMetadataProvider = modelMetadataProvider; _apiPublications = apiPublications; } diff --git a/src/SampleApplication/Startup.cs b/src/SampleApplication/Startup.cs index c0a21e6..17bf9c0 100644 --- a/src/SampleApplication/Startup.cs +++ b/src/SampleApplication/Startup.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; diff --git a/src/SampleBlazorApplication/ChatClient/IChatClient.cs b/src/SampleBlazorApplication/ChatClient/IChatClient.cs index 7dcf563..c59e48a 100644 --- a/src/SampleBlazorApplication/ChatClient/IChatClient.cs +++ b/src/SampleBlazorApplication/ChatClient/IChatClient.cs @@ -1,4 +1,4 @@ -namespace SampleBlazorApplication.ChatClient +namespace SampleBlazorApplication.ChatClient { /// /// See https://docs.microsoft.com/en-us/aspnet/core/signalr/hubs?view=aspnetcore-6.0#strongly-typed-hubs diff --git a/src/SampleBlazorApplication/ChatClient/StronglyTypedChatHub.cs b/src/SampleBlazorApplication/ChatClient/StronglyTypedChatHub.cs index 5ef0126..647fa6a 100644 --- a/src/SampleBlazorApplication/ChatClient/StronglyTypedChatHub.cs +++ b/src/SampleBlazorApplication/ChatClient/StronglyTypedChatHub.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.SignalR; +using Microsoft.AspNetCore.SignalR; namespace SampleBlazorApplication.ChatClient { diff --git a/src/SampleBlazorApplication/Data/WeatherForecast.cs b/src/SampleBlazorApplication/Data/WeatherForecast.cs index 242b4ca..9690700 100644 --- a/src/SampleBlazorApplication/Data/WeatherForecast.cs +++ b/src/SampleBlazorApplication/Data/WeatherForecast.cs @@ -1,13 +1,13 @@ namespace SampleBlazorApplication.Data { - public class WeatherForecast - { - public DateTime Date { get; set; } + public class WeatherForecast + { + public DateTime Date { get; set; } - public int TemperatureC { get; set; } + public int TemperatureC { get; set; } - public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); - public string? Summary { get; set; } - } -} \ No newline at end of file + public string? Summary { get; set; } + } +} diff --git a/src/SampleBlazorApplication/Data/WeatherForecastService.cs b/src/SampleBlazorApplication/Data/WeatherForecastService.cs index ab4aea7..0bc15ed 100644 --- a/src/SampleBlazorApplication/Data/WeatherForecastService.cs +++ b/src/SampleBlazorApplication/Data/WeatherForecastService.cs @@ -3,8 +3,8 @@ namespace SampleBlazorApplication.Data { - public class WeatherForecastService - { + public class WeatherForecastService + { /// /// The _chatHubContext is only here to test the _injection of strongly typed SignalR hub contexts as described in /// https://docs.microsoft.com/en-us/aspnet/core/signalr/hubcontext?view=aspnetcore-6.0#inject-a-strongly-typed-hubcontext @@ -18,19 +18,19 @@ public WeatherForecastService(IHubContext cha _chatHubContext = chatHubContext; } - private static readonly string[] Summaries = new[] - { + private static readonly string[] Summaries = new[] + { "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" }; - public Task GetForecastAsync(DateTime startDate) - { - return Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast - { - Date = startDate.AddDays(index), - TemperatureC = Random.Shared.Next(-20, 55), - Summary = Summaries[Random.Shared.Next(Summaries.Length)] - }).ToArray()); - } - } -} \ No newline at end of file + public Task GetForecastAsync(DateTime startDate) + { + return Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast + { + Date = startDate.AddDays(index), + TemperatureC = Random.Shared.Next(-20, 55), + Summary = Summaries[Random.Shared.Next(Summaries.Length)] + }).ToArray()); + } + } +} diff --git a/src/SampleBlazorApplication/Pages/Error.cshtml.cs b/src/SampleBlazorApplication/Pages/Error.cshtml.cs index 0cbe5c8..9d66f1a 100644 --- a/src/SampleBlazorApplication/Pages/Error.cshtml.cs +++ b/src/SampleBlazorApplication/Pages/Error.cshtml.cs @@ -1,27 +1,27 @@ -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; using System.Diagnostics; namespace SampleBlazorApplication.Pages { - [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] - [IgnoreAntiforgeryToken] - public class ErrorModel : PageModel - { - public string? RequestId { get; set; } + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] + [IgnoreAntiforgeryToken] + public class ErrorModel : PageModel + { + public string? RequestId { get; set; } - public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); + public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); - private readonly ILogger _logger; + private readonly ILogger _logger; - public ErrorModel(ILogger logger) - { - _logger = logger; - } + public ErrorModel(ILogger logger) + { + _logger = logger; + } - public void OnGet() - { - RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier; - } - } -} \ No newline at end of file + public void OnGet() + { + RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier; + } + } +} diff --git a/src/SampleBlazorApplication/Program.cs b/src/SampleBlazorApplication/Program.cs index b7561ab..6cf5fc9 100644 --- a/src/SampleBlazorApplication/Program.cs +++ b/src/SampleBlazorApplication/Program.cs @@ -54,4 +54,4 @@ public static AspNetCoreKernel CreateKernel() return kernel; } -} \ No newline at end of file +} From 115d31a9ac2818c8dda06c4114cb5ae2df62d2aa Mon Sep 17 00:00:00 2001 From: Lukas Angerer Date: Wed, 19 Aug 2026 13:54:59 +0200 Subject: [PATCH 5/5] Automated formatting check --- .github/workflows/build.yml | 3 +++ .github/workflows/publish.yml | 3 +++ 2 files changed, 6 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b7c24de..8ec442b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -34,6 +34,9 @@ jobs: - name: Restore dependencies run: dotnet restore $SOLUTION_FILE + - name: Verify formatting + run: dotnet format $SOLUTION_FILE --verify-no-changes + - name: Build run: dotnet build --no-restore $SOLUTION_FILE diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 7e95662..35a362f 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -35,6 +35,9 @@ jobs: - name: Restore dependencies run: dotnet restore $SOLUTION_FILE + - name: Verify formatting + run: dotnet format $SOLUTION_FILE --verify-no-changes + - name: Build run: dotnet build --no-restore $SOLUTION_FILE