From f8444e85b881045b2abc8773d1f52e88fa68fae9 Mon Sep 17 00:00:00 2001 From: Travis Illig Date: Tue, 7 Nov 2023 07:23:09 -0800 Subject: [PATCH 01/12] Use C# dev kit in VS Code. --- .vscode/extensions.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 767b23afb..8fde6762d 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,7 +1,6 @@ { "recommendations": [ - "formulahendry.dotnet-test-explorer", - "ms-dotnettools.csharp", + "ms-dotnettools.csdevkit", "editorconfig.editorconfig", "davidanson.vscode-markdownlint" ] From 6a885d34520598d1035df5ad7f7f3cb4283a3e50 Mon Sep 17 00:00:00 2001 From: Travis Illig Date: Tue, 7 Nov 2023 07:39:06 -0800 Subject: [PATCH 02/12] global.json - drop net3.1, add net8.0. --- global.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/global.json b/global.json index 0b64d5377..1ca03a8ac 100644 --- a/global.json +++ b/global.json @@ -1,11 +1,11 @@ { "sdk": { - "version": "7.0.203", + "version": "8.0.100-rc.2.23502.2", "rollForward": "latestFeature" }, "additionalSdks": [ - "3.1.426", - "6.0.408" + "6.0.416", + "7.0.403" ] } From 4154d4ed0d4896d3110572f2124c6c5d79f3c7ee Mon Sep 17 00:00:00 2001 From: Travis Illig Date: Tue, 7 Nov 2023 07:39:41 -0800 Subject: [PATCH 03/12] Update settings for C# dev kit. --- .vscode/settings.json | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index a562a4df1..400802825 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -14,14 +14,13 @@ "startable", "subclassing", "typeparam", + "unconfigured", "xunit" ], - "dotnet-test-explorer.testProjectPath": "test/**/*Test.csproj", "dotnet.defaultSolution": "Autofac.sln", "explorer.fileNesting.enabled": true, "explorer.fileNesting.patterns": { "*.resx": "$(capture).*.resx, $(capture).designer.cs, $(capture).designer.vb" }, - "omnisharp.enableEditorConfigSupport": true, - "omnisharp.enableRoslynAnalyzers": true + "omnisharp.enableEditorConfigSupport": true } From d28d636ef94602a97aff3250a47eaf9a1b601335 Mon Sep 17 00:00:00 2001 From: Travis Illig Date: Tue, 7 Nov 2023 07:41:01 -0800 Subject: [PATCH 04/12] Drop net3.1, add net8.0, update all dependencies. --- .../Autofac.BenchmarkProfiling.csproj | 2 +- .../Autofac.Benchmarks.csproj | 8 ++++---- codegen/Autofac.CodeGen/Autofac.CodeGen.csproj | 5 +++-- src/Autofac/Autofac.csproj | 6 +++--- .../Autofac.Specification.Test.csproj | 16 ++++++++-------- .../Autofac.Test.CodeGen.csproj | 18 +++++++++--------- .../Autofac.Test.Compilation.csproj | 16 ++++++++-------- .../Autofac.Test.Scenarios.LoadContext.csproj | 2 +- ...tofac.Test.Scenarios.ScannedAssembly.csproj | 2 +- test/Autofac.Test/Autofac.Test.csproj | 14 +++++++------- 10 files changed, 45 insertions(+), 44 deletions(-) diff --git a/bench/Autofac.BenchmarkProfiling/Autofac.BenchmarkProfiling.csproj b/bench/Autofac.BenchmarkProfiling/Autofac.BenchmarkProfiling.csproj index 34b649755..895dfe07e 100644 --- a/bench/Autofac.BenchmarkProfiling/Autofac.BenchmarkProfiling.csproj +++ b/bench/Autofac.BenchmarkProfiling/Autofac.BenchmarkProfiling.csproj @@ -8,7 +8,7 @@ - + diff --git a/bench/Autofac.Benchmarks/Autofac.Benchmarks.csproj b/bench/Autofac.Benchmarks/Autofac.Benchmarks.csproj index c519fb16b..8ae556ef3 100644 --- a/bench/Autofac.Benchmarks/Autofac.Benchmarks.csproj +++ b/bench/Autofac.Benchmarks/Autofac.Benchmarks.csproj @@ -34,10 +34,10 @@ - - - - + + + + all runtime; build; native; contentfiles; analyzers diff --git a/codegen/Autofac.CodeGen/Autofac.CodeGen.csproj b/codegen/Autofac.CodeGen/Autofac.CodeGen.csproj index 28e5edbdd..0830a6d15 100644 --- a/codegen/Autofac.CodeGen/Autofac.CodeGen.csproj +++ b/codegen/Autofac.CodeGen/Autofac.CodeGen.csproj @@ -12,6 +12,7 @@ AllEnabledByDefault enable true + true @@ -23,8 +24,8 @@ - - + + diff --git a/src/Autofac/Autofac.csproj b/src/Autofac/Autofac.csproj index 0644169f1..8868843c4 100644 --- a/src/Autofac/Autofac.csproj +++ b/src/Autofac/Autofac.csproj @@ -75,14 +75,14 @@ all - + all - + - + diff --git a/test/Autofac.Specification.Test/Autofac.Specification.Test.csproj b/test/Autofac.Specification.Test/Autofac.Specification.Test.csproj index 5466de525..c44d90624 100644 --- a/test/Autofac.Specification.Test/Autofac.Specification.Test.csproj +++ b/test/Autofac.Specification.Test/Autofac.Specification.Test.csproj @@ -1,7 +1,7 @@  - net7.0;net6.0;netcoreapp3.1; + net8.0;net7.0;net6.0; $(NoWarn);CS1591 true ../../build/Test.ruleset @@ -22,7 +22,7 @@ - + false @@ -34,20 +34,20 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + all - - + + all runtime; build; native; contentfiles; analyzers diff --git a/test/Autofac.Test.CodeGen/Autofac.Test.CodeGen.csproj b/test/Autofac.Test.CodeGen/Autofac.Test.CodeGen.csproj index 52e85d1b6..40964862d 100644 --- a/test/Autofac.Test.CodeGen/Autofac.Test.CodeGen.csproj +++ b/test/Autofac.Test.CodeGen/Autofac.Test.CodeGen.csproj @@ -34,26 +34,26 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + + all - - + + all runtime; build; native; contentfiles; analyzers - - + + diff --git a/test/Autofac.Test.Compilation/Autofac.Test.Compilation.csproj b/test/Autofac.Test.Compilation/Autofac.Test.Compilation.csproj index a3cea5038..7d86d54de 100644 --- a/test/Autofac.Test.Compilation/Autofac.Test.Compilation.csproj +++ b/test/Autofac.Test.Compilation/Autofac.Test.Compilation.csproj @@ -1,7 +1,7 @@  - net7.0;net6.0;netcoreapp3.1; + net8.0;net7.0;net6.0; $(NoWarn);CS1591 true ../../Autofac.snk @@ -33,21 +33,21 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + + all - - + + all runtime; build; native; contentfiles; analyzers diff --git a/test/Autofac.Test.Scenarios.LoadContext/Autofac.Test.Scenarios.LoadContext.csproj b/test/Autofac.Test.Scenarios.LoadContext/Autofac.Test.Scenarios.LoadContext.csproj index fedb2ce3f..453e935f9 100644 --- a/test/Autofac.Test.Scenarios.LoadContext/Autofac.Test.Scenarios.LoadContext.csproj +++ b/test/Autofac.Test.Scenarios.LoadContext/Autofac.Test.Scenarios.LoadContext.csproj @@ -13,7 +13,7 @@ - + all diff --git a/test/Autofac.Test.Scenarios.ScannedAssembly/Autofac.Test.Scenarios.ScannedAssembly.csproj b/test/Autofac.Test.Scenarios.ScannedAssembly/Autofac.Test.Scenarios.ScannedAssembly.csproj index 13cff2866..133583104 100644 --- a/test/Autofac.Test.Scenarios.ScannedAssembly/Autofac.Test.Scenarios.ScannedAssembly.csproj +++ b/test/Autofac.Test.Scenarios.ScannedAssembly/Autofac.Test.Scenarios.ScannedAssembly.csproj @@ -14,7 +14,7 @@ - + all diff --git a/test/Autofac.Test/Autofac.Test.csproj b/test/Autofac.Test/Autofac.Test.csproj index 75a863e68..97b30bb94 100644 --- a/test/Autofac.Test/Autofac.Test.csproj +++ b/test/Autofac.Test/Autofac.Test.csproj @@ -1,7 +1,7 @@  - net7.0;net6.0;netcoreapp3.1; + net8.0;net7.0;net6.0; $(NoWarn);CS1591 true ../../Autofac.snk @@ -35,21 +35,21 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + - + all - - + + all runtime; build; native; contentfiles; analyzers From 25844a9501de8860845dac0b67da102d9e56309e Mon Sep 17 00:00:00 2001 From: Travis Illig Date: Tue, 7 Nov 2023 07:44:17 -0800 Subject: [PATCH 05/12] Fix analyzer warnings from updated dependencies. --- bench/Autofac.Benchmarks/ConcurrencyBenchmark.cs | 2 +- .../Autofac.Benchmarks/ConcurrencyNestedScopeBenchmark.cs | 2 +- test/Autofac.Test/Concurrency/ConcurrencyTests.cs | 4 ++-- test/Autofac.Test/Core/ContainerTests.cs | 2 +- test/Autofac.Test/Core/DisposerTests.cs | 8 ++++---- test/Autofac.Test/Core/Lifetime/LifetimeScopeTests.cs | 2 +- test/Autofac.Test/ModuleTests.cs | 8 ++++---- test/Autofac.Test/TagsFixture.cs | 2 +- test/Autofac.Test/Util/FallbackDictionaryTests.cs | 2 +- 9 files changed, 16 insertions(+), 16 deletions(-) diff --git a/bench/Autofac.Benchmarks/ConcurrencyBenchmark.cs b/bench/Autofac.Benchmarks/ConcurrencyBenchmark.cs index e55831678..3d3574a81 100644 --- a/bench/Autofac.Benchmarks/ConcurrencyBenchmark.cs +++ b/bench/Autofac.Benchmarks/ConcurrencyBenchmark.cs @@ -45,7 +45,7 @@ public async Task MultipleResolvesOnMultipleTasks() } catch (Exception ex) { - Assert.True(false, ex.ToString()); + Assert.Fail(ex.ToString()); } }); tasks.Add(task); diff --git a/bench/Autofac.Benchmarks/ConcurrencyNestedScopeBenchmark.cs b/bench/Autofac.Benchmarks/ConcurrencyNestedScopeBenchmark.cs index 825fc159d..db20d65d3 100644 --- a/bench/Autofac.Benchmarks/ConcurrencyNestedScopeBenchmark.cs +++ b/bench/Autofac.Benchmarks/ConcurrencyNestedScopeBenchmark.cs @@ -55,7 +55,7 @@ public async Task MultipleResolvesOnMultipleTasks() } catch (Exception ex) { - Assert.True(false, ex.ToString()); + Assert.Fail(ex.ToString()); } }); tasks.Add(task); diff --git a/test/Autofac.Test/Concurrency/ConcurrencyTests.cs b/test/Autofac.Test/Concurrency/ConcurrencyTests.cs index 5138f743b..3d7fbcf63 100644 --- a/test/Autofac.Test/Concurrency/ConcurrencyTests.cs +++ b/test/Autofac.Test/Concurrency/ConcurrencyTests.cs @@ -45,11 +45,11 @@ public void ConcurrentResolveOperationsForNonSharedInstancesFromDifferentLifetim } [Fact] - public void ConcurrentResolveOperationsFromDifferentContainers_DoesNotThrow() + public async Task ConcurrentResolveOperationsFromDifferentContainers_DoesNotThrow() { var task1 = Task.Factory.StartNew(ResolveObjectInstanceLoop); var task2 = Task.Factory.StartNew(ResolveObjectInstanceLoop); - Task.WaitAll(task1, task2); + await Task.WhenAll(task1, task2); } [Fact] diff --git a/test/Autofac.Test/Core/ContainerTests.cs b/test/Autofac.Test/Core/ContainerTests.cs index 9fe7e2ede..899a53a64 100644 --- a/test/Autofac.Test/Core/ContainerTests.cs +++ b/test/Autofac.Test/Core/ContainerTests.cs @@ -182,7 +182,7 @@ public void ReplaceInstance_ModuleActivatingHandlerProvidesResultToRelease() } [Fact] - public async ValueTask AsyncContainerDisposeTriggersAsyncServiceDispose() + public async Task AsyncContainerDisposeTriggersAsyncServiceDispose() { var builder = new ContainerBuilder(); builder.Register(c => new AsyncDisposeTracker()).SingleInstance(); diff --git a/test/Autofac.Test/Core/DisposerTests.cs b/test/Autofac.Test/Core/DisposerTests.cs index bd141d5b4..037d9ec7b 100644 --- a/test/Autofac.Test/Core/DisposerTests.cs +++ b/test/Autofac.Test/Core/DisposerTests.cs @@ -58,7 +58,7 @@ public void CannotAddObjectsToDisposerAfterSyncDispose() } [Fact] - public async ValueTask DisposerDisposesOfObjectsAsyncIfIAsyncDisposableDeclared() + public async Task DisposerDisposesOfObjectsAsyncIfIAsyncDisposableDeclared() { var instance = new AsyncDisposeTracker(); @@ -80,7 +80,7 @@ public async ValueTask DisposerDisposesOfObjectsAsyncIfIAsyncDisposableDeclared( } [Fact] - public async ValueTask DisposerDisposesOfObjectsSyncIfIDisposableOnly() + public async Task DisposerDisposesOfObjectsSyncIfIDisposableOnly() { var instance = new DisposeTracker(); @@ -106,7 +106,7 @@ public void DisposerDisposesOfObjectsSyncIfIAsyncDisposableDeclaredButSyncDispos } [Fact] - public async ValueTask CannotAddObjectsToDisposerAfterAsyncDispose() + public async Task CannotAddObjectsToDisposerAfterAsyncDispose() { var instance = new AsyncDisposeTracker(); @@ -138,7 +138,7 @@ public void SyncDisposalOnObjectWithNoIDisposableCanDispose() } [Fact] - public async ValueTask DisposerAsyncDisposesContainedInstances_InReverseOfOrderAdded() + public async Task DisposerAsyncDisposesContainedInstances_InReverseOfOrderAdded() { var disposeOrder = new List(); diff --git a/test/Autofac.Test/Core/Lifetime/LifetimeScopeTests.cs b/test/Autofac.Test/Core/Lifetime/LifetimeScopeTests.cs index 8a3df5f69..2eb93c024 100644 --- a/test/Autofac.Test/Core/Lifetime/LifetimeScopeTests.cs +++ b/test/Autofac.Test/Core/Lifetime/LifetimeScopeTests.cs @@ -73,7 +73,7 @@ public void NestedLifetimeScopesMaintainServiceLimitTypes() } [Fact] - public async ValueTask AsyncDisposeLifetimeScopeDisposesRegistrationsAsync() + public async Task AsyncDisposeLifetimeScopeDisposesRegistrationsAsync() { var cb = new ContainerBuilder(); diff --git a/test/Autofac.Test/ModuleTests.cs b/test/Autofac.Test/ModuleTests.cs index 12c685b33..2d90b3b55 100644 --- a/test/Autofac.Test/ModuleTests.cs +++ b/test/Autofac.Test/ModuleTests.cs @@ -49,7 +49,7 @@ protected override void AttachToComponentRegistration(IComponentRegistryBuilder public void AttachesToRegistrations() { var attachingModule = new AttachingModule(); - Assert.Equal(0, attachingModule.Registrations.Count); + Assert.Empty(attachingModule.Registrations); var builder = new ContainerBuilder(); builder.RegisterType(typeof(Service1)); @@ -65,7 +65,7 @@ public void AttachesToRegistrations() public void AttachesToRegistrationsInScope() { var attachingModule = new AttachingModule(); - Assert.Equal(0, attachingModule.Registrations.Count); + Assert.Empty(attachingModule.Registrations); var builder = new ContainerBuilder(); builder.RegisterModule(attachingModule); @@ -82,7 +82,7 @@ public void AttachesToRegistrationsInScope() public void AttachesToRegistrationsInNestedScope() { var attachingModule = new AttachingModule(); - Assert.Equal(0, attachingModule.Registrations.Count); + Assert.Empty(attachingModule.Registrations); var builder = new ContainerBuilder(); builder.RegisterModule(attachingModule); @@ -101,7 +101,7 @@ public void AttachesToRegistrationsInNestedScope() public void ModifiedScopesHaveTheirOwnDelegate() { var attachingModule = new AttachingModule(); - Assert.Equal(0, attachingModule.Registrations.Count); + Assert.Empty(attachingModule.Registrations); var builder = new ContainerBuilder(); builder.RegisterModule(attachingModule); diff --git a/test/Autofac.Test/TagsFixture.cs b/test/Autofac.Test/TagsFixture.cs index 774429780..35e68b8fa 100644 --- a/test/Autofac.Test/TagsFixture.cs +++ b/test/Autofac.Test/TagsFixture.cs @@ -52,7 +52,7 @@ public void CollectionsAreTaggable() var inner = outer.BeginLifetimeScope("tag"); var coll = inner.Resolve>(); - Assert.Equal(1, coll.Count); + Assert.Single(coll); Assert.Throws(() => outer.Resolve>()); } diff --git a/test/Autofac.Test/Util/FallbackDictionaryTests.cs b/test/Autofac.Test/Util/FallbackDictionaryTests.cs index 8fee3f26d..66e0348ec 100644 --- a/test/Autofac.Test/Util/FallbackDictionaryTests.cs +++ b/test/Autofac.Test/Util/FallbackDictionaryTests.cs @@ -202,7 +202,7 @@ public void GetEnumerator_UsesOverrides() public void Keys_Empty() { var dict = new FallbackDictionary(); - Assert.Equal(0, dict.Keys.Count); + Assert.Empty(dict.Keys); } [Fact] From 6e3510e0cda9851cae62def2d106bd738905596a Mon Sep 17 00:00:00 2001 From: Travis Illig Date: Tue, 7 Nov 2023 07:44:31 -0800 Subject: [PATCH 06/12] Add net8 to codegen tests. --- test/Autofac.Test.CodeGen/Autofac.Test.CodeGen.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Autofac.Test.CodeGen/Autofac.Test.CodeGen.csproj b/test/Autofac.Test.CodeGen/Autofac.Test.CodeGen.csproj index 40964862d..85ec16723 100644 --- a/test/Autofac.Test.CodeGen/Autofac.Test.CodeGen.csproj +++ b/test/Autofac.Test.CodeGen/Autofac.Test.CodeGen.csproj @@ -1,7 +1,7 @@  - net6.0 + net8.0;net7.0;net6.0; $(NoWarn);CS1591 true ../../Autofac.snk From e5e5f1d4e8324ac52cafe4ed7869fa70fd71bbb9 Mon Sep 17 00:00:00 2001 From: Travis Illig Date: Tue, 7 Nov 2023 07:50:14 -0800 Subject: [PATCH 07/12] Cleaned up target frameworks. --- src/Autofac/Autofac.csproj | 2 +- .../Autofac.Specification.Test.csproj | 2 +- test/Autofac.Test.CodeGen/Autofac.Test.CodeGen.csproj | 2 +- test/Autofac.Test.Compilation/Autofac.Test.Compilation.csproj | 2 +- .../Autofac.Test.Scenarios.LoadContext.csproj | 2 +- test/Autofac.Test/Autofac.Test.csproj | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Autofac/Autofac.csproj b/src/Autofac/Autofac.csproj index 8868843c4..3628b203b 100644 --- a/src/Autofac/Autofac.csproj +++ b/src/Autofac/Autofac.csproj @@ -15,7 +15,7 @@ true en-US - net7.0;net6.0;netstandard2.1;netstandard2.0; + net8.0;net7.0;net6.0;netstandard2.1;netstandard2.0 latest enable $(NoWarn);CS1591 diff --git a/test/Autofac.Specification.Test/Autofac.Specification.Test.csproj b/test/Autofac.Specification.Test/Autofac.Specification.Test.csproj index c44d90624..9723254d6 100644 --- a/test/Autofac.Specification.Test/Autofac.Specification.Test.csproj +++ b/test/Autofac.Specification.Test/Autofac.Specification.Test.csproj @@ -1,7 +1,7 @@  - net8.0;net7.0;net6.0; + net8.0;net7.0;net6.0 $(NoWarn);CS1591 true ../../build/Test.ruleset diff --git a/test/Autofac.Test.CodeGen/Autofac.Test.CodeGen.csproj b/test/Autofac.Test.CodeGen/Autofac.Test.CodeGen.csproj index 85ec16723..6a4b7405a 100644 --- a/test/Autofac.Test.CodeGen/Autofac.Test.CodeGen.csproj +++ b/test/Autofac.Test.CodeGen/Autofac.Test.CodeGen.csproj @@ -1,7 +1,7 @@  - net8.0;net7.0;net6.0; + net8.0;net7.0;net6.0 $(NoWarn);CS1591 true ../../Autofac.snk diff --git a/test/Autofac.Test.Compilation/Autofac.Test.Compilation.csproj b/test/Autofac.Test.Compilation/Autofac.Test.Compilation.csproj index 7d86d54de..fa2c8e6ef 100644 --- a/test/Autofac.Test.Compilation/Autofac.Test.Compilation.csproj +++ b/test/Autofac.Test.Compilation/Autofac.Test.Compilation.csproj @@ -1,7 +1,7 @@  - net8.0;net7.0;net6.0; + net8.0;net7.0;net6.0 $(NoWarn);CS1591 true ../../Autofac.snk diff --git a/test/Autofac.Test.Scenarios.LoadContext/Autofac.Test.Scenarios.LoadContext.csproj b/test/Autofac.Test.Scenarios.LoadContext/Autofac.Test.Scenarios.LoadContext.csproj index 453e935f9..6789ff1db 100644 --- a/test/Autofac.Test.Scenarios.LoadContext/Autofac.Test.Scenarios.LoadContext.csproj +++ b/test/Autofac.Test.Scenarios.LoadContext/Autofac.Test.Scenarios.LoadContext.csproj @@ -1,7 +1,7 @@ - net7.0;net6.0 + net8.0;net7.0;net6.0 $(NoWarn);CS1591 true false diff --git a/test/Autofac.Test/Autofac.Test.csproj b/test/Autofac.Test/Autofac.Test.csproj index 97b30bb94..fd6b61eff 100644 --- a/test/Autofac.Test/Autofac.Test.csproj +++ b/test/Autofac.Test/Autofac.Test.csproj @@ -1,7 +1,7 @@  - net8.0;net7.0;net6.0; + net8.0;net7.0;net6.0 $(NoWarn);CS1591 true ../../Autofac.snk From 70cfee211d043441b993a980a98327c49abe6400 Mon Sep 17 00:00:00 2001 From: Travis Illig Date: Tue, 7 Nov 2023 08:12:51 -0800 Subject: [PATCH 08/12] Spelling: netcoreapp. --- .vscode/settings.json | 1 + 1 file changed, 1 insertion(+) diff --git a/.vscode/settings.json b/.vscode/settings.json index 400802825..689802557 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -8,6 +8,7 @@ "diagnoser", "inheritdoc", "langword", + "netcoreapp", "netstandard", "notnull", "paramref", From 7f43baae9163f1c337727f0afcccda043e347003 Mon Sep 17 00:00:00 2001 From: Travis Illig Date: Tue, 7 Nov 2023 08:13:04 -0800 Subject: [PATCH 09/12] Suppress rules we can't follow. --- build/Analyzers.ruleset | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/build/Analyzers.ruleset b/build/Analyzers.ruleset index 4d4683992..2d6e24b2d 100644 --- a/build/Analyzers.ruleset +++ b/build/Analyzers.ruleset @@ -4,8 +4,16 @@ + + + + + + + + From 334ae01e47d73d2dc78ae737224b6682be87f292 Mon Sep 17 00:00:00 2001 From: Travis Illig Date: Tue, 7 Nov 2023 08:15:00 -0800 Subject: [PATCH 10/12] Analyzer changes. In some cases, this was "change a private method to return the concrete type instead of an interface." This seemed reasonable and not breaking. --- src/Autofac/Builder/MetadataConfiguration.cs | 2 +- src/Autofac/ContainerBuilder.cs | 4 ++-- src/Autofac/Core/DependencyResolutionException.cs | 4 ++-- src/Autofac/Core/Lifetime/LifetimeScope.cs | 6 +++--- .../Core/Resolving/Pipeline/ResolvePipelineBuilder.cs | 2 +- .../Features/AttributeFilters/MetadataFilterAttribute.cs | 2 +- .../LightweightAdapterRegistrationExtensions.cs | 2 +- src/Autofac/Util/Enforce.cs | 4 ++-- 8 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Autofac/Builder/MetadataConfiguration.cs b/src/Autofac/Builder/MetadataConfiguration.cs index dab190c16..56bde0872 100644 --- a/src/Autofac/Builder/MetadataConfiguration.cs +++ b/src/Autofac/Builder/MetadataConfiguration.cs @@ -16,7 +16,7 @@ namespace Autofac.Builder; /// This feature was suggested by OJ Reeves (@TheColonial). public class MetadataConfiguration { - private readonly IDictionary _properties = new Dictionary(); + private readonly Dictionary _properties = new Dictionary(); /// /// Gets the set of properties that have been provided. diff --git a/src/Autofac/ContainerBuilder.cs b/src/Autofac/ContainerBuilder.cs index a0a052a2b..965187707 100644 --- a/src/Autofac/ContainerBuilder.cs +++ b/src/Autofac/ContainerBuilder.cs @@ -39,7 +39,7 @@ public sealed class ContainerBuilder private static int _builderAlreadyAllocated; private readonly bool _clearRegistrationCaches; - private readonly IList _configurationCallbacks = new List(); + private readonly List _configurationCallbacks = new List(); private BuildCallbackService? _buildCallbacks; private bool _wasBuilt; @@ -150,7 +150,7 @@ public ContainerBuilder RegisterBuildCallback(Action buildCallba /// /// Create a new container with the component registrations that have been made. /// - /// Options that influence the way the container is initialised. + /// Options that influence the way the container is initialized. /// /// Build can only be called once per /// - this prevents ownership issues for provided instances. diff --git a/src/Autofac/Core/DependencyResolutionException.cs b/src/Autofac/Core/DependencyResolutionException.cs index 19d8721b5..0f5bb1b9d 100644 --- a/src/Autofac/Core/DependencyResolutionException.cs +++ b/src/Autofac/Core/DependencyResolutionException.cs @@ -17,8 +17,8 @@ public class DependencyResolutionException : Exception /// /// Initializes a new instance of the class. /// - /// The serialisation info. - /// The serialisation streaming context. + /// The serialization info. + /// The serialization streaming context. protected DependencyResolutionException(SerializationInfo info, StreamingContext context) : base(info, context) { diff --git a/src/Autofac/Core/Lifetime/LifetimeScope.cs b/src/Autofac/Core/Lifetime/LifetimeScope.cs index 633384ffd..2bd1f7507 100644 --- a/src/Autofac/Core/Lifetime/LifetimeScope.cs +++ b/src/Autofac/Core/Lifetime/LifetimeScope.cs @@ -24,7 +24,7 @@ namespace Autofac.Core.Lifetime; public class LifetimeScope : Disposable, ISharingLifetimeScope, IServiceProvider { /// - /// Protects shared instances from concurrent access. Other members and the base class are threadsafe. + /// Protects shared instances from concurrent access. Other members and the base class are thread-safe. /// private readonly object _synchRoot = new(); private readonly ConcurrentDictionary _sharedInstances = new(); @@ -235,7 +235,7 @@ public ILifetimeScope BeginLoadContextLifetimeScope(object tag, AssemblyLoadCont } #endif - private ILifetimeScope InternalBeginLifetimeScope(object tag, Action configurationAction, bool isolatedScope) + private LifetimeScope InternalBeginLifetimeScope(object tag, Action configurationAction, bool isolatedScope) { if (configurationAction == null) { @@ -278,7 +278,7 @@ private ILifetimeScope InternalBeginLifetimeScope(object tag, ActionIt is the responsibility of the caller to make sure that the registry is properly /// disposed of. This is generally done by adding the registry to the /// property of the child scope. - private IComponentRegistryBuilder CreateScopeRestrictedRegistry(object tag, Action configurationAction, bool isolatedScope) + private ComponentRegistryBuilder CreateScopeRestrictedRegistry(object tag, Action configurationAction, bool isolatedScope) { var restrictedRootScopeLifetime = new MatchingScopeLifetime(tag); var tracker = new ScopeRestrictedRegisteredServicesTracker(restrictedRootScopeLifetime); diff --git a/src/Autofac/Core/Resolving/Pipeline/ResolvePipelineBuilder.cs b/src/Autofac/Core/Resolving/Pipeline/ResolvePipelineBuilder.cs index 3acfa9210..67474ced0 100644 --- a/src/Autofac/Core/Resolving/Pipeline/ResolvePipelineBuilder.cs +++ b/src/Autofac/Core/Resolving/Pipeline/ResolvePipelineBuilder.cs @@ -233,7 +233,7 @@ public IResolvePipeline Build() return BuildPipeline(_last); } - private static IResolvePipeline BuildPipeline(MiddlewareDeclaration? lastDecl) + private static ResolvePipeline BuildPipeline(MiddlewareDeclaration? lastDecl) { // When we build, we go through the set and construct a single call stack, starting from the end. var current = lastDecl; diff --git a/src/Autofac/Features/AttributeFilters/MetadataFilterAttribute.cs b/src/Autofac/Features/AttributeFilters/MetadataFilterAttribute.cs index d7d60c067..f779ca33f 100644 --- a/src/Autofac/Features/AttributeFilters/MetadataFilterAttribute.cs +++ b/src/Autofac/Features/AttributeFilters/MetadataFilterAttribute.cs @@ -190,7 +190,7 @@ private static Type GetElementType(Type type) .FirstOrDefault(); } - private static IEnumerable FilterAll(IComponentContext context, string metadataKey, object metadataValue) + private static T[] FilterAll(IComponentContext context, string metadataKey, object metadataValue) { // Using Lazy to ensure components that aren't actually used won't get activated. return context.Resolve>>>() diff --git a/src/Autofac/Features/LightweightAdapters/LightweightAdapterRegistrationExtensions.cs b/src/Autofac/Features/LightweightAdapters/LightweightAdapterRegistrationExtensions.cs index 29b610258..aecaf3502 100644 --- a/src/Autofac/Features/LightweightAdapters/LightweightAdapterRegistrationExtensions.cs +++ b/src/Autofac/Features/LightweightAdapters/LightweightAdapterRegistrationExtensions.cs @@ -63,7 +63,7 @@ private static Service ServiceWithKey(object? key) return new KeyedService(key, typeof(TService)); } - private static IRegistrationBuilder + private static RegistrationBuilder RegisterAdapter( ContainerBuilder builder, Func, TFrom, TTo> adapter, diff --git a/src/Autofac/Util/Enforce.cs b/src/Autofac/Util/Enforce.cs index 37facbdb8..23422852f 100644 --- a/src/Autofac/Util/Enforce.cs +++ b/src/Autofac/Util/Enforce.cs @@ -14,7 +14,7 @@ internal static class Enforce /// /// Enforce that sequence does not contain null. Returns the /// value if valid so that it can be used inline in - /// base initialiser syntax. + /// base initializer syntax. /// /// The value. /// The parameter name. @@ -55,7 +55,7 @@ public static T NotNull([ValidatedNotNull] T value) /// /// Enforce that an argument is not null or empty. Returns the /// value if valid so that it can be used inline in - /// base initialiser syntax. + /// base initializer syntax. /// /// The value. /// The description. From 0b78ed3e496da7e706123d6d8f2d0ef1ad34b0b7 Mon Sep 17 00:00:00 2001 From: Travis Illig Date: Tue, 7 Nov 2023 08:20:39 -0800 Subject: [PATCH 11/12] Breaking: DRE is no longer serializable https://github.com/dotnet/docs/issues/34893 .NET has long been deprecating BinaryFormatter and Serializable items. Analyzers as of .NET 8 are warning about obsolete serialization constructors. Given most of the underpinnings of this mechanism are also being deprecated, it seemed reasonable to include deprecation for that in Autofac. For projects that continue to use AppDomains and need to serialize exceptions over the wire, it's recommended to not upgrade Autofac to this version. --- .../Core/DependencyResolutionException.cs | 13 ----- .../DependencyResolutionExceptionTests.cs | 50 ------------------- 2 files changed, 63 deletions(-) diff --git a/src/Autofac/Core/DependencyResolutionException.cs b/src/Autofac/Core/DependencyResolutionException.cs index 0f5bb1b9d..d8eeaee4f 100644 --- a/src/Autofac/Core/DependencyResolutionException.cs +++ b/src/Autofac/Core/DependencyResolutionException.cs @@ -1,8 +1,6 @@ // Copyright (c) Autofac Project. All rights reserved. // Licensed under the MIT License. See LICENSE in the project root for license information. -using System.Runtime.Serialization; - namespace Autofac.Core; /// @@ -11,19 +9,8 @@ namespace Autofac.Core; /// been made during the operation. For example, 'on activated' handlers may have already been /// fired, or 'single instance' components partially constructed. /// -[Serializable] public class DependencyResolutionException : Exception { - /// - /// Initializes a new instance of the class. - /// - /// The serialization info. - /// The serialization streaming context. - protected DependencyResolutionException(SerializationInfo info, StreamingContext context) - : base(info, context) - { - } - /// /// Initializes a new instance of the class. /// diff --git a/test/Autofac.Test/Core/DependencyResolutionExceptionTests.cs b/test/Autofac.Test/Core/DependencyResolutionExceptionTests.cs index cdd87d028..0e6edbcb6 100644 --- a/test/Autofac.Test/Core/DependencyResolutionExceptionTests.cs +++ b/test/Autofac.Test/Core/DependencyResolutionExceptionTests.cs @@ -58,54 +58,4 @@ public void ExceptionMessageUnwrapsNestedResolutionFailures() Assert.IsType(inner.InnerException); Assert.Equal(A.Message, inner.InnerException.Message); } - -#if !NET5_0_OR_GREATER - - [Serializable] - public class CustomDependencyResolutionException : DependencyResolutionException - { - public int Value { get; } - - public CustomDependencyResolutionException(int value) - : base(null) - { - Value = value; - } - - protected CustomDependencyResolutionException(SerializationInfo info, StreamingContext context) - : base(info, context) - { - if (info == null) - { - throw new ArgumentNullException(nameof(info)); - } - - Value = info.GetInt32(nameof(Value)); - } - - [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)] - public override void GetObjectData(SerializationInfo info, StreamingContext context) - { - base.GetObjectData(info, context); - - info.AddValue(nameof(Value), 123); - } - } - - // Consider removing this test, or marking it as .NET Standard Only. Binary formatter serialisation has been obsoleted by Microsoft. - [Fact] - public void SupportCustomRuntimeSerialization() - { - using (var stream = new MemoryStream()) - { - var formatter = new BinaryFormatter(); - formatter.Serialize(stream, new CustomDependencyResolutionException(123)); - - stream.Position = 0; - var exception = (CustomDependencyResolutionException)formatter.Deserialize(stream); - - Assert.Equal(123, exception.Value); - } - } -#endif } From 7a25198a9c13dbd9536027b09d0acb86258e8a02 Mon Sep 17 00:00:00 2001 From: Travis Illig Date: Wed, 15 Nov 2023 07:09:21 -0800 Subject: [PATCH 12/12] Major version bump for breaking changes. --- appveyor.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 5c4f2f992..fdd6225a1 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,9 +1,9 @@ image: Ubuntu -version: "7.1.0.{build}" +version: "8.0.0.{build}" dotnet_csproj: - version_prefix: "7.1.0" + version_prefix: "8.0.0" patch: true file: 'src\**\*.csproj'