From b7b3b04041168b1a9290e5f47e47bb929dd65864 Mon Sep 17 00:00:00 2001 From: Travis Illig Date: Thu, 28 May 2026 12:36:06 -0700 Subject: [PATCH 1/8] 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 +++++++++++++----- .../Autofac.Integration.ServiceFabric.csproj | 5 + ...ofac.Integration.ServiceFabric.Test.csproj | 6 + .../Test.Scenario.InternalsVisible.csproj | 6 + 5 files changed, 121 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.Integration.ServiceFabric/Autofac.Integration.ServiceFabric.csproj b/src/Autofac.Integration.ServiceFabric/Autofac.Integration.ServiceFabric.csproj index 85244ca..d18354a 100644 --- a/src/Autofac.Integration.ServiceFabric/Autofac.Integration.ServiceFabric.csproj +++ b/src/Autofac.Integration.ServiceFabric/Autofac.Integration.ServiceFabric.csproj @@ -21,6 +21,7 @@ true ../../build/Source.ruleset AllEnabledByDefault + true enable x64 @@ -68,6 +69,10 @@ all + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/test/Autofac.Integration.ServiceFabric.Test/Autofac.Integration.ServiceFabric.Test.csproj b/test/Autofac.Integration.ServiceFabric.Test/Autofac.Integration.ServiceFabric.Test.csproj index a9d428a..074c242 100644 --- a/test/Autofac.Integration.ServiceFabric.Test/Autofac.Integration.ServiceFabric.Test.csproj +++ b/test/Autofac.Integration.ServiceFabric.Test/Autofac.Integration.ServiceFabric.Test.csproj @@ -8,6 +8,8 @@ ../../Autofac.snk true ../../build/Test.ruleset + AllEnabledByDefault + true false latest enable @@ -47,6 +49,10 @@ all + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + all diff --git a/test/Test.Scenario.InternalsVisible/Test.Scenario.InternalsVisible.csproj b/test/Test.Scenario.InternalsVisible/Test.Scenario.InternalsVisible.csproj index 547f496..13c0dbd 100644 --- a/test/Test.Scenario.InternalsVisible/Test.Scenario.InternalsVisible.csproj +++ b/test/Test.Scenario.InternalsVisible/Test.Scenario.InternalsVisible.csproj @@ -6,6 +6,8 @@ ../../Autofac.snk true ../../build/Test.ruleset + AllEnabledByDefault + true false latest @@ -16,6 +18,10 @@ + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + From b4c5a0b01140b7b14dfe338528140409eaa97c41 Mon Sep 17 00:00:00 2001 From: Travis Illig Date: Thu, 28 May 2026 13:49:26 -0700 Subject: [PATCH 2/8] Fix S927: rename parameters to match interface declarations. --- .../ActorFactoryRegistration.cs | 6 +++--- .../StatefulServiceFactoryRegistration.cs | 4 ++-- .../StatelessServiceFactoryRegistration.cs | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Autofac.Integration.ServiceFabric/ActorFactoryRegistration.cs b/src/Autofac.Integration.ServiceFabric/ActorFactoryRegistration.cs index 73dfc57..a7307c3 100644 --- a/src/Autofac.Integration.ServiceFabric/ActorFactoryRegistration.cs +++ b/src/Autofac.Integration.ServiceFabric/ActorFactoryRegistration.cs @@ -46,7 +46,7 @@ internal Action ConfigurationAction /// public void RegisterActorFactory( - ILifetimeScope container, + ILifetimeScope lifetimeScope, Type actorServiceType, Func? stateManagerFactory = null, IActorStateProvider? stateProvider = null, @@ -59,7 +59,7 @@ public void RegisterActorFactory( ActorBase ActorFactory(ActorService actorService, ActorId actorId) { var tag = lifetimeScopeTag ?? Constants.DefaultLifetimeScopeTag; - var lifetimeScope = container.BeginLifetimeScope(tag, builder => + var lifetimeScope = lifetimeScope.BeginLifetimeScope(tag, builder => { builder.RegisterInstance(context) .As() @@ -87,7 +87,7 @@ ActorBase ActorFactory(ActorService actorService, ActorId actorId) } } - return (ActorService)container.Resolve( + return (ActorService)lifetimeScope.Resolve( actorServiceType, new TypedParameter(typeof(StatefulServiceContext), context), new TypedParameter(typeof(ActorTypeInformation), actorTypeInfo), diff --git a/src/Autofac.Integration.ServiceFabric/StatefulServiceFactoryRegistration.cs b/src/Autofac.Integration.ServiceFabric/StatefulServiceFactoryRegistration.cs index 3e231b4..6faba93 100644 --- a/src/Autofac.Integration.ServiceFabric/StatefulServiceFactoryRegistration.cs +++ b/src/Autofac.Integration.ServiceFabric/StatefulServiceFactoryRegistration.cs @@ -45,13 +45,13 @@ internal Action ConfigurationAction /// public void RegisterStatefulServiceFactory( - ILifetimeScope container, string serviceTypeName, object? lifetimeScopeTag = null) + ILifetimeScope lifetimeScope, string serviceTypeName, object? lifetimeScopeTag = null) where TService : StatefulServiceBase { ServiceRuntime.RegisterServiceAsync(serviceTypeName, context => { var tag = lifetimeScopeTag ?? Constants.DefaultLifetimeScopeTag; - var lifetimeScope = container.BeginLifetimeScope(tag, builder => + var lifetimeScope = lifetimeScope.BeginLifetimeScope(tag, builder => { builder.RegisterInstance(context) .As() diff --git a/src/Autofac.Integration.ServiceFabric/StatelessServiceFactoryRegistration.cs b/src/Autofac.Integration.ServiceFabric/StatelessServiceFactoryRegistration.cs index 958af1a..86a4ea3 100644 --- a/src/Autofac.Integration.ServiceFabric/StatelessServiceFactoryRegistration.cs +++ b/src/Autofac.Integration.ServiceFabric/StatelessServiceFactoryRegistration.cs @@ -45,13 +45,13 @@ internal Action ConfigurationAction /// public void RegisterStatelessServiceFactory( - ILifetimeScope container, string serviceTypeName, object? lifetimeScopeTag = null) + ILifetimeScope lifetimeScope, string serviceTypeName, object? lifetimeScopeTag = null) where TService : StatelessService { ServiceRuntime.RegisterServiceAsync(serviceTypeName, context => { var tag = lifetimeScopeTag ?? Constants.DefaultLifetimeScopeTag; - var lifetimeScope = container.BeginLifetimeScope(tag, builder => + var lifetimeScope = lifetimeScope.BeginLifetimeScope(tag, builder => { builder.RegisterInstance(context) .As() From 51d54349dfec08fd3817c054d3f9a74c81e2d276 Mon Sep 17 00:00:00 2001 From: Travis Illig Date: Thu, 28 May 2026 14:44:07 -0700 Subject: [PATCH 3/8] 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 8f13f97ae000c2a68f3f9bcf46322e9af3700c51 Mon Sep 17 00:00:00 2001 From: Travis Illig Date: Thu, 28 May 2026 17:45:29 -0700 Subject: [PATCH 4/8] 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 b7fa73f1c4471eba3dcb4ef2bbbe3b076a379af0 Mon Sep 17 00:00:00 2001 From: Travis Illig Date: Fri, 29 May 2026 07:19:26 -0700 Subject: [PATCH 5/8] 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 6a99a685797e365a390c8fcbe24746c9fc89cd72 Mon Sep 17 00:00:00 2001 From: Travis Illig Date: Fri, 29 May 2026 10:38:08 -0700 Subject: [PATCH 6/8] Fix S927 shadowing: rename local variable to avoid parameter name conflict. The S927 fix renamed parameters to match their interface declarations, but the method bodies had local variables with the same name, causing CS0841 errors. Renamed the locals to 'serviceScope' to disambiguate. --- .../ActorFactoryRegistration.cs | 6 +++--- .../StatefulServiceFactoryRegistration.cs | 6 +++--- .../StatelessServiceFactoryRegistration.cs | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Autofac.Integration.ServiceFabric/ActorFactoryRegistration.cs b/src/Autofac.Integration.ServiceFabric/ActorFactoryRegistration.cs index a7307c3..206e3d6 100644 --- a/src/Autofac.Integration.ServiceFabric/ActorFactoryRegistration.cs +++ b/src/Autofac.Integration.ServiceFabric/ActorFactoryRegistration.cs @@ -59,7 +59,7 @@ public void RegisterActorFactory( ActorBase ActorFactory(ActorService actorService, ActorId actorId) { var tag = lifetimeScopeTag ?? Constants.DefaultLifetimeScopeTag; - var lifetimeScope = lifetimeScope.BeginLifetimeScope(tag, builder => + var serviceScope = lifetimeScope.BeginLifetimeScope(tag, builder => { builder.RegisterInstance(context) .As() @@ -74,13 +74,13 @@ ActorBase ActorFactory(ActorService actorService, ActorId actorId) try { - var actor = lifetimeScope.Resolve(); + var actor = serviceScope.Resolve(); return actor; } catch (Exception ex) { // Proactively dispose lifetime scope as interceptor will not be called. - lifetimeScope.Dispose(); + serviceScope.Dispose(); ConstructorExceptionCallback(ex); throw; diff --git a/src/Autofac.Integration.ServiceFabric/StatefulServiceFactoryRegistration.cs b/src/Autofac.Integration.ServiceFabric/StatefulServiceFactoryRegistration.cs index 6faba93..c3952d4 100644 --- a/src/Autofac.Integration.ServiceFabric/StatefulServiceFactoryRegistration.cs +++ b/src/Autofac.Integration.ServiceFabric/StatefulServiceFactoryRegistration.cs @@ -51,7 +51,7 @@ public void RegisterStatefulServiceFactory( ServiceRuntime.RegisterServiceAsync(serviceTypeName, context => { var tag = lifetimeScopeTag ?? Constants.DefaultLifetimeScopeTag; - var lifetimeScope = lifetimeScope.BeginLifetimeScope(tag, builder => + var serviceScope = lifetimeScope.BeginLifetimeScope(tag, builder => { builder.RegisterInstance(context) .As() @@ -62,13 +62,13 @@ public void RegisterStatefulServiceFactory( try { - var service = lifetimeScope.Resolve(); + var service = serviceScope.Resolve(); return service; } catch (Exception ex) { // Proactively dispose lifetime scope as interceptor will not be called. - lifetimeScope.Dispose(); + serviceScope.Dispose(); ConstructorExceptionCallback(ex); throw; diff --git a/src/Autofac.Integration.ServiceFabric/StatelessServiceFactoryRegistration.cs b/src/Autofac.Integration.ServiceFabric/StatelessServiceFactoryRegistration.cs index 86a4ea3..d4492e9 100644 --- a/src/Autofac.Integration.ServiceFabric/StatelessServiceFactoryRegistration.cs +++ b/src/Autofac.Integration.ServiceFabric/StatelessServiceFactoryRegistration.cs @@ -51,7 +51,7 @@ public void RegisterStatelessServiceFactory( ServiceRuntime.RegisterServiceAsync(serviceTypeName, context => { var tag = lifetimeScopeTag ?? Constants.DefaultLifetimeScopeTag; - var lifetimeScope = lifetimeScope.BeginLifetimeScope(tag, builder => + var serviceScope = lifetimeScope.BeginLifetimeScope(tag, builder => { builder.RegisterInstance(context) .As() @@ -62,13 +62,13 @@ public void RegisterStatelessServiceFactory( try { - var service = lifetimeScope.Resolve(); + var service = serviceScope.Resolve(); return service; } catch (Exception ex) { // Proactively dispose lifetime scope as interceptor will not be called. - lifetimeScope.Dispose(); + serviceScope.Dispose(); ConstructorExceptionCallback(ex); throw; From 9bfb3551e5779ba8c490f74af47e6db2ad36ebb4 Mon Sep 17 00:00:00 2001 From: Travis Illig Date: Fri, 29 May 2026 10:39:40 -0700 Subject: [PATCH 7/8] 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 a2976f52e48792f28bafdac13216989afc3fcf69 Mon Sep 17 00:00:00 2001 From: Travis Illig Date: Fri, 29 May 2026 12:58:34 -0700 Subject: [PATCH 8/8] 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 @@ + +