From e40dcc10b2704abb6e4a22b0ca1fd2fe977657fb Mon Sep 17 00:00:00 2001 From: Travis Illig Date: Thu, 28 May 2026 12:36:04 -0700 Subject: [PATCH 01/19] Add SonarAnalyzer.CSharp and unified analyzer rulesets. Adds SonarAnalyzer.CSharp 10.27.0.140913 to all projects. Replaces existing Source.ruleset and Test.ruleset with unified versions shared across the Autofac organization. Ensures all projects have AnalysisMode=AllEnabledByDefault and EnforceCodeStyleInBuild=true. --- build/Source.ruleset | 42 +++++-- build/Test.ruleset | 103 +++++++++++++----- src/Autofac.Pooling/Autofac.Pooling.csproj | 6 + .../Autofac.Pooling.Test.csproj | 6 + 4 files changed, 116 insertions(+), 41 deletions(-) diff --git a/build/Source.ruleset b/build/Source.ruleset index 459e4e0..b1e5bb6 100644 --- a/build/Source.ruleset +++ b/build/Source.ruleset @@ -1,8 +1,8 @@ - - + + - - + + @@ -12,23 +12,41 @@ - + - + - + - + - + - + - + - + + + + + + + + + + + + + + + + + + + diff --git a/build/Test.ruleset b/build/Test.ruleset index 3c26c01..9434578 100644 --- a/build/Test.ruleset +++ b/build/Test.ruleset @@ -1,16 +1,12 @@ - - + + - - - - + + - - - + - + @@ -20,37 +16,79 @@ - - - + - + - - - + - + - + - + + + - + - + - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -58,11 +96,11 @@ - + - + - + @@ -82,6 +120,13 @@ + + + + + + + diff --git a/src/Autofac.Pooling/Autofac.Pooling.csproj b/src/Autofac.Pooling/Autofac.Pooling.csproj index 1e71b41..6f4370d 100644 --- a/src/Autofac.Pooling/Autofac.Pooling.csproj +++ b/src/Autofac.Pooling/Autofac.Pooling.csproj @@ -8,6 +8,8 @@ ../../Autofac.snk true ../../build/Source.ruleset + AllEnabledByDefault + true false false false @@ -51,6 +53,10 @@ All + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/test/Autofac.Pooling.Test/Autofac.Pooling.Test.csproj b/test/Autofac.Pooling.Test/Autofac.Pooling.Test.csproj index f67c43d..8294f22 100644 --- a/test/Autofac.Pooling.Test/Autofac.Pooling.Test.csproj +++ b/test/Autofac.Pooling.Test/Autofac.Pooling.Test.csproj @@ -2,6 +2,8 @@ net10.0 ../../build/Test.ruleset + AllEnabledByDefault + true false @@ -15,6 +17,10 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + From a2de181549d8dd7c078010b88bccbff8c9f57010 Mon Sep 17 00:00:00 2001 From: Travis Illig Date: Thu, 28 May 2026 14:43:59 -0700 Subject: [PATCH 02/19] Disable CA1034 in Test.ruleset: nested types are standard in test fixtures. --- build/Test.ruleset | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build/Test.ruleset b/build/Test.ruleset index 9434578..742a68c 100644 --- a/build/Test.ruleset +++ b/build/Test.ruleset @@ -42,6 +42,8 @@ + + From b2a0e527e19b6373d32817708b4cb340c01fa3ad Mon Sep 17 00:00:00 2001 From: Travis Illig Date: Thu, 28 May 2026 14:46:05 -0700 Subject: [PATCH 03/19] Fix CA1852: seal internal types with no subtypes. --- src/Autofac.Pooling/AutofacPooledObjectPolicy.cs | 2 +- src/Autofac.Pooling/PoolService.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Autofac.Pooling/AutofacPooledObjectPolicy.cs b/src/Autofac.Pooling/AutofacPooledObjectPolicy.cs index 8665959..8b202c4 100644 --- a/src/Autofac.Pooling/AutofacPooledObjectPolicy.cs +++ b/src/Autofac.Pooling/AutofacPooledObjectPolicy.cs @@ -10,7 +10,7 @@ namespace Autofac.Pooling; /// Provides the needed for creating/returning objects in the pool in an Autofac way. /// /// The type of object being pooled. -internal class AutofacPooledObjectPolicy : IPooledObjectPolicy +internal sealed class AutofacPooledObjectPolicy : IPooledObjectPolicy where TPooledObject : class { private readonly Service _poolInstanceService; diff --git a/src/Autofac.Pooling/PoolService.cs b/src/Autofac.Pooling/PoolService.cs index 358cb76..1faae61 100644 --- a/src/Autofac.Pooling/PoolService.cs +++ b/src/Autofac.Pooling/PoolService.cs @@ -11,7 +11,7 @@ namespace Autofac.Pooling; /// /// Defines a service used to access an , ensuring that each pooled item registration gets a different pool. /// -internal class PoolService : Service, IEquatable +internal sealed class PoolService : Service, IEquatable { private readonly IComponentRegistration _pooledItemRegistration; From 7ef08de66cfff240f85e81dea5134ba1303b4866 Mon Sep 17 00:00:00 2001 From: Travis Illig Date: Thu, 28 May 2026 14:46:07 -0700 Subject: [PATCH 04/19] Fix S1481: remove unused local variable. --- test/Autofac.Pooling.Test/ImplicitRelationshipTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Autofac.Pooling.Test/ImplicitRelationshipTests.cs b/test/Autofac.Pooling.Test/ImplicitRelationshipTests.cs index e0a81c4..dd76982 100644 --- a/test/Autofac.Pooling.Test/ImplicitRelationshipTests.cs +++ b/test/Autofac.Pooling.Test/ImplicitRelationshipTests.cs @@ -237,7 +237,7 @@ public void CanResolveCollectionOfTwoDifferentPoolsOfSameLimitType() using (var scope1 = container.BeginLifetimeScope()) { - var set = scope1.Resolve>(); + scope1.Resolve>(); // The important point is that each pool goes up by one, meaning that we can track different pools // for the same limit type. From d31f3b91f5f2fd7810cd1da6692d42aa7096e41d Mon Sep 17 00:00:00 2001 From: Travis Illig Date: Thu, 28 May 2026 14:46:18 -0700 Subject: [PATCH 05/19] Fix S2699: add assertions to tests that verify no exception is thrown. --- test/Autofac.Pooling.Test/ConcurrencyTests.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/test/Autofac.Pooling.Test/ConcurrencyTests.cs b/test/Autofac.Pooling.Test/ConcurrencyTests.cs index 29f5bf5..7e391b6 100644 --- a/test/Autofac.Pooling.Test/ConcurrencyTests.cs +++ b/test/Autofac.Pooling.Test/ConcurrencyTests.cs @@ -22,14 +22,18 @@ public async Task CanUsePoolConcurrently() var container = builder.Build(); - await Task.WhenAll(Enumerable.Range(0, 2000).Select(i => Task.Run(() => + var exception = await Record.ExceptionAsync(async () => { - using var scope = container.BeginLifetimeScope(); + await Task.WhenAll(Enumerable.Range(0, 2000).Select(i => Task.Run(() => + { + using var scope = container.BeginLifetimeScope(); - scope.Resolve(); - }))); + scope.Resolve(); + }))); - container.Dispose(); + container.Dispose(); + }); + Assert.Null(exception); } [Fact] From e41d0e0f52d7174e8d73d3ac3b5a71747f48fd51 Mon Sep 17 00:00:00 2001 From: Travis Illig Date: Thu, 28 May 2026 16:22:10 -0700 Subject: [PATCH 06/19] Fix S927: rename parameter to match interface declaration. --- test/Autofac.Pooling.Test/Shared/PooledComponent.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Autofac.Pooling.Test/Shared/PooledComponent.cs b/test/Autofac.Pooling.Test/Shared/PooledComponent.cs index 5791620..b745d81 100644 --- a/test/Autofac.Pooling.Test/Shared/PooledComponent.cs +++ b/test/Autofac.Pooling.Test/Shared/PooledComponent.cs @@ -21,7 +21,7 @@ public int DisposeCalled get; private set; } - public void OnGetFromPool(IComponentContext ctxt, IEnumerable parameters) + public void OnGetFromPool(IComponentContext context, IEnumerable parameters) { GetCalled++; } From d5b9fe007a4714015a316981f976d485ee16d1e2 Mon Sep 17 00:00:00 2001 From: Travis Illig Date: Thu, 28 May 2026 16:22:11 -0700 Subject: [PATCH 07/19] Fix CA1062: add null check for parameter validation. --- test/Autofac.Pooling.Test/Shared/PoolTrackingPolicy.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/Autofac.Pooling.Test/Shared/PoolTrackingPolicy.cs b/test/Autofac.Pooling.Test/Shared/PoolTrackingPolicy.cs index 2365abe..17b5992 100644 --- a/test/Autofac.Pooling.Test/Shared/PoolTrackingPolicy.cs +++ b/test/Autofac.Pooling.Test/Shared/PoolTrackingPolicy.cs @@ -14,6 +14,8 @@ public class PoolTrackingPolicy : DefaultPooledRegistrationPolicy parameters, Func getFromPool) { + ArgumentNullException.ThrowIfNull(getFromPool); + Interlocked.Increment(ref _outOfPool); return getFromPool(); From 99ae68b558d6d2791d9d1af8cbce5dc804acd2a8 Mon Sep 17 00:00:00 2001 From: Travis Illig Date: Thu, 28 May 2026 17:45:28 -0700 Subject: [PATCH 08/19] Disable S1133: do not warn on use of obsolete/deprecated members. Autofac intentionally maintains deprecated APIs for backward compatibility. Tests exercise deprecated APIs to verify they still work. Warnings about using deprecated code are not actionable in this context. --- build/Source.ruleset | 2 ++ build/Test.ruleset | 2 ++ 2 files changed, 4 insertions(+) diff --git a/build/Source.ruleset b/build/Source.ruleset index b1e5bb6..1cd02ff 100644 --- a/build/Source.ruleset +++ b/build/Source.ruleset @@ -32,6 +32,8 @@ + + diff --git a/build/Test.ruleset b/build/Test.ruleset index 742a68c..7729333 100644 --- a/build/Test.ruleset +++ b/build/Test.ruleset @@ -55,6 +55,8 @@ + + From b5bf8a0b5c87cdd41b3f17a1f94139710b95e3eb Mon Sep 17 00:00:00 2001 From: Travis Illig Date: Fri, 29 May 2026 07:19:24 -0700 Subject: [PATCH 09/19] Enable CA1063, disable S3881, fix ruleset comment ordering. - CA1063 (Implement IDisposable correctly): enabled as Warning in both Source and Test rulesets for explicit enforcement. - S3881 (IDisposable pattern): disabled because Autofac uses non-standard dispose patterns for container lifecycle management. - Fixed comment/rule ordering where S1133 insertion displaced comments. --- build/Source.ruleset | 4 ++++ build/Test.ruleset | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/build/Source.ruleset b/build/Source.ruleset index 1cd02ff..8994858 100644 --- a/build/Source.ruleset +++ b/build/Source.ruleset @@ -4,6 +4,8 @@ + + @@ -44,6 +46,8 @@ + + diff --git a/build/Test.ruleset b/build/Test.ruleset index 7729333..cd29cf9 100644 --- a/build/Test.ruleset +++ b/build/Test.ruleset @@ -6,6 +6,8 @@ + + @@ -54,9 +56,9 @@ - + @@ -80,6 +82,8 @@ + + From aeada67df3c511252719bdc8a25148f58086d0a0 Mon Sep 17 00:00:00 2001 From: Travis Illig Date: Fri, 29 May 2026 08:39:31 -0700 Subject: [PATCH 10/19] Correct build task. --- .vscode/tasks.json | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 2354883..70e1c3b 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -1,21 +1,9 @@ { "tasks": [ - { - "args": [ - "watch", - "run", - "${workspaceFolder}/test/Autofac.Pooling.Tests/Autofac.Pooling.Tests.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" - ], - "command": "dotnet", - "label": "watch", - "problemMatcher": "$msCompile", - "type": "process" - }, { "args": [ "build", + "Autofac.Pooling.sln", "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary" ], From 218b846dd31e29422e45ad5a7eb579c46f9bb0fe Mon Sep 17 00:00:00 2001 From: Travis Illig Date: Fri, 29 May 2026 08:40:01 -0700 Subject: [PATCH 11/19] Removed unused targets file. --- Directory.Build.targets | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 Directory.Build.targets diff --git a/Directory.Build.targets b/Directory.Build.targets deleted file mode 100644 index 341027f..0000000 --- a/Directory.Build.targets +++ /dev/null @@ -1,3 +0,0 @@ - - - From 72fb7cc641bc7e264a435578e8c2a50d8417a0e1 Mon Sep 17 00:00:00 2001 From: Travis Illig Date: Fri, 29 May 2026 08:46:01 -0700 Subject: [PATCH 12/19] Spelling. --- .vscode/settings.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.vscode/settings.json b/.vscode/settings.json index 0a8ba99..41fbb23 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,6 @@ { + "cSpell.words": [ + "autofac" + ], "omnisharp.enableEditorConfigSupport": true } From b3ddbb0f36f0ca0b3a9426a58fa8c30ce09036c7 Mon Sep 17 00:00:00 2001 From: Travis Illig Date: Fri, 29 May 2026 08:46:13 -0700 Subject: [PATCH 13/19] Project cleanup. --- src/Autofac.Pooling/Autofac.Pooling.csproj | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Autofac.Pooling/Autofac.Pooling.csproj b/src/Autofac.Pooling/Autofac.Pooling.csproj index 6f4370d..7954479 100644 --- a/src/Autofac.Pooling/Autofac.Pooling.csproj +++ b/src/Autofac.Pooling/Autofac.Pooling.csproj @@ -34,19 +34,18 @@ true $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb - + + + - - - All @@ -58,7 +57,6 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - True @@ -76,7 +74,6 @@ RegistrationExtensionsResources.resx - ResXFileCodeGenerator @@ -91,5 +88,4 @@ RegistrationExtensionsResources.Designer.cs - From bba4ca033ab4f85eb1714ba67678000071868805 Mon Sep 17 00:00:00 2001 From: Travis Illig Date: Fri, 29 May 2026 08:46:27 -0700 Subject: [PATCH 14/19] Suppress false positive. --- src/Autofac.Pooling/PooledLifetime.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Autofac.Pooling/PooledLifetime.cs b/src/Autofac.Pooling/PooledLifetime.cs index bfed629..4398da7 100644 --- a/src/Autofac.Pooling/PooledLifetime.cs +++ b/src/Autofac.Pooling/PooledLifetime.cs @@ -8,6 +8,7 @@ namespace Autofac.Pooling; /// /// Lifetime wrapper to help us detect if we finished registering in a pooled configuration. /// +[SuppressMessage("S2094", "S2094", Justification = "Lifetimes are classes, not interfaces. Changing this would be a breaking change.")] public class PooledLifetime : CurrentScopeLifetime { } From f4c3b96df748a2c2c20833d4a65bec0417c9194a Mon Sep 17 00:00:00 2001 From: Travis Illig Date: Fri, 29 May 2026 08:46:40 -0700 Subject: [PATCH 15/19] Fix analyzer issues. --- test/Autofac.Pooling.Test/PolicyTests.cs | 4 +--- test/Autofac.Pooling.Test/Shared/OtherPooledComponent.cs | 6 +++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/test/Autofac.Pooling.Test/PolicyTests.cs b/test/Autofac.Pooling.Test/PolicyTests.cs index ab302c2..ad16ca4 100644 --- a/test/Autofac.Pooling.Test/PolicyTests.cs +++ b/test/Autofac.Pooling.Test/PolicyTests.cs @@ -144,11 +144,9 @@ public void PolicyCanSeeParametersFromThePooledServiceResolve() var container = builder.Build(); - IPooledService pooledInstance; - using (var scope = container.BeginLifetimeScope()) { - pooledInstance = scope.Resolve(new NamedParameter("Val1", 123), new TypedParameter(typeof(int), 456)); + var _ = scope.Resolve(new NamedParameter("Val1", 123), new TypedParameter(typeof(int), 456)); } Assert.Collection(policyReceivedParameters, diff --git a/test/Autofac.Pooling.Test/Shared/OtherPooledComponent.cs b/test/Autofac.Pooling.Test/Shared/OtherPooledComponent.cs index f30acbe..524baf9 100644 --- a/test/Autofac.Pooling.Test/Shared/OtherPooledComponent.cs +++ b/test/Autofac.Pooling.Test/Shared/OtherPooledComponent.cs @@ -2,9 +2,9 @@ public class OtherPooledComponent : IPooledService { - public int GetCalled => throw new System.NotImplementedException(); + public int GetCalled => 0; - public int ReturnCalled => throw new System.NotImplementedException(); + public int ReturnCalled => 0; - public int DisposeCalled => throw new System.NotImplementedException(); + public int DisposeCalled => 0; } From 67409697e6a306a09a2d8243ecd8f55442115c9a Mon Sep 17 00:00:00 2001 From: Travis Illig Date: Fri, 29 May 2026 08:50:08 -0700 Subject: [PATCH 16/19] Fix analyzer issues. --- .vscode/settings.json | 3 ++- test/Autofac.Pooling.Test/Autofac.Pooling.Test.csproj | 3 +++ test/Autofac.Pooling.Test/{Shared => Common}/IPooledService.cs | 2 +- .../{Shared => Common}/OtherPooledComponent.cs | 2 +- .../{Shared => Common}/PoolTrackingPolicy.cs | 2 +- .../Autofac.Pooling.Test/{Shared => Common}/PooledComponent.cs | 2 +- test/Autofac.Pooling.Test/ConcurrencyTests.cs | 2 +- test/Autofac.Pooling.Test/DisposableTests.cs | 2 +- test/Autofac.Pooling.Test/ImplicitRelationshipTests.cs | 2 +- test/Autofac.Pooling.Test/LifetimeScopeTests.cs | 2 +- test/Autofac.Pooling.Test/PolicyTests.cs | 2 +- test/Autofac.Pooling.Test/PooledComponentTests.cs | 2 +- test/Autofac.Pooling.Test/PoolingTests.cs | 2 +- test/Autofac.Pooling.Test/RegistrationExtensionsTests.cs | 3 ++- 14 files changed, 18 insertions(+), 13 deletions(-) rename test/Autofac.Pooling.Test/{Shared => Common}/IPooledService.cs (80%) rename test/Autofac.Pooling.Test/{Shared => Common}/OtherPooledComponent.cs (78%) rename test/Autofac.Pooling.Test/{Shared => Common}/PoolTrackingPolicy.cs (94%) rename test/Autofac.Pooling.Test/{Shared => Common}/PooledComponent.cs (93%) diff --git a/.vscode/settings.json b/.vscode/settings.json index 41fbb23..f7754b1 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,7 @@ { "cSpell.words": [ - "autofac" + "autofac", + "xunit" ], "omnisharp.enableEditorConfigSupport": true } diff --git a/test/Autofac.Pooling.Test/Autofac.Pooling.Test.csproj b/test/Autofac.Pooling.Test/Autofac.Pooling.Test.csproj index 8294f22..83c24e7 100644 --- a/test/Autofac.Pooling.Test/Autofac.Pooling.Test.csproj +++ b/test/Autofac.Pooling.Test/Autofac.Pooling.Test.csproj @@ -6,6 +6,9 @@ true false + + + all diff --git a/test/Autofac.Pooling.Test/Shared/IPooledService.cs b/test/Autofac.Pooling.Test/Common/IPooledService.cs similarity index 80% rename from test/Autofac.Pooling.Test/Shared/IPooledService.cs rename to test/Autofac.Pooling.Test/Common/IPooledService.cs index 144234e..951e569 100644 --- a/test/Autofac.Pooling.Test/Shared/IPooledService.cs +++ b/test/Autofac.Pooling.Test/Common/IPooledService.cs @@ -1,4 +1,4 @@ -namespace Autofac.Pooling.Tests.Shared; +namespace Autofac.Pooling.Tests.Common; public interface IPooledService { diff --git a/test/Autofac.Pooling.Test/Shared/OtherPooledComponent.cs b/test/Autofac.Pooling.Test/Common/OtherPooledComponent.cs similarity index 78% rename from test/Autofac.Pooling.Test/Shared/OtherPooledComponent.cs rename to test/Autofac.Pooling.Test/Common/OtherPooledComponent.cs index 524baf9..edbf163 100644 --- a/test/Autofac.Pooling.Test/Shared/OtherPooledComponent.cs +++ b/test/Autofac.Pooling.Test/Common/OtherPooledComponent.cs @@ -1,4 +1,4 @@ -namespace Autofac.Pooling.Tests.Shared; +namespace Autofac.Pooling.Tests.Common; public class OtherPooledComponent : IPooledService { diff --git a/test/Autofac.Pooling.Test/Shared/PoolTrackingPolicy.cs b/test/Autofac.Pooling.Test/Common/PoolTrackingPolicy.cs similarity index 94% rename from test/Autofac.Pooling.Test/Shared/PoolTrackingPolicy.cs rename to test/Autofac.Pooling.Test/Common/PoolTrackingPolicy.cs index 17b5992..7fa7cb3 100644 --- a/test/Autofac.Pooling.Test/Shared/PoolTrackingPolicy.cs +++ b/test/Autofac.Pooling.Test/Common/PoolTrackingPolicy.cs @@ -3,7 +3,7 @@ using System.Threading; using Autofac.Core; -namespace Autofac.Pooling.Tests.Shared; +namespace Autofac.Pooling.Tests.Common; public class PoolTrackingPolicy : DefaultPooledRegistrationPolicy where TLimit : class diff --git a/test/Autofac.Pooling.Test/Shared/PooledComponent.cs b/test/Autofac.Pooling.Test/Common/PooledComponent.cs similarity index 93% rename from test/Autofac.Pooling.Test/Shared/PooledComponent.cs rename to test/Autofac.Pooling.Test/Common/PooledComponent.cs index b745d81..0270eae 100644 --- a/test/Autofac.Pooling.Test/Shared/PooledComponent.cs +++ b/test/Autofac.Pooling.Test/Common/PooledComponent.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using Autofac.Core; -namespace Autofac.Pooling.Tests.Shared; +namespace Autofac.Pooling.Tests.Common; public class PooledComponent : IPooledService, IPooledComponent, IDisposable { diff --git a/test/Autofac.Pooling.Test/ConcurrencyTests.cs b/test/Autofac.Pooling.Test/ConcurrencyTests.cs index 7e391b6..7f2a8c7 100644 --- a/test/Autofac.Pooling.Test/ConcurrencyTests.cs +++ b/test/Autofac.Pooling.Test/ConcurrencyTests.cs @@ -5,7 +5,7 @@ using System.Threading; using System.Threading.Tasks; using Autofac.Core; -using Autofac.Pooling.Tests.Shared; +using Autofac.Pooling.Tests.Common; using Xunit; namespace Autofac.Pooling.Test; diff --git a/test/Autofac.Pooling.Test/DisposableTests.cs b/test/Autofac.Pooling.Test/DisposableTests.cs index cf59a18..d903072 100644 --- a/test/Autofac.Pooling.Test/DisposableTests.cs +++ b/test/Autofac.Pooling.Test/DisposableTests.cs @@ -1,5 +1,5 @@ using Autofac.Features.OwnedInstances; -using Autofac.Pooling.Tests.Shared; +using Autofac.Pooling.Tests.Common; using Xunit; namespace Autofac.Pooling.Test; diff --git a/test/Autofac.Pooling.Test/ImplicitRelationshipTests.cs b/test/Autofac.Pooling.Test/ImplicitRelationshipTests.cs index dd76982..29b2f97 100644 --- a/test/Autofac.Pooling.Test/ImplicitRelationshipTests.cs +++ b/test/Autofac.Pooling.Test/ImplicitRelationshipTests.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using Autofac.Features.Metadata; using Autofac.Features.OwnedInstances; -using Autofac.Pooling.Tests.Shared; +using Autofac.Pooling.Tests.Common; using Xunit; namespace Autofac.Pooling.Test; diff --git a/test/Autofac.Pooling.Test/LifetimeScopeTests.cs b/test/Autofac.Pooling.Test/LifetimeScopeTests.cs index 3116bed..2a2cc28 100644 --- a/test/Autofac.Pooling.Test/LifetimeScopeTests.cs +++ b/test/Autofac.Pooling.Test/LifetimeScopeTests.cs @@ -1,5 +1,5 @@ using Autofac.Core; -using Autofac.Pooling.Tests.Shared; +using Autofac.Pooling.Tests.Common; using Xunit; namespace Autofac.Pooling.Test; diff --git a/test/Autofac.Pooling.Test/PolicyTests.cs b/test/Autofac.Pooling.Test/PolicyTests.cs index ad16ca4..b3af42d 100644 --- a/test/Autofac.Pooling.Test/PolicyTests.cs +++ b/test/Autofac.Pooling.Test/PolicyTests.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Linq; using Autofac.Core; -using Autofac.Pooling.Tests.Shared; +using Autofac.Pooling.Tests.Common; using Xunit; namespace Autofac.Pooling.Test; diff --git a/test/Autofac.Pooling.Test/PooledComponentTests.cs b/test/Autofac.Pooling.Test/PooledComponentTests.cs index d511bd9..08fb98c 100644 --- a/test/Autofac.Pooling.Test/PooledComponentTests.cs +++ b/test/Autofac.Pooling.Test/PooledComponentTests.cs @@ -1,5 +1,5 @@ using Autofac.Features.OwnedInstances; -using Autofac.Pooling.Tests.Shared; +using Autofac.Pooling.Tests.Common; using Xunit; namespace Autofac.Pooling.Test; diff --git a/test/Autofac.Pooling.Test/PoolingTests.cs b/test/Autofac.Pooling.Test/PoolingTests.cs index 79d7cc6..dfdaed3 100644 --- a/test/Autofac.Pooling.Test/PoolingTests.cs +++ b/test/Autofac.Pooling.Test/PoolingTests.cs @@ -1,4 +1,4 @@ -using Autofac.Pooling.Tests.Shared; +using Autofac.Pooling.Tests.Common; using Xunit; namespace Autofac.Pooling.Tests; diff --git a/test/Autofac.Pooling.Test/RegistrationExtensionsTests.cs b/test/Autofac.Pooling.Test/RegistrationExtensionsTests.cs index 6a0505f..b3b7025 100644 --- a/test/Autofac.Pooling.Test/RegistrationExtensionsTests.cs +++ b/test/Autofac.Pooling.Test/RegistrationExtensionsTests.cs @@ -1,6 +1,6 @@ using System; using Autofac.Builder; -using Autofac.Pooling.Tests.Shared; +using Autofac.Pooling.Tests.Common; using Xunit; namespace Autofac.Pooling.Test; @@ -17,6 +17,7 @@ public void RequiresCallbackContainer() } [Fact] + [SuppressMessage("CA2000", "CA2000", Justification = "The container will dispose of the object.")] public void NoProvidedInstances() { var builder = new ContainerBuilder(); From ff26663c16d056b79bf16eb9d3dfea8f9e14f081 Mon Sep 17 00:00:00 2001 From: Travis Illig Date: Fri, 29 May 2026 08:53:34 -0700 Subject: [PATCH 17/19] Fix analyzer issues. --- .../Common/PooledComponent.cs | 2 ++ test/Autofac.Pooling.Test/ConcurrencyTests.cs | 25 +++++++++++++++++-- test/Autofac.Pooling.Test/PoolingTests.cs | 2 +- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/test/Autofac.Pooling.Test/Common/PooledComponent.cs b/test/Autofac.Pooling.Test/Common/PooledComponent.cs index 0270eae..ffbed02 100644 --- a/test/Autofac.Pooling.Test/Common/PooledComponent.cs +++ b/test/Autofac.Pooling.Test/Common/PooledComponent.cs @@ -4,6 +4,7 @@ namespace Autofac.Pooling.Tests.Common; +[SuppressMessage("CA1063", "CA1063", Justification = "Dispose remains simple here for testing.")] public class PooledComponent : IPooledService, IPooledComponent, IDisposable { public int GetCalled @@ -31,6 +32,7 @@ public void OnReturnToPool() ReturnCalled++; } + [SuppressMessage("CA1063", "CA1063", Justification = "Dispose remains simple here for testing.")] public void Dispose() { DisposeCalled++; diff --git a/test/Autofac.Pooling.Test/ConcurrencyTests.cs b/test/Autofac.Pooling.Test/ConcurrencyTests.cs index 7f2a8c7..a73c2e7 100644 --- a/test/Autofac.Pooling.Test/ConcurrencyTests.cs +++ b/test/Autofac.Pooling.Test/ConcurrencyTests.cs @@ -41,7 +41,7 @@ public async Task CanUsePoolConcurrentlyWithCustomPolicyToBlockOnMaxUsage() { var builder = new ContainerBuilder(); - var blockingPolicy = new BlockingPolicy(4); + using var blockingPolicy = new BlockingPolicy(4); builder.RegisterType().As() .PooledInstancePerLifetimeScope(blockingPolicy); @@ -60,10 +60,11 @@ await Task.WhenAll(Enumerable.Range(0, 10000).Select(i => Task.Run(() => container.Dispose(); } - private class BlockingPolicy : DefaultPooledRegistrationPolicy + private class BlockingPolicy : DefaultPooledRegistrationPolicy, IDisposable where TLimit : class { private readonly SemaphoreSlim _semaphore; + private bool _disposedValue; public BlockingPolicy(int maxConcurrentInstances) : base(maxConcurrentInstances) { @@ -87,5 +88,25 @@ public override bool Return(TLimit pooledObject) return base.Return(pooledObject); } + + protected virtual void Dispose(bool disposing) + { + if (!_disposedValue) + { + if (disposing) + { + _semaphore.Dispose(); + } + + _disposedValue = true; + } + } + + public void Dispose() + { + // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method + Dispose(disposing: true); + GC.SuppressFinalize(this); + } } } diff --git a/test/Autofac.Pooling.Test/PoolingTests.cs b/test/Autofac.Pooling.Test/PoolingTests.cs index dfdaed3..26a63a5 100644 --- a/test/Autofac.Pooling.Test/PoolingTests.cs +++ b/test/Autofac.Pooling.Test/PoolingTests.cs @@ -1,7 +1,7 @@ using Autofac.Pooling.Tests.Common; using Xunit; -namespace Autofac.Pooling.Tests; +namespace Autofac.Pooling.Test; public class PoolingTest { From 96337384c74f6df188a16ce4b423e258732bd413 Mon Sep 17 00:00:00 2001 From: Travis Illig Date: Fri, 29 May 2026 10:39:11 -0700 Subject: [PATCH 18/19] Disable CA2201 in Test.ruleset: tests use generic exceptions for simulation. --- build/Test.ruleset | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build/Test.ruleset b/build/Test.ruleset index cd29cf9..8559de5 100644 --- a/build/Test.ruleset +++ b/build/Test.ruleset @@ -39,6 +39,8 @@ + + From 7039f9dd844c0fa922c554939f8c43845513760f Mon Sep 17 00:00:00 2001 From: Travis Illig Date: Fri, 29 May 2026 12:58:33 -0700 Subject: [PATCH 19/19] Disable CA1711, CA1721, S125 in Test.ruleset. - CA1711: test classes commonly use suffixes like Impl, Handler, etc. - CA1721: test interfaces intentionally have properties matching methods. - S125: commented-out code in tests is acceptable for examples/notes. --- build/Test.ruleset | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/build/Test.ruleset b/build/Test.ruleset index 8559de5..b64a37a 100644 --- a/build/Test.ruleset +++ b/build/Test.ruleset @@ -23,6 +23,10 @@ + + + + @@ -55,6 +59,8 @@ + +