From 3d47ff17db981aa6e8c3bea198aea7ca4fa10c6d Mon Sep 17 00:00:00 2001 From: Nikolay Pianikov Date: Tue, 7 May 2024 09:46:35 +0300 Subject: [PATCH] Renaming and minor fixes --- readme/EnumDetails.md | 6 +++--- readme/SingletonDetails.md | 8 ++++---- readme/accumulators.md | 7 +++---- readme/advanced-interception.md | 4 ++-- readme/async-disposable-scope.md | 6 +++--- readme/async-disposable-singleton.md | 10 +++++----- readme/async-enumerable.md | 7 ++++--- readme/auto-scoped.md | 6 +++--- readme/default-lifetime.md | 12 +++++------- readme/disposable-singleton.md | 10 +++++----- readme/enumerable-generics.md | 12 ++++++------ readme/enumerable.md | 6 +++--- readme/func-with-arguments.md | 7 +++---- readme/func-with-tag.md | 2 +- readme/func.md | 2 +- readme/keyed-service-provider.md | 12 +++++------- readme/lazy.md | 2 +- readme/manually-started-tasks.md | 2 +- readme/ondependencyinjection-hint.md | 2 +- readme/onnewinstance-hint.md | 9 ++++----- readme/partial-class.md | 2 +- readme/perblock.md | 2 +- readme/perresolve.md | 6 +++--- readme/scope.md | 6 +++--- readme/service-collection.md | 12 +++++------- readme/service-provider-with-scope.md | 16 +++++++--------- readme/service-provider.md | 12 +++++------- readme/singleton.md | 7 +++---- readme/tag-type.md | 12 +++++------- readme/tag-unique.md | 6 +++--- readme/tags.md | 12 +++++------- readme/task.md | 2 +- ...ng-async-disposable-instances-in-delegates.md | 2 +- ...tracking-disposable-instances-in-delegates.md | 2 +- samples/Clock.Tests/Clock.Tests.csproj | 4 ++-- src/Pure.DI.Core/Components/Api.g.cs | 2 +- src/Pure.DI.Core/Core/Code/BlockCodeBuilder.cs | 5 ++--- src/Pure.DI.Core/Core/Code/ClassBuilder.cs | 3 --- .../Core/Code/ConstructCodeBuilder.cs | 8 ++++---- src/Pure.DI.Core/Core/Names.cs | 4 ++-- tests/Pure.DI.IntegrationTests/FactoryTests.cs | 2 +- .../Pure.DI.IntegrationTests.csproj | 4 ++-- .../ShroedingersCatTests.cs | 13 ++++++++++--- tests/Pure.DI.IntegrationTests/TestExtensions.cs | 2 +- tests/Pure.DI.Tests/Pure.DI.Tests.csproj | 4 ++-- .../Pure.DI.UsageTests/Pure.DI.UsageTests.csproj | 4 ++-- 46 files changed, 136 insertions(+), 150 deletions(-) diff --git a/readme/EnumDetails.md b/readme/EnumDetails.md index c8bc3af6..6526d46e 100644 --- a/readme/EnumDetails.md +++ b/readme/EnumDetails.md @@ -103,15 +103,15 @@ partial class Enum [MethodImpl((MethodImplOptions)0x100)] public partial Benchmarks.Model.CompositionRoot TestPureDIByCR() { - [MethodImpl((MethodImplOptions)0x200)] - IEnumerable Local_perBlock10_IEnumerable() + [MethodImpl((MethodImplOptions)0x100)] + IEnumerable EnumerationOf_perBlock10_IEnumerable() { yield return new Benchmarks.Model.Service3(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()); yield return new Benchmarks.Model.Service3v2(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()); yield return new Benchmarks.Model.Service3v3(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()); yield return new Benchmarks.Model.Service3v4(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()); } - IEnumerable perBlock10_IEnumerable = Local_perBlock10_IEnumerable(); + IEnumerable perBlock10_IEnumerable = EnumerationOf_perBlock10_IEnumerable(); return new Benchmarks.Model.CompositionRoot(new Benchmarks.Model.Service1(new Benchmarks.Model.Service2Enum(perBlock10_IEnumerable)), new Benchmarks.Model.Service2Enum(perBlock10_IEnumerable), new Benchmarks.Model.Service2Enum(perBlock10_IEnumerable), new Benchmarks.Model.Service2Enum(perBlock10_IEnumerable), new Benchmarks.Model.Service3(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()), new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()); } diff --git a/readme/SingletonDetails.md b/readme/SingletonDetails.md index a7b42ed1..dd4a6dea 100644 --- a/readme/SingletonDetails.md +++ b/readme/SingletonDetails.md @@ -70,8 +70,8 @@ classDiagram partial class Singleton { private readonly Singleton _root; - private Benchmarks.Model.Service1 _scoped37_Service1; - private Benchmarks.Model.Service4 _scoped40_Service4; + private Benchmarks.Model.Service1? _scoped37_Service1; + private Benchmarks.Model.Service4? _scoped40_Service4; public Singleton() { @@ -92,9 +92,9 @@ partial class Singleton } if (_scoped37_Service1 == null) { - _scoped37_Service1 = new Benchmarks.Model.Service1(new Benchmarks.Model.Service2(new Benchmarks.Model.Service3(_scoped40_Service4, _scoped40_Service4), new Benchmarks.Model.Service3(_scoped40_Service4, _scoped40_Service4), new Benchmarks.Model.Service3(_scoped40_Service4, _scoped40_Service4), new Benchmarks.Model.Service3(_scoped40_Service4, _scoped40_Service4), new Benchmarks.Model.Service3(_scoped40_Service4, _scoped40_Service4))); + _scoped37_Service1 = new Benchmarks.Model.Service1(new Benchmarks.Model.Service2(new Benchmarks.Model.Service3(_scoped40_Service4!, _scoped40_Service4!), new Benchmarks.Model.Service3(_scoped40_Service4!, _scoped40_Service4!), new Benchmarks.Model.Service3(_scoped40_Service4!, _scoped40_Service4!), new Benchmarks.Model.Service3(_scoped40_Service4!, _scoped40_Service4!), new Benchmarks.Model.Service3(_scoped40_Service4!, _scoped40_Service4!))); } - return new Benchmarks.Model.CompositionRoot(_scoped37_Service1, new Benchmarks.Model.Service2(new Benchmarks.Model.Service3(_scoped40_Service4, _scoped40_Service4), new Benchmarks.Model.Service3(_scoped40_Service4, _scoped40_Service4), new Benchmarks.Model.Service3(_scoped40_Service4, _scoped40_Service4), new Benchmarks.Model.Service3(_scoped40_Service4, _scoped40_Service4), new Benchmarks.Model.Service3(_scoped40_Service4, _scoped40_Service4)), new Benchmarks.Model.Service2(new Benchmarks.Model.Service3(_scoped40_Service4, _scoped40_Service4), new Benchmarks.Model.Service3(_scoped40_Service4, _scoped40_Service4), new Benchmarks.Model.Service3(_scoped40_Service4, _scoped40_Service4), new Benchmarks.Model.Service3(_scoped40_Service4, _scoped40_Service4), new Benchmarks.Model.Service3(_scoped40_Service4, _scoped40_Service4)), new Benchmarks.Model.Service2(new Benchmarks.Model.Service3(_scoped40_Service4, _scoped40_Service4), new Benchmarks.Model.Service3(_scoped40_Service4, _scoped40_Service4), new Benchmarks.Model.Service3(_scoped40_Service4, _scoped40_Service4), new Benchmarks.Model.Service3(_scoped40_Service4, _scoped40_Service4), new Benchmarks.Model.Service3(_scoped40_Service4, _scoped40_Service4)), new Benchmarks.Model.Service3(_scoped40_Service4, _scoped40_Service4), _scoped40_Service4, _scoped40_Service4); + return new Benchmarks.Model.CompositionRoot(_scoped37_Service1!, new Benchmarks.Model.Service2(new Benchmarks.Model.Service3(_scoped40_Service4!, _scoped40_Service4!), new Benchmarks.Model.Service3(_scoped40_Service4!, _scoped40_Service4!), new Benchmarks.Model.Service3(_scoped40_Service4!, _scoped40_Service4!), new Benchmarks.Model.Service3(_scoped40_Service4!, _scoped40_Service4!), new Benchmarks.Model.Service3(_scoped40_Service4!, _scoped40_Service4!)), new Benchmarks.Model.Service2(new Benchmarks.Model.Service3(_scoped40_Service4!, _scoped40_Service4!), new Benchmarks.Model.Service3(_scoped40_Service4!, _scoped40_Service4!), new Benchmarks.Model.Service3(_scoped40_Service4!, _scoped40_Service4!), new Benchmarks.Model.Service3(_scoped40_Service4!, _scoped40_Service4!), new Benchmarks.Model.Service3(_scoped40_Service4!, _scoped40_Service4!)), new Benchmarks.Model.Service2(new Benchmarks.Model.Service3(_scoped40_Service4!, _scoped40_Service4!), new Benchmarks.Model.Service3(_scoped40_Service4!, _scoped40_Service4!), new Benchmarks.Model.Service3(_scoped40_Service4!, _scoped40_Service4!), new Benchmarks.Model.Service3(_scoped40_Service4!, _scoped40_Service4!), new Benchmarks.Model.Service3(_scoped40_Service4!, _scoped40_Service4!)), new Benchmarks.Model.Service3(_scoped40_Service4!, _scoped40_Service4!), _scoped40_Service4!, _scoped40_Service4!); } [MethodImpl((MethodImplOptions)0x100)] diff --git a/readme/accumulators.md b/readme/accumulators.md index b95b8ca1..dfdc14cd 100644 --- a/readme/accumulators.md +++ b/readme/accumulators.md @@ -92,7 +92,7 @@ partial class Composition { private readonly Composition _root; private readonly object _lock; - private XyzDependency _singleton38_XyzDependency; + private XyzDependency? _singleton38_XyzDependency; public Composition() { @@ -123,8 +123,7 @@ partial class Composition _singleton38_XyzDependencyTemp = new XyzDependency(); accumulator42.Add(_singleton38_XyzDependencyTemp); Thread.MemoryBarrier(); - _singleton38_XyzDependency = _singleton38_XyzDependencyTemp; - _root._singleton38_XyzDependency = _singleton38_XyzDependency; + _root._singleton38_XyzDependency = _singleton38_XyzDependencyTemp; } } } @@ -133,7 +132,7 @@ partial class Composition { accumulator42.Add(transient3_AbcDependency); } - Service transient1_Service = new Service(transient3_AbcDependency, _root._singleton38_XyzDependency, perBlock4_AbcDependency); + Service transient1_Service = new Service(transient3_AbcDependency, _root._singleton38_XyzDependency!, perBlock4_AbcDependency); lock (_lock) { accumulator42.Add(transient1_Service); diff --git a/readme/advanced-interception.md b/readme/advanced-interception.md index 3e4e3fa7..64b52a14 100644 --- a/readme/advanced-interception.md +++ b/readme/advanced-interception.md @@ -31,9 +31,9 @@ class Service(IDependency dependency) : IService internal partial class Composition: IInterceptor { - private readonly List _log; + private readonly List _log = new(); private static readonly IProxyBuilder ProxyBuilder = new DefaultProxyBuilder(); - private readonly IInterceptor[] _interceptors; + private readonly IInterceptor[] _interceptors = []; public Composition(List log) : this() diff --git a/readme/async-disposable-scope.md b/readme/async-disposable-scope.md index fdde8183..1b62c008 100644 --- a/readme/async-disposable-scope.md +++ b/readme/async-disposable-scope.md @@ -140,7 +140,7 @@ partial class Composition: IDisposable, IAsyncDisposable private readonly object _lock; private object[] _disposables; private int _disposeIndex; - private Dependency _scoped36_Dependency; + private Dependency? _scoped36_Dependency; public Composition() { @@ -172,7 +172,7 @@ partial class Composition: IDisposable, IAsyncDisposable } } } - return new Service(_scoped36_Dependency); + return new Service(_scoped36_Dependency!); } } @@ -190,7 +190,7 @@ partial class Composition: IDisposable, IAsyncDisposable var value_1 = new Session(transient2_Composition); return value_1; }); - return new Program(perResolve43_Func); + return new Program(perResolve43_Func!); } } diff --git a/readme/async-disposable-singleton.md b/readme/async-disposable-singleton.md index 62235c46..42bde17e 100644 --- a/readme/async-disposable-singleton.md +++ b/readme/async-disposable-singleton.md @@ -93,7 +93,7 @@ partial class Composition: IDisposable, IAsyncDisposable private readonly object _lock; private object[] _disposables; private int _disposeIndex; - private Dependency _singleton36_Dependency; + private Dependency? _singleton36_Dependency; public Composition() { @@ -106,6 +106,7 @@ partial class Composition: IDisposable, IAsyncDisposable { _root = parentScope._root; _lock = _root._lock; + _disposables = parentScope._disposables; } public IService Root @@ -119,13 +120,12 @@ partial class Composition: IDisposable, IAsyncDisposable { if (_root._singleton36_Dependency == null) { - _singleton36_Dependency = new Dependency(); - _root._singleton36_Dependency = _singleton36_Dependency; - _root._disposables[_root._disposeIndex++] = _singleton36_Dependency; + _root._singleton36_Dependency = new Dependency(); + _root._disposables[_root._disposeIndex++] = _root._singleton36_Dependency; } } } - return new Service(_root._singleton36_Dependency); + return new Service(_root._singleton36_Dependency!); } } diff --git a/readme/async-enumerable.md b/readme/async-enumerable.md index 8ff2d1e7..a8fdd6e0 100644 --- a/readme/async-enumerable.md +++ b/readme/async-enumerable.md @@ -107,13 +107,14 @@ partial class Composition [MethodImpl((MethodImplOptions)0x100)] get { - [MethodImpl((MethodImplOptions)0x200)] - async IAsyncEnumerable Local_transient1_IAsyncEnumerable() + [MethodImpl((MethodImplOptions)0x100)] + async IAsyncEnumerable EnumerationOf_transient1_IAsyncEnumerable() { yield return new AbcDependency(); yield return new XyzDependency(); + await Task.CompletedTask; } - IAsyncEnumerable transient1_IAsyncEnumerable = Local_transient1_IAsyncEnumerable(); + IAsyncEnumerable transient1_IAsyncEnumerable = EnumerationOf_transient1_IAsyncEnumerable(); return new Service(transient1_IAsyncEnumerable); } } diff --git a/readme/auto-scoped.md b/readme/auto-scoped.md index c0593b08..a7143c77 100644 --- a/readme/auto-scoped.md +++ b/readme/auto-scoped.md @@ -108,7 +108,7 @@ partial class Composition { private readonly Composition _root; private readonly object _lock; - private Dependency _scoped36_Dependency; + private Dependency? _scoped36_Dependency; public Composition() { @@ -137,7 +137,7 @@ partial class Composition } } } - return new Service(_scoped36_Dependency); + return new Service(_scoped36_Dependency!); } } @@ -162,7 +162,7 @@ partial class Composition var value_1 = transient1_IService; return value_1; }); - return new Program(perResolve43_Func); + return new Program(perResolve43_Func!); } } diff --git a/readme/default-lifetime.md b/readme/default-lifetime.md index ecf38739..ca5c03ff 100644 --- a/readme/default-lifetime.md +++ b/readme/default-lifetime.md @@ -79,8 +79,8 @@ partial class Composition { private readonly Composition _root; private readonly object _lock; - private Service _singleton37_Service; - private Dependency _singleton36_Dependency; + private Service? _singleton37_Service; + private Dependency? _singleton36_Dependency; public Composition() { @@ -107,15 +107,13 @@ partial class Composition { if (_root._singleton36_Dependency == null) { - _singleton36_Dependency = new Dependency(); - _root._singleton36_Dependency = _singleton36_Dependency; + _root._singleton36_Dependency = new Dependency(); } - _singleton37_Service = new Service(_singleton36_Dependency, _root._singleton36_Dependency); - _root._singleton37_Service = _singleton37_Service; + _root._singleton37_Service = new Service(_root._singleton36_Dependency!, _root._singleton36_Dependency!); } } } - return _root._singleton37_Service; + return _root._singleton37_Service!; } } diff --git a/readme/disposable-singleton.md b/readme/disposable-singleton.md index 96a93209..e8adaec9 100644 --- a/readme/disposable-singleton.md +++ b/readme/disposable-singleton.md @@ -86,7 +86,7 @@ partial class Composition: IDisposable private readonly object _lock; private object[] _disposables; private int _disposeIndex; - private Dependency _singleton36_Dependency; + private Dependency? _singleton36_Dependency; public Composition() { @@ -99,6 +99,7 @@ partial class Composition: IDisposable { _root = parentScope._root; _lock = _root._lock; + _disposables = parentScope._disposables; } public IService Root @@ -112,13 +113,12 @@ partial class Composition: IDisposable { if (_root._singleton36_Dependency == null) { - _singleton36_Dependency = new Dependency(); - _root._singleton36_Dependency = _singleton36_Dependency; - _root._disposables[_root._disposeIndex++] = _singleton36_Dependency; + _root._singleton36_Dependency = new Dependency(); + _root._disposables[_root._disposeIndex++] = _root._singleton36_Dependency; } } } - return new Service(_root._singleton36_Dependency); + return new Service(_root._singleton36_Dependency!); } } diff --git a/readme/enumerable-generics.md b/readme/enumerable-generics.md index d4000841..80123a0c 100644 --- a/readme/enumerable-generics.md +++ b/readme/enumerable-generics.md @@ -128,13 +128,13 @@ partial class Composition [MethodImpl((MethodImplOptions)0x100)] get { - [MethodImpl((MethodImplOptions)0x200)] - IEnumerable> Local_perBlock1_IEnumerable() + [MethodImpl((MethodImplOptions)0x100)] + IEnumerable> EnumerationOf_perBlock1_IEnumerable() { yield return new AbcDependency(); yield return new XyzDependency(); } - IEnumerable> perBlock1_IEnumerable = Local_perBlock1_IEnumerable(); + IEnumerable> perBlock1_IEnumerable = EnumerationOf_perBlock1_IEnumerable(); return new Service(perBlock1_IEnumerable); } } @@ -144,13 +144,13 @@ partial class Composition [MethodImpl((MethodImplOptions)0x100)] get { - [MethodImpl((MethodImplOptions)0x200)] - IEnumerable> Local_perBlock1_IEnumerable() + [MethodImpl((MethodImplOptions)0x100)] + IEnumerable> EnumerationOf_perBlock1_IEnumerable() { yield return new AbcDependency(); yield return new XyzDependency(); } - IEnumerable> perBlock1_IEnumerable = Local_perBlock1_IEnumerable(); + IEnumerable> perBlock1_IEnumerable = EnumerationOf_perBlock1_IEnumerable(); return new Service(perBlock1_IEnumerable); } } diff --git a/readme/enumerable.md b/readme/enumerable.md index 3a459a13..c59fd58d 100644 --- a/readme/enumerable.md +++ b/readme/enumerable.md @@ -99,13 +99,13 @@ partial class Composition [MethodImpl((MethodImplOptions)0x100)] get { - [MethodImpl((MethodImplOptions)0x200)] - IEnumerable Local_perBlock1_IEnumerable() + [MethodImpl((MethodImplOptions)0x100)] + IEnumerable EnumerationOf_perBlock1_IEnumerable() { yield return new AbcDependency(); yield return new XyzDependency(); } - IEnumerable perBlock1_IEnumerable = Local_perBlock1_IEnumerable(); + IEnumerable perBlock1_IEnumerable = EnumerationOf_perBlock1_IEnumerable(); return new Service(perBlock1_IEnumerable); } } diff --git a/readme/func-with-arguments.md b/readme/func-with-arguments.md index cfa3863e..21f69cd2 100644 --- a/readme/func-with-arguments.md +++ b/readme/func-with-arguments.md @@ -113,7 +113,7 @@ partial class Composition { private readonly Composition _root; private readonly object _lock; - private Clock _singleton36_Clock; + private Clock? _singleton36_Clock; public Composition() { @@ -141,12 +141,11 @@ partial class Composition { if (_root._singleton36_Clock == null) { - _singleton36_Clock = new Clock(); - _root._singleton36_Clock = _singleton36_Clock; + _root._singleton36_Clock = new Clock(); } } } - var dependency_1 = new Dependency(_root._singleton36_Clock, transient3_Int32); + var dependency_1 = new Dependency(_root._singleton36_Clock!, transient3_Int32); return dependency_1; }; return new Service(transient1_Func); diff --git a/readme/func-with-tag.md b/readme/func-with-tag.md index a3be594f..f4d49dc2 100644 --- a/readme/func-with-tag.md +++ b/readme/func-with-tag.md @@ -103,7 +103,7 @@ partial class Composition var value_1 = new Dependency(); return value_1; }); - return new Service(perResolve39_Func); + return new Service(perResolve39_Func!); } } diff --git a/readme/func.md b/readme/func.md index fe1f12aa..5523eb64 100644 --- a/readme/func.md +++ b/readme/func.md @@ -106,7 +106,7 @@ partial class Composition var value_1 = new Dependency(); return value_1; }); - return new Service(perResolve39_Func); + return new Service(perResolve39_Func!); } } diff --git a/readme/keyed-service-provider.md b/readme/keyed-service-provider.md index 33ce77ee..c24359b1 100644 --- a/readme/keyed-service-provider.md +++ b/readme/keyed-service-provider.md @@ -86,7 +86,7 @@ partial class Composition { private readonly Composition _root; private readonly object _lock; - private Dependency _singleton36_Dependency; + private Dependency? _singleton36_Dependency; public Composition() { @@ -111,12 +111,11 @@ partial class Composition { if (_root._singleton36_Dependency == null) { - _singleton36_Dependency = new Dependency(); - _root._singleton36_Dependency = _singleton36_Dependency; + _root._singleton36_Dependency = new Dependency(); } } } - return _root._singleton36_Dependency; + return _root._singleton36_Dependency!; } } @@ -131,12 +130,11 @@ partial class Composition { if (_root._singleton36_Dependency == null) { - _singleton36_Dependency = new Dependency(); - _root._singleton36_Dependency = _singleton36_Dependency; + _root._singleton36_Dependency = new Dependency(); } } } - return new Service(_root._singleton36_Dependency); + return new Service(_root._singleton36_Dependency!); } } diff --git a/readme/lazy.md b/readme/lazy.md index caf7785e..8a9224a7 100644 --- a/readme/lazy.md +++ b/readme/lazy.md @@ -101,7 +101,7 @@ partial class Composition }); Lazy transient1_Lazy; { - var factory_2 = perResolve40_Func; + var factory_2 = perResolve40_Func!; transient1_Lazy = new Lazy(factory_2, true); } return new Service(transient1_Lazy); diff --git a/readme/manually-started-tasks.md b/readme/manually-started-tasks.md index a3f50f21..b956b955 100644 --- a/readme/manually-started-tasks.md +++ b/readme/manually-started-tasks.md @@ -139,7 +139,7 @@ partial class Composition }); Task transient1_Task; { - var factory_2 = perResolve42_Func; + var factory_2 = perResolve42_Func!; var cancellationToken_3 = cancellationToken; transient1_Task = new Task(factory_2, cancellationToken_3); } diff --git a/readme/ondependencyinjection-hint.md b/readme/ondependencyinjection-hint.md index 8ed38460..b3e0ab31 100644 --- a/readme/ondependencyinjection-hint.md +++ b/readme/ondependencyinjection-hint.md @@ -24,7 +24,7 @@ class Service(IDependency dependency) : IService partial class Composition { - private readonly List _log; + private readonly List _log = []; public Composition(List log) : this() => _log = log; diff --git a/readme/onnewinstance-hint.md b/readme/onnewinstance-hint.md index 6fcb4375..97d6bb21 100644 --- a/readme/onnewinstance-hint.md +++ b/readme/onnewinstance-hint.md @@ -29,7 +29,7 @@ class Service(IDependency dependency) : IService internal partial class Composition { - private readonly List _log; + private readonly List _log = []; public Composition(List log) : this() => _log = log; @@ -97,7 +97,7 @@ partial class Composition { private readonly Composition _root; private readonly object _lock; - private Dependency _singleton36_Dependency; + private Dependency? _singleton36_Dependency; public Composition() { @@ -126,12 +126,11 @@ partial class Composition _singleton36_DependencyTemp = new Dependency(); OnNewInstance(ref _singleton36_DependencyTemp, null, Lifetime.Singleton); Thread.MemoryBarrier(); - _singleton36_Dependency = _singleton36_DependencyTemp; - _root._singleton36_Dependency = _singleton36_Dependency; + _root._singleton36_Dependency = _singleton36_DependencyTemp; } } } - Service transient0_Service = new Service(_root._singleton36_Dependency); + Service transient0_Service = new Service(_root._singleton36_Dependency!); OnNewInstance(ref transient0_Service, null, Lifetime.Transient); return transient0_Service; } diff --git a/readme/partial-class.md b/readme/partial-class.md index 4772914d..489c8f36 100644 --- a/readme/partial-class.md +++ b/readme/partial-class.md @@ -30,7 +30,7 @@ class Service( // The partial class is also useful for specifying access modifiers to the generated class public partial class Composition { - private readonly string _serviceName; + private readonly string _serviceName = ""; private long _id; // Customizable constructor diff --git a/readme/perblock.md b/readme/perblock.md index 300f8fa0..7a13ca4e 100644 --- a/readme/perblock.md +++ b/readme/perblock.md @@ -116,7 +116,7 @@ partial class Composition }); Lazy<(IDependency dep3, IDependency dep4)> transient2_Lazy; { - var factory_2 = perResolve43_Func; + var factory_2 = perResolve43_Func!; transient2_Lazy = new Lazy<(IDependency dep3, IDependency dep4)>(factory_2, true); } Dependency perBlock1_Dependency = new Dependency(); diff --git a/readme/perresolve.md b/readme/perresolve.md index 2497372f..9ad5497c 100644 --- a/readme/perresolve.md +++ b/readme/perresolve.md @@ -121,12 +121,12 @@ partial class Composition } } } - var value_1 = (perResolve36_Dependency, perResolve36_Dependency); + var value_1 = (perResolve36_Dependency!, perResolve36_Dependency!); return value_1; }); Lazy<(IDependency dep3, IDependency dep4)> transient1_Lazy; { - var factory_2 = perResolve43_Func; + var factory_2 = perResolve43_Func!; transient1_Lazy = new Lazy<(IDependency dep3, IDependency dep4)>(factory_2, true); } if (perResolve36_Dependency == null) @@ -139,7 +139,7 @@ partial class Composition } } } - return new Service(perResolve36_Dependency, perResolve36_Dependency, transient1_Lazy); + return new Service(perResolve36_Dependency!, perResolve36_Dependency!, transient1_Lazy); } } diff --git a/readme/scope.md b/readme/scope.md index e3bf02b1..d55abd56 100644 --- a/readme/scope.md +++ b/readme/scope.md @@ -133,7 +133,7 @@ partial class Composition: IDisposable private readonly object _lock; private object[] _disposables; private int _disposeIndex; - private Dependency _scoped36_Dependency; + private Dependency? _scoped36_Dependency; public Composition() { @@ -165,7 +165,7 @@ partial class Composition: IDisposable } } } - return new Service(_scoped36_Dependency); + return new Service(_scoped36_Dependency!); } } @@ -183,7 +183,7 @@ partial class Composition: IDisposable var value_1 = new Session(transient2_Composition); return value_1; }); - return new Program(perResolve43_Func); + return new Program(perResolve43_Func!); } } diff --git a/readme/service-collection.md b/readme/service-collection.md index 983c4b2f..6fcea54b 100644 --- a/readme/service-collection.md +++ b/readme/service-collection.md @@ -83,7 +83,7 @@ partial class Composition { private readonly Composition _root; private readonly object _lock; - private Dependency _singleton36_Dependency; + private Dependency? _singleton36_Dependency; public Composition() { @@ -108,12 +108,11 @@ partial class Composition { if (_root._singleton36_Dependency == null) { - _singleton36_Dependency = new Dependency(); - _root._singleton36_Dependency = _singleton36_Dependency; + _root._singleton36_Dependency = new Dependency(); } } } - return _root._singleton36_Dependency; + return _root._singleton36_Dependency!; } } @@ -128,12 +127,11 @@ partial class Composition { if (_root._singleton36_Dependency == null) { - _singleton36_Dependency = new Dependency(); - _root._singleton36_Dependency = _singleton36_Dependency; + _root._singleton36_Dependency = new Dependency(); } } } - return new Service(_root._singleton36_Dependency); + return new Service(_root._singleton36_Dependency!); } } diff --git a/readme/service-provider-with-scope.md b/readme/service-provider-with-scope.md index 2bae6af5..884d55f3 100644 --- a/readme/service-provider-with-scope.md +++ b/readme/service-provider-with-scope.md @@ -114,8 +114,8 @@ partial class Composition: IDisposable private readonly object _lock; private object[] _disposables; private int _disposeIndex; - private Dependency _singleton36_Dependency; - private Service _scoped37_Service; + private Dependency? _singleton36_Dependency; + private Service? _scoped37_Service; public Composition() { @@ -142,12 +142,11 @@ partial class Composition: IDisposable { if (_root._singleton36_Dependency == null) { - _singleton36_Dependency = new Dependency(); - _root._singleton36_Dependency = _singleton36_Dependency; + _root._singleton36_Dependency = new Dependency(); } } } - return _root._singleton36_Dependency; + return _root._singleton36_Dependency!; } } @@ -164,15 +163,14 @@ partial class Composition: IDisposable { if (_root._singleton36_Dependency == null) { - _singleton36_Dependency = new Dependency(); - _root._singleton36_Dependency = _singleton36_Dependency; + _root._singleton36_Dependency = new Dependency(); } - _scoped37_Service = new Service(_root._singleton36_Dependency); + _scoped37_Service = new Service(_root._singleton36_Dependency!); _disposables[_disposeIndex++] = _scoped37_Service; } } } - return _scoped37_Service; + return _scoped37_Service!; } } diff --git a/readme/service-provider.md b/readme/service-provider.md index 936dd8b8..b7e4d959 100644 --- a/readme/service-provider.md +++ b/readme/service-provider.md @@ -81,7 +81,7 @@ partial class Composition { private readonly Composition _root; private readonly object _lock; - private Dependency _singleton36_Dependency; + private Dependency? _singleton36_Dependency; public Composition() { @@ -106,12 +106,11 @@ partial class Composition { if (_root._singleton36_Dependency == null) { - _singleton36_Dependency = new Dependency(); - _root._singleton36_Dependency = _singleton36_Dependency; + _root._singleton36_Dependency = new Dependency(); } } } - return _root._singleton36_Dependency; + return _root._singleton36_Dependency!; } } @@ -126,12 +125,11 @@ partial class Composition { if (_root._singleton36_Dependency == null) { - _singleton36_Dependency = new Dependency(); - _root._singleton36_Dependency = _singleton36_Dependency; + _root._singleton36_Dependency = new Dependency(); } } } - return new Service(_root._singleton36_Dependency); + return new Service(_root._singleton36_Dependency!); } } diff --git a/readme/singleton.md b/readme/singleton.md index 4e9fe597..072fe933 100644 --- a/readme/singleton.md +++ b/readme/singleton.md @@ -78,7 +78,7 @@ partial class Composition { private readonly Composition _root; private readonly object _lock; - private Dependency _singleton36_Dependency; + private Dependency? _singleton36_Dependency; public Composition() { @@ -103,12 +103,11 @@ partial class Composition { if (_root._singleton36_Dependency == null) { - _singleton36_Dependency = new Dependency(); - _root._singleton36_Dependency = _singleton36_Dependency; + _root._singleton36_Dependency = new Dependency(); } } } - return new Service(_singleton36_Dependency, _root._singleton36_Dependency); + return new Service(_root._singleton36_Dependency!, _root._singleton36_Dependency!); } } diff --git a/readme/tag-type.md b/readme/tag-type.md index e7bd0456..03cbdb7f 100644 --- a/readme/tag-type.md +++ b/readme/tag-type.md @@ -103,7 +103,7 @@ partial class Composition { private readonly Composition _root; private readonly object _lock; - private XyzDependency _singleton37_XyzDependency; + private XyzDependency? _singleton37_XyzDependency; public Composition() { @@ -128,12 +128,11 @@ partial class Composition { if (_root._singleton37_XyzDependency == null) { - _singleton37_XyzDependency = new XyzDependency(); - _root._singleton37_XyzDependency = _singleton37_XyzDependency; + _root._singleton37_XyzDependency = new XyzDependency(); } } } - return _root._singleton37_XyzDependency; + return _root._singleton37_XyzDependency!; } } @@ -148,12 +147,11 @@ partial class Composition { if (_root._singleton37_XyzDependency == null) { - _singleton37_XyzDependency = new XyzDependency(); - _root._singleton37_XyzDependency = _singleton37_XyzDependency; + _root._singleton37_XyzDependency = new XyzDependency(); } } } - return new Service(new AbcDependency(), _root._singleton37_XyzDependency, new AbcDependency()); + return new Service(new AbcDependency(), _root._singleton37_XyzDependency!, new AbcDependency()); } } diff --git a/readme/tag-unique.md b/readme/tag-unique.md index b003886e..7eb40071 100644 --- a/readme/tag-unique.md +++ b/readme/tag-unique.md @@ -97,13 +97,13 @@ partial class Composition [MethodImpl((MethodImplOptions)0x100)] get { - [MethodImpl((MethodImplOptions)0x200)] - IEnumerable> Local_perBlock1_IEnumerable() + [MethodImpl((MethodImplOptions)0x100)] + IEnumerable> EnumerationOf_perBlock1_IEnumerable() { yield return new AbcDependency(); yield return new XyzDependency(); } - IEnumerable> perBlock1_IEnumerable = Local_perBlock1_IEnumerable(); + IEnumerable> perBlock1_IEnumerable = EnumerationOf_perBlock1_IEnumerable(); return new Service(perBlock1_IEnumerable); } } diff --git a/readme/tags.md b/readme/tags.md index dbd25c69..cefc5958 100644 --- a/readme/tags.md +++ b/readme/tags.md @@ -107,7 +107,7 @@ partial class Composition { private readonly Composition _root; private readonly object _lock; - private XyzDependency _singleton37_XyzDependency; + private XyzDependency? _singleton37_XyzDependency; public Composition() { @@ -132,12 +132,11 @@ partial class Composition { if (_root._singleton37_XyzDependency == null) { - _singleton37_XyzDependency = new XyzDependency(); - _root._singleton37_XyzDependency = _singleton37_XyzDependency; + _root._singleton37_XyzDependency = new XyzDependency(); } } } - return _root._singleton37_XyzDependency; + return _root._singleton37_XyzDependency!; } } @@ -152,12 +151,11 @@ partial class Composition { if (_root._singleton37_XyzDependency == null) { - _singleton37_XyzDependency = new XyzDependency(); - _root._singleton37_XyzDependency = _singleton37_XyzDependency; + _root._singleton37_XyzDependency = new XyzDependency(); } } } - return new Service(new AbcDependency(), _root._singleton37_XyzDependency, new AbcDependency()); + return new Service(new AbcDependency(), _root._singleton37_XyzDependency!, new AbcDependency()); } } diff --git a/readme/task.md b/readme/task.md index d6eadd62..6c0c194e 100644 --- a/readme/task.md +++ b/readme/task.md @@ -149,7 +149,7 @@ partial class Composition }); Task transient1_Task; { - var factory_6 = perResolve42_Func; + var factory_6 = perResolve42_Func!; var taskFactory_7 = perBlock2_TaskFactory; transient1_Task = taskFactory_7.StartNew(factory_6); } diff --git a/readme/tracking-async-disposable-instances-in-delegates.md b/readme/tracking-async-disposable-instances-in-delegates.md index 8db954a4..dbfc0a77 100644 --- a/readme/tracking-async-disposable-instances-in-delegates.md +++ b/readme/tracking-async-disposable-instances-in-delegates.md @@ -161,7 +161,7 @@ partial class Composition var value_1 = perBlock1_Owned; return value_1; }); - return new Service(perResolve39_Func); + return new Service(perResolve39_Func!); } } diff --git a/readme/tracking-disposable-instances-in-delegates.md b/readme/tracking-disposable-instances-in-delegates.md index 5c16caf3..a6ec6dbc 100644 --- a/readme/tracking-disposable-instances-in-delegates.md +++ b/readme/tracking-disposable-instances-in-delegates.md @@ -150,7 +150,7 @@ partial class Composition var value_1 = perBlock1_Owned; return value_1; }); - return new Service(perResolve39_Func); + return new Service(perResolve39_Func!); } } diff --git a/samples/Clock.Tests/Clock.Tests.csproj b/samples/Clock.Tests/Clock.Tests.csproj index 992d7143..ec5075ff 100644 --- a/samples/Clock.Tests/Clock.Tests.csproj +++ b/samples/Clock.Tests/Clock.Tests.csproj @@ -9,8 +9,8 @@ - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/Pure.DI.Core/Components/Api.g.cs b/src/Pure.DI.Core/Components/Api.g.cs index cab84e62..22a50dee 100644 --- a/src/Pure.DI.Core/Components/Api.g.cs +++ b/src/Pure.DI.Core/Components/Api.g.cs @@ -2,7 +2,7 @@ #if !PUREDI_API_SUPPRESSION || PUREDI_API_V1 #pragma warning disable -#if !NET40_OR_GREATER && !NETSTANDARD2_0_OR_GREATER && !NETCOREAPP2_0_OR_GREATER +#if !NET40_OR_GREATER && !NETSTANDARD2_0_OR_GREATER && !NETCOREAPP2_0_OR_GREATER && !NET5_0_OR_GREATER namespace System.Diagnostics.CodeAnalysis { // ReSharper disable UnusedType.Global diff --git a/src/Pure.DI.Core/Core/Code/BlockCodeBuilder.cs b/src/Pure.DI.Core/Core/Code/BlockCodeBuilder.cs index 01a9a77b..d7b9f80e 100644 --- a/src/Pure.DI.Core/Core/Code/BlockCodeBuilder.cs +++ b/src/Pure.DI.Core/Core/Code/BlockCodeBuilder.cs @@ -126,12 +126,11 @@ variable.Node.Lifetime is Lifetime.Singleton or Lifetime.Scoped finally { info.HasCode = true; - // ctx.Code.AppendLines(info.Code.Lines); if (block.Parent is not null - && info is { PerBlockRefCount: > 1, Code.Lines.Count: > 3 }) + && info is { PerBlockRefCount: > 1, Code.Lines.Count: > 11 }) { var localFunctionsCode = ctx.LocalFunctionsCode; - var localMethodName = $"{Names.LocalMethodPrefix}{variable.VariableDeclarationName}{Names.EnsureExistsMethodNamePostfix}"; + var localMethodName = $"{Names.EnsureExistsMethodNamePrefix}_{variable.VariableDeclarationName}".Replace("__", "_"); if (variable.Node.Binding.SemanticModel.Compilation.GetLanguageVersion() >= LanguageVersion.CSharp9) { localFunctionsCode.AppendLine($"[{Names.MethodImplAttribute}(({Names.MethodImplOptions})0x100)]"); diff --git a/src/Pure.DI.Core/Core/Code/ClassBuilder.cs b/src/Pure.DI.Core/Core/Code/ClassBuilder.cs index 926fd872..4e690141 100644 --- a/src/Pure.DI.Core/Core/Code/ClassBuilder.cs +++ b/src/Pure.DI.Core/Core/Code/ClassBuilder.cs @@ -44,10 +44,7 @@ public CompositionCode Build(CompositionCode composition) code.AppendLine("#nullable enable"); } - code.AppendLine("#pragma warning disable CS0436"); - code.AppendLine(); - composition = usingDeclarationsBuilder.Build(composition); var nsIndent = Disposables.Empty; diff --git a/src/Pure.DI.Core/Core/Code/ConstructCodeBuilder.cs b/src/Pure.DI.Core/Core/Code/ConstructCodeBuilder.cs index 53dcb6a4..cd5136f7 100644 --- a/src/Pure.DI.Core/Core/Code/ConstructCodeBuilder.cs +++ b/src/Pure.DI.Core/Core/Code/ConstructCodeBuilder.cs @@ -50,13 +50,13 @@ private void BuildEnumerable(BuildContext ctx, in DpConstruct enumerable, string var variable = ctx.Variable; var code = ctx.Code; var level = ctx.Level + 1; - var localFuncName = $"{Names.LocalMethodPrefix}{variable.VariableDeclarationName}"; + var localMethodName = $"{Names.EnumerateMethodNamePrefix}_{variable.VariableDeclarationName}".Replace("__", "_"); if (enumerable.Source.SemanticModel.Compilation.GetLanguageVersion() >= LanguageVersion.CSharp9) { - code.AppendLine($"[{Names.MethodImplAttribute}(({Names.MethodImplOptions})0x200)]"); + code.AppendLine($"[{Names.MethodImplAttribute}(({Names.MethodImplOptions})0x100)]"); } - code.AppendLine($"{methodPrefix}{typeResolver.Resolve(variable.InstanceType)} {localFuncName}()"); + code.AppendLine($"{methodPrefix}{typeResolver.Resolve(variable.InstanceType)} {localMethodName}()"); code.AppendLine("{"); using (code.Indent()) { @@ -83,7 +83,7 @@ private void BuildEnumerable(BuildContext ctx, in DpConstruct enumerable, string code.AppendLine("}"); code.AppendLine(); - ctx.Code.AppendLine($"{ctx.BuildTools.GetDeclaration(variable)}{variable.VariableName} = {localFuncName}();"); + ctx.Code.AppendLine($"{ctx.BuildTools.GetDeclaration(variable)}{variable.VariableName} = {localMethodName}();"); ctx.Code.AppendLines(ctx.BuildTools.OnCreated(ctx, variable)); } diff --git a/src/Pure.DI.Core/Core/Names.cs b/src/Pure.DI.Core/Core/Names.cs index 2b2c76fd..f38e2394 100644 --- a/src/Pure.DI.Core/Core/Names.cs +++ b/src/Pure.DI.Core/Core/Names.cs @@ -47,8 +47,8 @@ internal static class Names public const string OnNewRootMethodName = "OnNewRoot"; // Local methods - public const string LocalMethodPrefix = "Local_"; - public const string EnsureExistsMethodNamePostfix = "EnsureExists"; + public const string EnsureExistsMethodNamePrefix = "EnsureExistenceOf"; + public const string EnumerateMethodNamePrefix = "EnumerationOf"; // Fields public static readonly string BucketsFieldName = $"_buckets{Salt}"; diff --git a/tests/Pure.DI.IntegrationTests/FactoryTests.cs b/tests/Pure.DI.IntegrationTests/FactoryTests.cs index ef211ef1..845a191b 100644 --- a/tests/Pure.DI.IntegrationTests/FactoryTests.cs +++ b/tests/Pure.DI.IntegrationTests/FactoryTests.cs @@ -1157,6 +1157,6 @@ public static void Main() // Then result.Success.ShouldBeTrue(result); - result.GeneratedCode.Split(Environment.NewLine).Count(i => i.Contains(" = new Sample.Dependency2();")).ShouldBe(1); + result.GeneratedCode.Split(Environment.NewLine).Count(i => i.Contains(" = new Sample.Dependency2();")).ShouldBe(2); } } \ No newline at end of file diff --git a/tests/Pure.DI.IntegrationTests/Pure.DI.IntegrationTests.csproj b/tests/Pure.DI.IntegrationTests/Pure.DI.IntegrationTests.csproj index 9cee1b51..8b053e48 100644 --- a/tests/Pure.DI.IntegrationTests/Pure.DI.IntegrationTests.csproj +++ b/tests/Pure.DI.IntegrationTests/Pure.DI.IntegrationTests.csproj @@ -7,8 +7,8 @@ - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/tests/Pure.DI.IntegrationTests/ShroedingersCatTests.cs b/tests/Pure.DI.IntegrationTests/ShroedingersCatTests.cs index 50cf0934..40d60005 100644 --- a/tests/Pure.DI.IntegrationTests/ShroedingersCatTests.cs +++ b/tests/Pure.DI.IntegrationTests/ShroedingersCatTests.cs @@ -60,7 +60,12 @@ void Setup() // FormatCode = On DI.Setup(nameof(Composition)) // Models a random subatomic event that may or may not occur - .Bind().As(Singleton).To() + .Bind().As(Singleton).To(_ => + { + var i = 0; + i++; + return new Random(); + }) // Represents a quantum superposition of 2 states: Alive or Dead .Bind().To(ctx => { @@ -93,13 +98,15 @@ public static void Main() } """.RunAsync(new Options { - LanguageVersion = LanguageVersion.CSharp8, + LanguageVersion = LanguageVersion.CSharp9, NullableContextOptions = nullableContextOptions } ); // Then result.Success.ShouldBeTrue(result); (result.StdOut.Contains("[Dead cat]") || result.StdOut.Contains("[Alive cat]")).ShouldBeTrue(result); - result.GeneratedCode.Contains("= new System.Random();").ShouldBeTrue(); + var lines = result.GeneratedCode.Split(Environment.NewLine); + lines.Count(i => i.Contains(" = new Random();")).ShouldBe(1); + lines.Count(i => i.Contains("EnsureExistenceOf_")).ShouldBe(3); } } \ No newline at end of file diff --git a/tests/Pure.DI.IntegrationTests/TestExtensions.cs b/tests/Pure.DI.IntegrationTests/TestExtensions.cs index 57818cbe..8af2c515 100644 --- a/tests/Pure.DI.IntegrationTests/TestExtensions.cs +++ b/tests/Pure.DI.IntegrationTests/TestExtensions.cs @@ -36,7 +36,7 @@ internal static async Task RunAsync(this string setupCode, Options? opti .WithLanguageVersion(runOptions.LanguageVersion); parseOptions = runOptions.PreprocessorSymbols.IsDefaultOrEmpty - ? parseOptions.WithPreprocessorSymbols("NET", "NET6_0_OR_GREATER", "NETCOREAPP2_0_OR_GREATER") + ? parseOptions.WithPreprocessorSymbols("NET", "NET6_0_OR_GREATER", "NET5_0_OR_GREATER") : parseOptions.WithPreprocessorSymbols(runOptions.PreprocessorSymbols); var generator = new Generator(); diff --git a/tests/Pure.DI.Tests/Pure.DI.Tests.csproj b/tests/Pure.DI.Tests/Pure.DI.Tests.csproj index 1cc775e8..9cd0125d 100644 --- a/tests/Pure.DI.Tests/Pure.DI.Tests.csproj +++ b/tests/Pure.DI.Tests/Pure.DI.Tests.csproj @@ -4,8 +4,8 @@ - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/tests/Pure.DI.UsageTests/Pure.DI.UsageTests.csproj b/tests/Pure.DI.UsageTests/Pure.DI.UsageTests.csproj index 5df764e9..b554943b 100644 --- a/tests/Pure.DI.UsageTests/Pure.DI.UsageTests.csproj +++ b/tests/Pure.DI.UsageTests/Pure.DI.UsageTests.csproj @@ -13,8 +13,8 @@ - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive