From 10b0ead2f8a9259dc8feb717141a4bf5342d55fe Mon Sep 17 00:00:00 2001 From: Nikolay Pianikov Date: Thu, 9 May 2024 10:06:48 +0300 Subject: [PATCH] Update README.md --- README.md | 68 ++--- build/ReadmeTarget.cs | 5 +- docs/README.md | 7 + readme/ArrayDetails.md | 22 +- readme/EnumDetails.md | 32 +-- readme/FooterTemplate.md | 5 - readme/FuncDetails.md | 24 +- readme/ReadmeTemplate.md | 42 ++- readme/SingletonDetails.md | 30 +- readme/TransientDetails.md | 22 +- readme/a-few-partial-classes.md | 14 +- readme/accumulators.md | 14 +- readme/advanced-interception.md | 14 +- readme/arguments.md | 14 +- readme/array.md | 14 +- readme/async-disposable-scope.md | 16 +- readme/async-disposable-singleton.md | 14 +- readme/async-enumerable.md | 16 +- readme/auto-bindings.md | 2 +- readme/auto-scoped.md | 16 +- readme/check-for-a-root.md | 16 +- readme/complex-generics.md | 14 +- readme/composition-root-kinds.md | 18 +- readme/composition-roots-simplified.md | 269 ------------------ readme/composition-roots.md | 44 +-- readme/constructor-ordinal-attribute.md | 16 +- readme/custom-attributes.md | 14 +- readme/decorator.md | 14 +- readme/default-lifetime.md | 18 +- readme/default-values.md | 16 +- readme/dependent-compositions.md | 30 +- readme/disposable-singleton.md | 14 +- readme/enumerable-generics.md | 20 +- readme/enumerable.md | 16 +- readme/factory.md | 21 +- readme/field-injection.md | 17 +- readme/func-with-arguments.md | 14 +- readme/func-with-tag.md | 14 +- readme/func.md | 14 +- ...eric-composition-roots-with-constraints.md | 4 +- readme/generic-composition-roots.md | 4 +- readme/generics.md | 14 +- readme/injection.md | 245 ---------------- readme/injections-of-abstractions.md | 4 +- readme/instance-initialization.md | 266 ----------------- readme/interception.md | 14 +- readme/keyed-service-provider.md | 16 +- readme/lazy.md | 14 +- readme/manually-started-tasks.md | 2 +- readme/member-ordinal-attribute.md | 17 +- readme/method-injection.md | 17 +- readme/multi-contract-bindings.md | 248 ---------------- readme/oncannotresolve-hint.md | 14 +- readme/ondependencyinjection-hint.md | 14 +- readme/onnewinstance-hint.md | 14 +- readme/overriding-the-bcl-binding.md | 14 +- readme/partial-class.md | 14 +- readme/perblock.md | 14 +- readme/perresolve.md | 14 +- readme/property-injection.md | 17 +- readme/required-properties-or-fields.md | 16 +- readme/resolve-hint.md | 4 +- readme/resolve-methods.md | 20 +- readme/root-arguments.md | 2 +- readme/{rootbind.md => root-binding.md} | 16 +- readme/scope.md | 16 +- readme/service-collection.md | 16 +- readme/service-provider-with-scope.md | 16 +- readme/service-provider.md | 16 +- readme/simplified-binding.md | 2 +- readme/singleton.md | 14 +- readme/span-and-readonlyspan.md | 14 +- readme/tag-attribute.md | 14 +- readme/tag-type.md | 16 +- readme/tag-unique.md | 16 +- readme/tags.md | 16 +- readme/task.md | 2 +- readme/threadsafe-hint.md | 14 +- readme/tostring-hint.md | 14 +- ...async-disposable-instances-in-delegates.md | 16 +- ...osable-instances-per-a-composition-root.md | 12 +- ...cking-disposable-instances-in-delegates.md | 16 +- ...osable-instances-per-a-composition-root.md | 12 +- readme/transient.md | 14 +- readme/tuple.md | 14 +- readme/type-attribute.md | 14 +- readme/valuetask.md | 14 +- readme/weak-reference.md | 14 +- samples/ShroedingersCat/Program.cs | 4 +- .../Program.cs | 4 +- .../InstanceInitializationScenario.cs | 75 ----- ...ckingAsyncDisposableInDelegatesScenario.cs | 2 +- .../TrackingAsyncDisposableScenario.cs | 2 +- .../TrackingDisposableInDelegatesScenario.cs | 2 +- .../TrackingDisposableScenario.cs | 2 +- .../ConstructorOrdinalAttributeScenario.cs | 2 + .../MemberOrdinalAttributeScenario.cs | 3 + .../Basics/CompositionRootsScenario.cs | 14 +- .../CompositionRootsSimplifiedScenario.cs | 64 ----- .../Basics/DefaultValuesScenario.cs | 2 + .../Basics/FactoryScenario.cs | 7 + .../Basics/FieldInjectionScenario.cs | 3 + .../Basics/InjectionScenario.cs | 58 ---- .../InjectionsOfAbstractionsScenario.cs | 2 +- .../Basics/MethodInjectionScenario.cs | 3 + .../Basics/MultiContractBindingsScenario.cs | 53 ---- .../Basics/PropertyInjectionScenario.cs | 3 + .../RequiredPropertiesOrFieldsScenario.cs | 2 + ...eScenario.cs => ResolveMethodsScenario.cs} | 2 +- .../Basics/RootBindScenario.cs | 2 +- .../Lifetimes/DefaultLifetimeScenario.cs | 4 + 111 files changed, 713 insertions(+), 1942 deletions(-) delete mode 100644 readme/composition-roots-simplified.md delete mode 100644 readme/injection.md delete mode 100644 readme/instance-initialization.md delete mode 100644 readme/multi-contract-bindings.md rename readme/{rootbind.md => root-binding.md} (93%) delete mode 100644 tests/Pure.DI.UsageTests/Advanced/InstanceInitializationScenario.cs rename tests/Pure.DI.UsageTests/{Basics => Advanced}/TrackingAsyncDisposableInDelegatesScenario.cs (96%) rename tests/Pure.DI.UsageTests/{Basics => Advanced}/TrackingAsyncDisposableScenario.cs (96%) rename tests/Pure.DI.UsageTests/{Basics => Advanced}/TrackingDisposableInDelegatesScenario.cs (96%) rename tests/Pure.DI.UsageTests/{Basics => Advanced}/TrackingDisposableScenario.cs (96%) delete mode 100644 tests/Pure.DI.UsageTests/Basics/CompositionRootsSimplifiedScenario.cs delete mode 100644 tests/Pure.DI.UsageTests/Basics/InjectionScenario.cs delete mode 100644 tests/Pure.DI.UsageTests/Basics/MultiContractBindingsScenario.cs rename tests/Pure.DI.UsageTests/Basics/{ResolveScenario.cs => ResolveMethodsScenario.cs} (97%) diff --git a/README.md b/README.md index c2c4bd37e..cb34f55c1 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,13 @@ ![](readme/di.gif) +## Usage requirements + +Supports .NET starting with .NET Framework 2.0 released 2005-10-27 and all newer versions. + +- Installed [.NET SDK 6.0.4](https://dotnet.microsoft.com/download/dotnet/6.0) or later +- Using [C# 8](https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-version-history#c-version-80) or later + ## Key features Pure.DI is not a framework or library, but a source code generator for creating object graphs. To make them accurate, the developer uses a set of intuitive hints from the Pure.DI API. During the compilation phase, Pure.DI determines the optimal graph structure, checks its correctness, and generates partial class code to create object graphs in the Pure DI paradigm using only basic language constructs. The resulting generated code is robust, works everywhere, throws no exceptions, does not depend on .NET library calls or .NET reflections, is efficient in terms of performance and memory consumption, and is subject to all optimizations. This code can be easily integrated into an application because it does not use unnecessary delegates, additional calls to any methods, type conversions, boxing/unboxing, etc. @@ -52,11 +59,7 @@ interface ICat State State { get; } } -enum State -{ - Alive, - Dead -} +enum State { Alive, Dead } ``` ### Here's our implementation @@ -64,18 +67,14 @@ enum State ```c# class CardboardBox(T content) : IBox { - public T Content { get; } = content; - - public override string ToString() => $"[{Content}]"; + public T Content { get; } = content; } class ShroedingersCat(Lazy superposition) : ICat { // The decoherence of the superposition // at the time of observation via an irreversible process - public State State => superposition.Value; - - public override string ToString() => $"{State} cat"; + public State State => superposition.Value; } ``` @@ -94,14 +93,14 @@ Let's bind the abstractions to their implementations and set up the creation of DI.Setup(nameof(Composition)) // Models a random subatomic event that may or may not occur .Bind().As(Singleton).To() - // Represents a quantum superposition of 2 states: Alive or Dead + // Quantum superposition of two states: Alive or Dead .Bind().To(ctx => { ctx.Inject(out var random); return (State)random.Next(2); }) .Bind().To() - // Represents a cardboard box with any contents + // Cardboard box with any contents .Bind().To>() // Composition Root .Root("Root"); @@ -113,27 +112,27 @@ The above code specifies the generation of a partial class named *__Composition_ partial class Composition { private object _lock = new object(); - private Random _random; + private Random? _random; public Program Root { get { - Func stateFunc = new Func(() => - { - if (_random == null) - { - lock (_lock) + var stateFunc = new Func(() => { if (_random == null) { - _random = new Random(); + lock (_lock) + { + if (_random == null) + { + _random = new Random(); + } + } } - } - } - - return (State)_random.Next(2); - }); + + return (State)_random.Next(2); + }); return new Program( new CardboardBox( @@ -197,25 +196,18 @@ dotnet run - [Auto-bindings](readme/auto-bindings.md) - [Injections of abstractions](readme/injections-of-abstractions.md) - [Composition roots](readme/composition-roots.md) -- [Composition roots simplified](readme/composition-roots-simplified.md) - [Resolve methods](readme/resolve-methods.md) - [Simplified binding](readme/simplified-binding.md) - [Factory](readme/factory.md) -- [Injection](readme/injection.md) - [Arguments](readme/arguments.md) - [Root arguments](readme/root-arguments.md) - [Tags](readme/tags.md) -- [Multi-contract bindings](readme/multi-contract-bindings.md) - [Field injection](readme/field-injection.md) - [Method injection](readme/method-injection.md) - [Property injection](readme/property-injection.md) - [Default values](readme/default-values.md) - [Required properties or fields](readme/required-properties-or-fields.md) -- [Tracking async disposable instances in delegates](readme/tracking-async-disposable-instances-in-delegates.md) -- [Tracking disposable instances in delegates](readme/tracking-disposable-instances-in-delegates.md) -- [Tracking disposable instances per a composition root](readme/tracking-disposable-instances-per-a-composition-root.md) -- [RootBind](readme/rootbind.md) -- [Tracking async disposable instances per a composition root](readme/tracking-async-disposable-instances-per-a-composition-root.md) +- [Root binding](readme/root-binding.md) ### Lifetimes - [Singleton](readme/singleton.md) - [PerResolve](readme/perresolve.md) @@ -272,7 +264,6 @@ dotnet run - [Check for a root](readme/check-for-a-root.md) ### Advanced - [Composition root kinds](readme/composition-root-kinds.md) -- [Instance Initialization](readme/instance-initialization.md) - [Tag Type](readme/tag-type.md) - [Tag Unique](readme/tag-unique.md) - [A few partial classes](readme/a-few-partial-classes.md) @@ -280,6 +271,10 @@ dotnet run - [Dependent compositions](readme/dependent-compositions.md) - [Accumulators](readme/accumulators.md) - [Global compositions](readme/global-compositions.md) +- [Tracking async disposable instances in delegates](readme/tracking-async-disposable-instances-in-delegates.md) +- [Tracking disposable instances in delegates](readme/tracking-disposable-instances-in-delegates.md) +- [Tracking disposable instances per a composition root](readme/tracking-disposable-instances-per-a-composition-root.md) +- [Tracking async disposable instances per a composition root](readme/tracking-async-disposable-instances-per-a-composition-root.md) ### Applications - Console - [Schrödinger's cat](readme/Console.md) @@ -824,11 +819,6 @@ Then documentation for the composition root: | Pure.DI.Templates | [![NuGet](https://buildstats.info/nuget/Pure.DI.Templates)](https://www.nuget.org/packages/Pure.DI.Templates) | Template Package you can call from the shell/command line. | | Pure.DI.MS | [![NuGet](https://buildstats.info/nuget/Pure.DI.MS)](https://www.nuget.org/packages/Pure.DI.MS) | Tools for working with Microsoft DI | -## Requirements for development environments - -- [.NET SDK 6.0.4xx or newer](https://dotnet.microsoft.com/download/dotnet/6.0) -- [C# 8 or newer](https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-version-history#c-version-80) - ## Project template Install the DI template [Pure.DI.Templates](https://www.nuget.org/packages/Pure.DI.Templates) diff --git a/build/ReadmeTarget.cs b/build/ReadmeTarget.cs index 74de94933..a2a797b4b 100644 --- a/build/ReadmeTarget.cs +++ b/build/ReadmeTarget.cs @@ -361,7 +361,10 @@ private static async Task AddExample(string logsDirectory, string exampleSearchP .Replace("System.Collections.Generic.", "") .Replace("System.", "") .Replace("Pure.DI.", "") - .Replace(salt, ""))); + .Replace(" Benchmarks.Model.", "") + .Replace(salt, "") + .Replace("(MethodImplOptions)0x100", "MethodImplOptions.AggressiveInlining") + .Replace("(MethodImplOptions)0x8", "MethodImplOptions.NoInlining"))); await examplesWriter.WriteLineAsync(generatedCode); await examplesWriter.WriteLineAsync("```"); await examplesWriter.WriteLineAsync(""); diff --git a/docs/README.md b/docs/README.md index ee0aa5a09..3765e6d02 100644 --- a/docs/README.md +++ b/docs/README.md @@ -8,6 +8,13 @@ ![](readme/di.gif) +## Usage requirements + +Supports .NET starting with .NET Framework 2.0 released 2005-10-27 and all newer versions. + +- Installed [.NET SDK 6.0.4](https://dotnet.microsoft.com/download/dotnet/6.0) or later +- Using [C# 8](https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-version-history#c-version-80) or later + ## Key features Pure.DI is not a framework or library, but a source code generator for creating object graphs. To make them accurate, the developer uses a set of intuitive hints from the Pure.DI API. During the compilation phase, Pure.DI determines the optimal graph structure, checks its correctness, and generates partial class code to create object graphs in the Pure DI paradigm using only basic language constructs. The resulting generated code is robust, works everywhere, throws no exceptions, does not depend on .NET library calls or .NET reflections, is efficient in terms of performance and memory consumption, and is subject to all optimizations. This code can be easily integrated into an application because it does not use unnecessary delegates, additional calls to any methods, type conversions, boxing/unboxing, etc. diff --git a/readme/ArrayDetails.md b/readme/ArrayDetails.md index e3ec4f7a3..d1bf10ace 100644 --- a/readme/ArrayDetails.md +++ b/readme/ArrayDetails.md @@ -100,25 +100,25 @@ partial class Array _root = (parentScope ?? throw new ArgumentNullException(nameof(parentScope)))._root; } - [MethodImpl((MethodImplOptions)0x100)] - public partial Benchmarks.Model.CompositionRoot TestPureDIByCR() + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public partialCompositionRoot TestPureDIByCR() { - return new Benchmarks.Model.CompositionRoot(new Benchmarks.Model.Service1(new Benchmarks.Model.Service2Array(new Benchmarks.Model.IService3[4] { new Benchmarks.Model.Service3(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()), new Benchmarks.Model.Service3v2(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()), new Benchmarks.Model.Service3v3(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()), new Benchmarks.Model.Service3v4(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()) })), new Benchmarks.Model.Service2Array(new Benchmarks.Model.IService3[4] { new Benchmarks.Model.Service3(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()), new Benchmarks.Model.Service3v2(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()), new Benchmarks.Model.Service3v3(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()), new Benchmarks.Model.Service3v4(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()) }), new Benchmarks.Model.Service2Array(new Benchmarks.Model.IService3[4] { new Benchmarks.Model.Service3(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()), new Benchmarks.Model.Service3v2(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()), new Benchmarks.Model.Service3v3(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()), new Benchmarks.Model.Service3v4(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()) }), new Benchmarks.Model.Service2Array(new Benchmarks.Model.IService3[4] { new Benchmarks.Model.Service3(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()), new Benchmarks.Model.Service3v2(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()), new Benchmarks.Model.Service3v3(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()), new Benchmarks.Model.Service3v4(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()) }), new Benchmarks.Model.Service3(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()), new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()); + return newCompositionRoot(newService1(newService2Array(newIService3[4] { newService3(newService4(), newService4()), newService3v2(newService4(), newService4()), newService3v3(newService4(), newService4()), newService3v4(newService4(), newService4()) })), newService2Array(newIService3[4] { newService3(newService4(), newService4()), newService3v2(newService4(), newService4()), newService3v3(newService4(), newService4()), newService3v4(newService4(), newService4()) }), newService2Array(newIService3[4] { newService3(newService4(), newService4()), newService3v2(newService4(), newService4()), newService3v3(newService4(), newService4()), newService3v4(newService4(), newService4()) }), newService2Array(newIService3[4] { newService3(newService4(), newService4()), newService3v2(newService4(), newService4()), newService3v3(newService4(), newService4()), newService3v4(newService4(), newService4()) }), newService3(newService4(), newService4()), newService4(), newService4()); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -126,7 +126,7 @@ partial class Array return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -142,7 +142,7 @@ partial class Array throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -150,7 +150,7 @@ partial class Array return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; @@ -281,12 +281,12 @@ partial class Array private sealed class Resolver_0000: Resolver { - public override Benchmarks.Model.CompositionRoot Resolve(Array composition) + public overrideCompositionRoot Resolve(Array composition) { return composition.TestPureDIByCR(); } - public override Benchmarks.Model.CompositionRoot ResolveByTag(Array composition, object tag) + public overrideCompositionRoot ResolveByTag(Array composition, object tag) { switch (tag) { diff --git a/readme/EnumDetails.md b/readme/EnumDetails.md index 2281068c1..082388bda 100644 --- a/readme/EnumDetails.md +++ b/readme/EnumDetails.md @@ -100,34 +100,34 @@ partial class Enum _root = (parentScope ?? throw new ArgumentNullException(nameof(parentScope)))._root; } - [MethodImpl((MethodImplOptions)0x100)] - public partial Benchmarks.Model.CompositionRoot TestPureDIByCR() + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public partialCompositionRoot TestPureDIByCR() { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] 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()); + yield return newService3(newService4(), newService4()); + yield return newService3v2(newService4(), newService4()); + yield return newService3v3(newService4(), newService4()); + yield return newService3v4(newService4(), newService4()); } 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()); + return newCompositionRoot(newService1(newService2Enum(perBlock10_IEnumerable)), newService2Enum(perBlock10_IEnumerable), newService2Enum(perBlock10_IEnumerable), newService2Enum(perBlock10_IEnumerable), newService3(newService4(), newService4()), newService4(), newService4()); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -135,7 +135,7 @@ partial class Enum return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -151,7 +151,7 @@ partial class Enum throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -159,7 +159,7 @@ partial class Enum return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; @@ -290,12 +290,12 @@ partial class Enum private sealed class Resolver_0000: Resolver { - public override Benchmarks.Model.CompositionRoot Resolve(Enum composition) + public overrideCompositionRoot Resolve(Enum composition) { return composition.TestPureDIByCR(); } - public override Benchmarks.Model.CompositionRoot ResolveByTag(Enum composition, object tag) + public overrideCompositionRoot ResolveByTag(Enum composition, object tag) { switch (tag) { diff --git a/readme/FooterTemplate.md b/readme/FooterTemplate.md index 3b907e5aa..e8f96781f 100644 --- a/readme/FooterTemplate.md +++ b/readme/FooterTemplate.md @@ -542,11 +542,6 @@ Then documentation for the composition root: | Pure.DI.Templates | [![NuGet](https://buildstats.info/nuget/Pure.DI.Templates)](https://www.nuget.org/packages/Pure.DI.Templates) | Template Package you can call from the shell/command line. | | Pure.DI.MS | [![NuGet](https://buildstats.info/nuget/Pure.DI.MS)](https://www.nuget.org/packages/Pure.DI.MS) | Tools for working with Microsoft DI | -## Requirements for development environments - -- [.NET SDK 6.0.4xx or newer](https://dotnet.microsoft.com/download/dotnet/6.0) -- [C# 8 or newer](https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-version-history#c-version-80) - ## Project template Install the DI template [Pure.DI.Templates](https://www.nuget.org/packages/Pure.DI.Templates) diff --git a/readme/FuncDetails.md b/readme/FuncDetails.md index 59b16fa30..6575ba10e 100644 --- a/readme/FuncDetails.md +++ b/readme/FuncDetails.md @@ -79,32 +79,32 @@ partial class Func _root = (parentScope ?? throw new ArgumentNullException(nameof(parentScope)))._root; } - [MethodImpl((MethodImplOptions)0x100)] - public partial Benchmarks.Model.CompositionRoot TestPureDIByCR() + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public partialCompositionRoot TestPureDIByCR() { Func perBlock10_Func = new Func( [MethodImpl((MethodImplOptions)256)] () => { - var value_1 = new Benchmarks.Model.Service3(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()); + var value_1 = newService3(newService4(), newService4()); return value_1; }); - return new Benchmarks.Model.CompositionRoot(new Benchmarks.Model.Service1(new Benchmarks.Model.Service2Func(perBlock10_Func)), new Benchmarks.Model.Service2Func(perBlock10_Func), new Benchmarks.Model.Service2Func(perBlock10_Func), new Benchmarks.Model.Service2Func(perBlock10_Func), new Benchmarks.Model.Service3(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()), new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()); + return newCompositionRoot(newService1(newService2Func(perBlock10_Func)), newService2Func(perBlock10_Func), newService2Func(perBlock10_Func), newService2Func(perBlock10_Func), newService3(newService4(), newService4()), newService4(), newService4()); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -112,7 +112,7 @@ partial class Func return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -128,7 +128,7 @@ partial class Func throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -136,7 +136,7 @@ partial class Func return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; @@ -246,12 +246,12 @@ partial class Func private sealed class Resolver_0000: Resolver { - public override Benchmarks.Model.CompositionRoot Resolve(Func composition) + public overrideCompositionRoot Resolve(Func composition) { return composition.TestPureDIByCR(); } - public override Benchmarks.Model.CompositionRoot ResolveByTag(Func composition, object tag) + public overrideCompositionRoot ResolveByTag(Func composition, object tag) { switch (tag) { diff --git a/readme/ReadmeTemplate.md b/readme/ReadmeTemplate.md index 65017063a..ca0cb68c0 100644 --- a/readme/ReadmeTemplate.md +++ b/readme/ReadmeTemplate.md @@ -19,11 +19,7 @@ interface ICat State State { get; } } -enum State -{ - Alive, - Dead -} +enum State { Alive, Dead } ``` ### Here's our implementation @@ -31,18 +27,14 @@ enum State ```c# class CardboardBox(T content) : IBox { - public T Content { get; } = content; - - public override string ToString() => $"[{Content}]"; + public T Content { get; } = content; } class ShroedingersCat(Lazy superposition) : ICat { // The decoherence of the superposition // at the time of observation via an irreversible process - public State State => superposition.Value; - - public override string ToString() => $"{State} cat"; + public State State => superposition.Value; } ``` @@ -61,14 +53,14 @@ Let's bind the abstractions to their implementations and set up the creation of DI.Setup(nameof(Composition)) // Models a random subatomic event that may or may not occur .Bind().As(Singleton).To() - // Represents a quantum superposition of 2 states: Alive or Dead + // Quantum superposition of two states: Alive or Dead .Bind().To(ctx => { ctx.Inject(out var random); return (State)random.Next(2); }) .Bind().To() - // Represents a cardboard box with any contents + // Cardboard box with any contents .Bind().To>() // Composition Root .Root("Root"); @@ -80,27 +72,27 @@ The above code specifies the generation of a partial class named *__Composition_ partial class Composition { private object _lock = new object(); - private Random _random; + private Random? _random; public Program Root { get { - Func stateFunc = new Func(() => - { - if (_random == null) - { - lock (_lock) + var stateFunc = new Func(() => { if (_random == null) { - _random = new Random(); + lock (_lock) + { + if (_random == null) + { + _random = new Random(); + } + } } - } - } - - return (State)_random.Next(2); - }); + + return (State)_random.Next(2); + }); return new Program( new CardboardBox( diff --git a/readme/SingletonDetails.md b/readme/SingletonDetails.md index fd1a53da7..69dd8e0b3 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; + privateService1? _scoped37_Service1; + privateService4? _scoped40_Service4; public Singleton() { @@ -83,33 +83,33 @@ partial class Singleton _root = (parentScope ?? throw new ArgumentNullException(nameof(parentScope)))._root; } - [MethodImpl((MethodImplOptions)0x100)] - public partial Benchmarks.Model.CompositionRoot TestPureDIByCR() + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public partialCompositionRoot TestPureDIByCR() { if (_scoped40_Service4 == null) { - _scoped40_Service4 = new Benchmarks.Model.Service4(); + _scoped40_Service4 = newService4(); } 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 = newService1(newService2(newService3(_scoped40_Service4!, _scoped40_Service4!), newService3(_scoped40_Service4!, _scoped40_Service4!), newService3(_scoped40_Service4!, _scoped40_Service4!), newService3(_scoped40_Service4!, _scoped40_Service4!), newService3(_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 newCompositionRoot(_scoped37_Service1!, newService2(newService3(_scoped40_Service4!, _scoped40_Service4!), newService3(_scoped40_Service4!, _scoped40_Service4!), newService3(_scoped40_Service4!, _scoped40_Service4!), newService3(_scoped40_Service4!, _scoped40_Service4!), newService3(_scoped40_Service4!, _scoped40_Service4!)), newService2(newService3(_scoped40_Service4!, _scoped40_Service4!), newService3(_scoped40_Service4!, _scoped40_Service4!), newService3(_scoped40_Service4!, _scoped40_Service4!), newService3(_scoped40_Service4!, _scoped40_Service4!), newService3(_scoped40_Service4!, _scoped40_Service4!)), newService2(newService3(_scoped40_Service4!, _scoped40_Service4!), newService3(_scoped40_Service4!, _scoped40_Service4!), newService3(_scoped40_Service4!, _scoped40_Service4!), newService3(_scoped40_Service4!, _scoped40_Service4!), newService3(_scoped40_Service4!, _scoped40_Service4!)), newService3(_scoped40_Service4!, _scoped40_Service4!), _scoped40_Service4!, _scoped40_Service4!); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -117,7 +117,7 @@ partial class Singleton return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -133,7 +133,7 @@ partial class Singleton throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -141,7 +141,7 @@ partial class Singleton return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; @@ -253,12 +253,12 @@ partial class Singleton private sealed class Resolver_0000: Resolver { - public override Benchmarks.Model.CompositionRoot Resolve(Singleton composition) + public overrideCompositionRoot Resolve(Singleton composition) { return composition.TestPureDIByCR(); } - public override Benchmarks.Model.CompositionRoot ResolveByTag(Singleton composition, object tag) + public overrideCompositionRoot ResolveByTag(Singleton composition, object tag) { switch (tag) { diff --git a/readme/TransientDetails.md b/readme/TransientDetails.md index fae00645c..046c8b97a 100644 --- a/readme/TransientDetails.md +++ b/readme/TransientDetails.md @@ -81,25 +81,25 @@ partial class Transient _root = (parentScope ?? throw new ArgumentNullException(nameof(parentScope)))._root; } - [MethodImpl((MethodImplOptions)0x100)] - public partial Benchmarks.Model.CompositionRoot TestPureDIByCR() + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public partialCompositionRoot TestPureDIByCR() { - return new Benchmarks.Model.CompositionRoot(new Benchmarks.Model.Service1(new Benchmarks.Model.Service2(new Benchmarks.Model.Service3(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()), new Benchmarks.Model.Service3(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()), new Benchmarks.Model.Service3(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()), new Benchmarks.Model.Service3(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()), new Benchmarks.Model.Service3(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()))), new Benchmarks.Model.Service2(new Benchmarks.Model.Service3(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()), new Benchmarks.Model.Service3(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()), new Benchmarks.Model.Service3(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()), new Benchmarks.Model.Service3(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()), new Benchmarks.Model.Service3(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4())), new Benchmarks.Model.Service2(new Benchmarks.Model.Service3(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()), new Benchmarks.Model.Service3(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()), new Benchmarks.Model.Service3(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()), new Benchmarks.Model.Service3(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()), new Benchmarks.Model.Service3(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4())), new Benchmarks.Model.Service2(new Benchmarks.Model.Service3(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()), new Benchmarks.Model.Service3(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()), new Benchmarks.Model.Service3(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()), new Benchmarks.Model.Service3(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()), new Benchmarks.Model.Service3(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4())), new Benchmarks.Model.Service3(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()), new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4()); + return newCompositionRoot(newService1(newService2(newService3(newService4(), newService4()), newService3(newService4(), newService4()), newService3(newService4(), newService4()), newService3(newService4(), newService4()), newService3(newService4(), newService4()))), newService2(newService3(newService4(), newService4()), newService3(newService4(), newService4()), newService3(newService4(), newService4()), newService3(newService4(), newService4()), newService3(newService4(), newService4())), newService2(newService3(newService4(), newService4()), newService3(newService4(), newService4()), newService3(newService4(), newService4()), newService3(newService4(), newService4()), newService3(newService4(), newService4())), newService2(newService3(newService4(), newService4()), newService3(newService4(), newService4()), newService3(newService4(), newService4()), newService3(newService4(), newService4()), newService3(newService4(), newService4())), newService3(newService4(), newService4()), newService4(), newService4()); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -107,7 +107,7 @@ partial class Transient return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -123,7 +123,7 @@ partial class Transient throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -131,7 +131,7 @@ partial class Transient return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; @@ -243,12 +243,12 @@ partial class Transient private sealed class Resolver_0000: Resolver { - public override Benchmarks.Model.CompositionRoot Resolve(Transient composition) + public overrideCompositionRoot Resolve(Transient composition) { return composition.TestPureDIByCR(); } - public override Benchmarks.Model.CompositionRoot ResolveByTag(Transient composition, object tag) + public overrideCompositionRoot ResolveByTag(Transient composition, object tag) { switch (tag) { diff --git a/readme/a-few-partial-classes.md b/readme/a-few-partial-classes.md index 11cf89026..3c23daee4 100644 --- a/readme/a-few-partial-classes.md +++ b/readme/a-few-partial-classes.md @@ -93,26 +93,26 @@ partial class Composition public IService Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return new Service(new Dependency()); } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -120,7 +120,7 @@ partial class Composition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -136,7 +136,7 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -144,7 +144,7 @@ partial class Composition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/accumulators.md b/readme/accumulators.md index 85b9f6ce2..fa6a04898 100644 --- a/readme/accumulators.md +++ b/readme/accumulators.md @@ -108,7 +108,7 @@ partial class Composition public (IService service, MyAccumulator accumulator) Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { var accumulator42 = new MyAccumulator(); @@ -141,19 +141,19 @@ partial class Composition } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -161,7 +161,7 @@ partial class Composition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -177,7 +177,7 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -185,7 +185,7 @@ partial class Composition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/advanced-interception.md b/readme/advanced-interception.md index 0e975bfa1..a12c43128 100644 --- a/readme/advanced-interception.md +++ b/readme/advanced-interception.md @@ -161,26 +161,26 @@ partial class Composition public IService Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return OnDependencyInjection(new Service(OnDependencyInjection(new Dependency(), null, Lifetime.Transient)), null, Lifetime.Transient); } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -188,7 +188,7 @@ partial class Composition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -204,7 +204,7 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -212,7 +212,7 @@ partial class Composition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/arguments.md b/readme/arguments.md index 67c388804..7214e8e43 100644 --- a/readme/arguments.md +++ b/readme/arguments.md @@ -117,26 +117,26 @@ partial class Composition public IService Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return new Service(_arg_serviceName, new Dependency(_arg_id)); } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -144,7 +144,7 @@ partial class Composition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -160,7 +160,7 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -168,7 +168,7 @@ partial class Composition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/array.md b/readme/array.md index eb27d19ea..46eb12847 100644 --- a/readme/array.md +++ b/readme/array.md @@ -121,26 +121,26 @@ partial class Composition public IService Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return new Service(new IDependency[2] { new AbcDependency(), new XyzDependency() }); } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -148,7 +148,7 @@ partial class Composition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -164,7 +164,7 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -172,7 +172,7 @@ partial class Composition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/async-disposable-scope.md b/readme/async-disposable-scope.md index 96bcfae44..982911198 100644 --- a/readme/async-disposable-scope.md +++ b/readme/async-disposable-scope.md @@ -158,7 +158,7 @@ partial class Composition: IDisposable, IAsyncDisposable public IService SessionRoot { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { if (_scoped36_Dependency == null) @@ -178,7 +178,7 @@ partial class Composition: IDisposable, IAsyncDisposable public Program ProgramRoot { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { var perResolve43_Func = default(Func); @@ -194,19 +194,19 @@ partial class Composition: IDisposable, IAsyncDisposable } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 4)); @@ -214,7 +214,7 @@ partial class Composition: IDisposable, IAsyncDisposable return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -230,7 +230,7 @@ partial class Composition: IDisposable, IAsyncDisposable throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 4)); @@ -238,7 +238,7 @@ partial class Composition: IDisposable, IAsyncDisposable return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/async-disposable-singleton.md b/readme/async-disposable-singleton.md index 5ed07b229..2136eb2fe 100644 --- a/readme/async-disposable-singleton.md +++ b/readme/async-disposable-singleton.md @@ -111,7 +111,7 @@ partial class Composition: IDisposable, IAsyncDisposable public IService Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { if (_root._singleton36_Dependency == null) @@ -129,19 +129,19 @@ partial class Composition: IDisposable, IAsyncDisposable } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -149,7 +149,7 @@ partial class Composition: IDisposable, IAsyncDisposable return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -165,7 +165,7 @@ partial class Composition: IDisposable, IAsyncDisposable throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -173,7 +173,7 @@ partial class Composition: IDisposable, IAsyncDisposable return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/async-enumerable.md b/readme/async-enumerable.md index 770c4f95c..8b479c346 100644 --- a/readme/async-enumerable.md +++ b/readme/async-enumerable.md @@ -104,10 +104,10 @@ partial class Composition public IService Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] async IAsyncEnumerable EnumerationOf_transient1_IAsyncEnumerable() { yield return new AbcDependency(); @@ -119,19 +119,19 @@ partial class Composition } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -139,7 +139,7 @@ partial class Composition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -155,7 +155,7 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -163,7 +163,7 @@ partial class Composition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/auto-bindings.md b/readme/auto-bindings.md index b4d6412ad..262c9266a 100644 --- a/readme/auto-bindings.md +++ b/readme/auto-bindings.md @@ -65,7 +65,7 @@ partial class Composition public Service MyService { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return new Service(new Dependency()); diff --git a/readme/auto-scoped.md b/readme/auto-scoped.md index 5d0644102..f0c901d96 100644 --- a/readme/auto-scoped.md +++ b/readme/auto-scoped.md @@ -124,7 +124,7 @@ partial class Composition private Service SessionRoot { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { if (_scoped36_Dependency == null) @@ -143,7 +143,7 @@ partial class Composition public Program ProgramRoot { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { var perResolve43_Func = default(Func); @@ -166,19 +166,19 @@ partial class Composition } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 4)); @@ -186,7 +186,7 @@ partial class Composition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -202,7 +202,7 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 4)); @@ -210,7 +210,7 @@ partial class Composition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/check-for-a-root.md b/readme/check-for-a-root.md index db75845e7..84c8a158a 100644 --- a/readme/check-for-a-root.md +++ b/readme/check-for-a-root.md @@ -113,7 +113,7 @@ partial class Composition public IService Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return new Service() @@ -125,26 +125,26 @@ partial class Composition private IDependency Root0001 { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return new Dependency(); } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 4)); @@ -152,7 +152,7 @@ partial class Composition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -168,7 +168,7 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 4)); @@ -176,7 +176,7 @@ partial class Composition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/complex-generics.md b/readme/complex-generics.md index 4fc557550..53ca34c24 100644 --- a/readme/complex-generics.md +++ b/readme/complex-generics.md @@ -124,26 +124,26 @@ partial class Composition public Program Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return new Program(new Service, Dictionary>(new Dependency(), new DependencyStruct())); } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -151,7 +151,7 @@ partial class Composition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -167,7 +167,7 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -175,7 +175,7 @@ partial class Composition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/composition-root-kinds.md b/readme/composition-root-kinds.md index 592549d08..540f6830b 100644 --- a/readme/composition-root-kinds.md +++ b/readme/composition-root-kinds.md @@ -102,13 +102,13 @@ partial class Composition _root = (parentScope ?? throw new ArgumentNullException(nameof(parentScope)))._root; } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] private partial IService GetRoot() { return new Service(new Dependency()); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public IService GetOtherService() { return new OtherService(); @@ -116,26 +116,26 @@ partial class Composition internal static IDependency Dependency { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return new Dependency(); } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 4)); @@ -143,7 +143,7 @@ partial class Composition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -159,7 +159,7 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 4)); @@ -167,7 +167,7 @@ partial class Composition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/composition-roots-simplified.md b/readme/composition-roots-simplified.md deleted file mode 100644 index 4c1ca5d28..000000000 --- a/readme/composition-roots-simplified.md +++ /dev/null @@ -1,269 +0,0 @@ -#### Composition roots simplified - -[![CSharp](https://img.shields.io/badge/C%23-code-blue.svg)](../tests/Pure.DI.UsageTests/Basics/CompositionRootsSimplifiedScenario.cs) - -You can use `RootBind()` method in order to reduce repetitions. - -```c# -interface IDependency; - -class Dependency : IDependency; - -interface IService; - -class Service(IDependency dependency) : IService; - -class OtherService : IService; - -DI.Setup(nameof(Composition)) - // Specifies to create a regular public composition root - // of type "IService" with the name "MyRoot" and - // it's the equivalent of statements - // .Bind().To().Root("MyRoot") - .RootBind("MyRoot").To() - - // Specifies to create a private composition root - // that is only accessible from "Resolve()" methods and - // it's the equivalent of statements - // .Bind("Other").To().Root("MyRoot") - .RootBind(tags: "Other").To() - - .Bind().To(); - -var composition = new Composition(); - -// service = new Service(new Dependency()); -var service = composition.MyRoot; - -// someOtherService = new OtherService(); -var someOtherService = composition.Resolve("Other"); -``` - -
-Class Diagram - -```mermaid -classDiagram - class Composition { - +IService MyRoot - -IService _ - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - Service --|> IService : - class Service { - +Service(IDependency dependency) - } - OtherService --|> IService : "Other" - class OtherService { - +OtherService() - } - Dependency --|> IDependency : - class Dependency { - +Dependency() - } - class IService { - <> - } - class IDependency { - <> - } - Service *-- Dependency : IDependency - Composition ..> Service : IService MyRoot - Composition ..> OtherService : IService _ -``` - -
- -
-Pure.DI-generated partial class Composition
- -```c# -partial class Composition -{ - private readonly Composition _root; - - public Composition() - { - _root = this; - } - - internal Composition(Composition parentScope) - { - _root = (parentScope ?? throw new ArgumentNullException(nameof(parentScope)))._root; - } - - public IService MyRoot - { - [MethodImpl((MethodImplOptions)0x100)] - get - { - return new Service(new Dependency()); - } - } - - private IService Root0002 - { - [MethodImpl((MethodImplOptions)0x100)] - get - { - return new OtherService(); - } - } - - [MethodImpl((MethodImplOptions)0x100)] - public T Resolve() - { - return Resolver.Value.Resolve(this); - } - - [MethodImpl((MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return Resolver.Value.ResolveByTag(this, tag); - } - - [MethodImpl((MethodImplOptions)0x100)] - public object Resolve(Type type) - { - var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _buckets[index]; - return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); - } - - [MethodImpl((MethodImplOptions)0x8)] - private object Resolve(Type type, int index) - { - var finish = index + _bucketSize; - while (++index < finish) - { - ref var pair = ref _buckets[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); - } - - [MethodImpl((MethodImplOptions)0x100)] - public object Resolve(Type type, object? tag) - { - var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _buckets[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); - } - - [MethodImpl((MethodImplOptions)0x8)] - private object Resolve(Type type, object? tag, int index) - { - var finish = index + _bucketSize; - while (++index < finish) - { - ref var pair = ref _buckets[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new InvalidOperationException($"{CannotResolveMessage} \"{tag}\" {OfTypeMessage} {type}."); - } - - public override string ToString() - { - return - "classDiagram\n" + - " class Composition {\n" + - " +IService MyRoot\n" + - " -IService _\n" + - " + T ResolveᐸTᐳ()\n" + - " + T ResolveᐸTᐳ(object? tag)\n" + - " + object Resolve(Type type)\n" + - " + object Resolve(Type type, object? tag)\n" + - " }\n" + - " Service --|> IService : \n" + - " class Service {\n" + - " +Service(IDependency dependency)\n" + - " }\n" + - " OtherService --|> IService : \"Other\" \n" + - " class OtherService {\n" + - " +OtherService()\n" + - " }\n" + - " Dependency --|> IDependency : \n" + - " class Dependency {\n" + - " +Dependency()\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " Service *-- Dependency : IDependency\n" + - " Composition ..> Service : IService MyRoot\n" + - " Composition ..> OtherService : IService _"; - } - - private readonly static int _bucketSize; - private readonly static Pair>[] _buckets; - - static Composition() - { - var valResolver_0000 = new Resolver_0000(); - Resolver.Value = valResolver_0000; - _buckets = Buckets>.Create( - 1, - out _bucketSize, - new Pair>[1] - { - new Pair>(typeof(IService), valResolver_0000) - }); - } - - private const string CannotResolveMessage = "Cannot resolve composition root "; - private const string OfTypeMessage = "of type "; - - private class Resolver: IResolver - { - public static IResolver Value = new Resolver(); - - public virtual T Resolve(Composition composite) - { - throw new InvalidOperationException($"{CannotResolveMessage}{OfTypeMessage}{typeof(T)}."); - } - - public virtual T ResolveByTag(Composition composite, object tag) - { - throw new InvalidOperationException($"{CannotResolveMessage}\"{tag}\" {OfTypeMessage}{typeof(T)}."); - } - } - - private sealed class Resolver_0000: Resolver - { - public override IService Resolve(Composition composition) - { - return composition.MyRoot; - } - - public override IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case "Other": - return composition.Root0002; - case null: - return composition.MyRoot; - default: - return base.ResolveByTag(composition, tag); - } - } - } -} -``` - -
- diff --git a/readme/composition-roots.md b/readme/composition-roots.md index 89bed2cf8..66d09c854 100644 --- a/readme/composition-roots.md +++ b/readme/composition-roots.md @@ -20,18 +20,18 @@ DI.Setup(nameof(Composition)) .Bind("Other").To() .Bind().To() - // Specifies to create a regular public composition root - // of type "IService" with the name "SomeOtherService" - // using the "Other" tag - .Root("SomeOtherService", "Other") - // Specifies to create a regular public composition root // of type "IService" with the name "MyRoot" .Root("MyRoot") // Specifies to create a private composition root // that is only accessible from "Resolve()" methods - .Root(); + .Root() + + // Specifies to create a regular public composition root + // of type "IService" with the name "SomeOtherService" + // using the "Other" tag + .Root("SomeOtherService", "Other"); var composition = new Composition(); @@ -41,6 +41,8 @@ var service = composition.MyRoot; // someOtherService = new OtherService(); var someOtherService = composition.SomeOtherService; +// All and only the roots of the composition +// can be obtained by Resolve method var dependency = composition.Resolve(); ``` @@ -96,9 +98,9 @@ classDiagram <> } Service *-- Dependency : IDependency - Composition ..> OtherService : IService SomeOtherService Composition ..> Service : IService MyRoot Composition ..> Dependency : IDependency _ + Composition ..> OtherService : IService SomeOtherService ``` @@ -123,7 +125,7 @@ partial class Composition public IService MyRoot { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return new Service(new Dependency()); @@ -132,35 +134,35 @@ partial class Composition public IService SomeOtherService { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return new OtherService(); } } - private IDependency Root0003 + private IDependency Root0002 { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return new Dependency(); } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 4)); @@ -168,7 +170,7 @@ partial class Composition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -184,7 +186,7 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 4)); @@ -192,7 +194,7 @@ partial class Composition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; @@ -240,9 +242,9 @@ partial class Composition " <>\n" + " }\n" + " Service *-- Dependency : IDependency\n" + - " Composition ..> OtherService : IService SomeOtherService\n" + " Composition ..> Service : IService MyRoot\n" + - " Composition ..> Dependency : IDependency _"; + " Composition ..> Dependency : IDependency _\n" + + " Composition ..> OtherService : IService SomeOtherService"; } private readonly static int _bucketSize; @@ -307,7 +309,7 @@ partial class Composition { public override IDependency Resolve(Composition composition) { - return composition.Root0003; + return composition.Root0002; } public override IDependency ResolveByTag(Composition composition, object tag) @@ -315,7 +317,7 @@ partial class Composition switch (tag) { case null: - return composition.Root0003; + return composition.Root0002; default: return base.ResolveByTag(composition, tag); } diff --git a/readme/constructor-ordinal-attribute.md b/readme/constructor-ordinal-attribute.md index ebfecef99..1bef1d1ce 100644 --- a/readme/constructor-ordinal-attribute.md +++ b/readme/constructor-ordinal-attribute.md @@ -15,6 +15,8 @@ class Service : IService { private readonly string _name; + // The integer value in the argument specifies + // the ordinal of injection [Ordinal(1)] public Service(IDependency dependency) => _name = "with dependency"; @@ -92,26 +94,26 @@ partial class Composition public IService Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return new Service(_arg_serviceName); } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -119,7 +121,7 @@ partial class Composition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -135,7 +137,7 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -143,7 +145,7 @@ partial class Composition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/custom-attributes.md b/readme/custom-attributes.md index dc1c3e4b8..75cc440e6 100644 --- a/readme/custom-attributes.md +++ b/readme/custom-attributes.md @@ -108,7 +108,7 @@ partial class PersonComposition public IPerson Person { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { string transient1_String = "Nik"; @@ -118,19 +118,19 @@ partial class PersonComposition } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -138,7 +138,7 @@ partial class PersonComposition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -154,7 +154,7 @@ partial class PersonComposition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -162,7 +162,7 @@ partial class PersonComposition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/decorator.md b/readme/decorator.md index 2121a9a1f..74ceb0173 100644 --- a/readme/decorator.md +++ b/readme/decorator.md @@ -78,26 +78,26 @@ partial class Composition public IService Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return new GreetingService(new Service()); } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -105,7 +105,7 @@ partial class Composition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -121,7 +121,7 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -129,7 +129,7 @@ partial class Composition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/default-lifetime.md b/readme/default-lifetime.md index 1aaa0df4f..30ba88406 100644 --- a/readme/default-lifetime.md +++ b/readme/default-lifetime.md @@ -27,7 +27,11 @@ class Service( } DI.Setup(nameof(Composition)) + // Default Lifetime applies + // to all bindings until the end of the chain + // or the next call to the DefaultLifetime method .DefaultLifetime(Lifetime.Singleton) + .Bind().To() .RootBind("Root").To(); @@ -96,7 +100,7 @@ partial class Composition public IService Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { if (_root._singleton37_Service == null) @@ -117,19 +121,19 @@ partial class Composition } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -137,7 +141,7 @@ partial class Composition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -153,7 +157,7 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -161,7 +165,7 @@ partial class Composition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/default-values.md b/readme/default-values.md index 82b0d5a63..cc915ac15 100644 --- a/readme/default-values.md +++ b/readme/default-values.md @@ -14,6 +14,8 @@ interface IService IDependency Dependency { get;} } +// If injection cannot be performed explicitly, +// the default value will be used class Service(string name = "My Service") : IService { public string Name { get; } = name; @@ -87,7 +89,7 @@ partial class Composition public IService Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return new Service() @@ -97,19 +99,19 @@ partial class Composition } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -117,7 +119,7 @@ partial class Composition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -133,7 +135,7 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -141,7 +143,7 @@ partial class Composition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/dependent-compositions.md b/readme/dependent-compositions.md index f96dced37..d372c06c7 100644 --- a/readme/dependent-compositions.md +++ b/readme/dependent-compositions.md @@ -104,26 +104,26 @@ partial class Composition public IService Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return new Service(new Dependency()); } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -131,7 +131,7 @@ partial class Composition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -147,7 +147,7 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -155,7 +155,7 @@ partial class Composition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; @@ -277,7 +277,7 @@ partial class OtherComposition public IService Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return new Service(new Dependency()); @@ -286,26 +286,26 @@ partial class OtherComposition public Program Program { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return new Program(new Service(new Dependency())); } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 4)); @@ -313,7 +313,7 @@ partial class OtherComposition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -329,7 +329,7 @@ partial class OtherComposition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 4)); @@ -337,7 +337,7 @@ partial class OtherComposition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/disposable-singleton.md b/readme/disposable-singleton.md index afe0bb22d..c0c73863f 100644 --- a/readme/disposable-singleton.md +++ b/readme/disposable-singleton.md @@ -104,7 +104,7 @@ partial class Composition: IDisposable public IService Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { if (_root._singleton36_Dependency == null) @@ -122,19 +122,19 @@ partial class Composition: IDisposable } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -142,7 +142,7 @@ partial class Composition: IDisposable return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -158,7 +158,7 @@ partial class Composition: IDisposable throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -166,7 +166,7 @@ partial class Composition: IDisposable return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/enumerable-generics.md b/readme/enumerable-generics.md index ffbd22122..05aed1131 100644 --- a/readme/enumerable-generics.md +++ b/readme/enumerable-generics.md @@ -125,10 +125,10 @@ partial class Composition public IService IntRoot { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] IEnumerable> EnumerationOf_perBlock1_IEnumerable() { yield return new AbcDependency(); @@ -141,10 +141,10 @@ partial class Composition public IService StringRoot { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] IEnumerable> EnumerationOf_perBlock1_IEnumerable() { yield return new AbcDependency(); @@ -155,19 +155,19 @@ partial class Composition } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 4)); @@ -175,7 +175,7 @@ partial class Composition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -191,7 +191,7 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 4)); @@ -199,7 +199,7 @@ partial class Composition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/enumerable.md b/readme/enumerable.md index dedf0b3ac..3d70185b4 100644 --- a/readme/enumerable.md +++ b/readme/enumerable.md @@ -96,10 +96,10 @@ partial class Composition public IService Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] IEnumerable EnumerationOf_perBlock1_IEnumerable() { yield return new AbcDependency(); @@ -110,19 +110,19 @@ partial class Composition } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -130,7 +130,7 @@ partial class Composition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -146,7 +146,7 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -154,7 +154,7 @@ partial class Composition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/factory.md b/readme/factory.md index e528d1722..a26b03018 100644 --- a/readme/factory.md +++ b/readme/factory.md @@ -35,8 +35,15 @@ DI.Setup(nameof(Composition)) .Bind().To(_ => DateTimeOffset.Now) .Bind().To(ctx => { + // Some custom logic for creating an instance. + // For example, here's how you can inject + // an instance of a particular type ctx.Inject(out Dependency dependency); + + // And do something about it dependency.Initialize(); + + // And at the end return an instance return dependency; }) .Bind().To() @@ -99,7 +106,7 @@ partial class Composition public IService Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { DateTimeOffset transient3_DateTimeOffset = DateTimeOffset.Now; @@ -113,19 +120,19 @@ partial class Composition } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -133,7 +140,7 @@ partial class Composition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -149,7 +156,7 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -157,7 +164,7 @@ partial class Composition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/field-injection.md b/readme/field-injection.md index 720077ebb..88dd32402 100644 --- a/readme/field-injection.md +++ b/readme/field-injection.md @@ -16,6 +16,9 @@ interface IService class Service : IService { + // The Ordinal attribute specifies to perform an injection, + // the integer value in the argument specifies + // the ordinal of injection [Ordinal(0)] internal IDependency? DependencyVal; @@ -87,7 +90,7 @@ partial class Composition public IService Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { Service transient0_Service = new Service(); @@ -96,19 +99,19 @@ partial class Composition } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -116,7 +119,7 @@ partial class Composition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -132,7 +135,7 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -140,7 +143,7 @@ partial class Composition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/func-with-arguments.md b/readme/func-with-arguments.md index 75bdc3e57..51043a22e 100644 --- a/readme/func-with-arguments.md +++ b/readme/func-with-arguments.md @@ -129,7 +129,7 @@ partial class Composition public IService Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { Func transient1_Func = dependencyId => @@ -152,19 +152,19 @@ partial class Composition } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -172,7 +172,7 @@ partial class Composition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -188,7 +188,7 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -196,7 +196,7 @@ partial class Composition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/func-with-tag.md b/readme/func-with-tag.md index 0ac155b90..5501bda64 100644 --- a/readme/func-with-tag.md +++ b/readme/func-with-tag.md @@ -92,7 +92,7 @@ partial class Composition public IService Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { var perResolve39_Func = default(Func); @@ -107,19 +107,19 @@ partial class Composition } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -127,7 +127,7 @@ partial class Composition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -143,7 +143,7 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -151,7 +151,7 @@ partial class Composition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/func.md b/readme/func.md index 5760597c4..2b13bb345 100644 --- a/readme/func.md +++ b/readme/func.md @@ -95,7 +95,7 @@ partial class Composition public IService Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { var perResolve39_Func = default(Func); @@ -110,19 +110,19 @@ partial class Composition } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -130,7 +130,7 @@ partial class Composition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -146,7 +146,7 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -154,7 +154,7 @@ partial class Composition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/generic-composition-roots-with-constraints.md b/readme/generic-composition-roots-with-constraints.md index a5ba2d667..e30ab5230 100644 --- a/readme/generic-composition-roots-with-constraints.md +++ b/readme/generic-composition-roots-with-constraints.md @@ -107,7 +107,7 @@ partial class Composition _root = (parentScope ?? throw new ArgumentNullException(nameof(parentScope)))._root; } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public IService GetMyRoot() where T: IDisposable where T4: struct @@ -115,7 +115,7 @@ partial class Composition return new Service(new Dependency()); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public IService GetOtherService() where T: IDisposable { diff --git a/readme/generic-composition-roots.md b/readme/generic-composition-roots.md index 3d91467f0..2840c1823 100644 --- a/readme/generic-composition-roots.md +++ b/readme/generic-composition-roots.md @@ -101,13 +101,13 @@ partial class Composition _root = (parentScope ?? throw new ArgumentNullException(nameof(parentScope)))._root; } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public IService GetMyRoot() { return new Service(new Dependency()); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public IService GetOtherService() { OtherService transient0_OtherService; diff --git a/readme/generics.md b/readme/generics.md index 213a8968d..624012b1d 100644 --- a/readme/generics.md +++ b/readme/generics.md @@ -110,26 +110,26 @@ partial class Composition public IService Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return new Service(new Dependency(), new Dependency()); } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -137,7 +137,7 @@ partial class Composition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -153,7 +153,7 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -161,7 +161,7 @@ partial class Composition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/injection.md b/readme/injection.md deleted file mode 100644 index f348d9d6a..000000000 --- a/readme/injection.md +++ /dev/null @@ -1,245 +0,0 @@ -#### Injection - -[![CSharp](https://img.shields.io/badge/C%23-code-blue.svg)](../tests/Pure.DI.UsageTests/Basics/InjectionScenario.cs) - -This example shows how to manually create and initialize an instance by injecting the necessary dependencies. - -```c# -interface IDependency; - -class Dependency : IDependency; - -interface IService -{ - IDependency Dependency { get; } -} - -class Service(IDependency dependency) : IService -{ - public IDependency Dependency { get; } = dependency; -} - -DI.Setup(nameof(Composition)) - .Bind().To() - .Bind() - .To(ctx => - { - ctx.Inject(out var dependency); - return new Service(dependency); - }) - - // Composition root - .Root("Root"); - -var composition = new Composition(); -var service = composition.Root; -``` - -In addition to the dependency type, you can specify the dependency tag in the first parameter. Then the overloaded method `void Inject(object tag, out T value)` is used. Where the first argument is the tag, the second is the dependency instance. - -
-Class Diagram - -```mermaid -classDiagram - class Composition { - +IService Root - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - Service --|> IService : - class Service - Dependency --|> IDependency : - class Dependency { - +Dependency() - } - class IService { - <> - } - class IDependency { - <> - } - Service *-- Dependency : IDependency - Composition ..> Service : IService Root -``` - -
- -
-Pure.DI-generated partial class Composition
- -```c# -partial class Composition -{ - private readonly Composition _root; - - public Composition() - { - _root = this; - } - - internal Composition(Composition parentScope) - { - _root = (parentScope ?? throw new ArgumentNullException(nameof(parentScope)))._root; - } - - public IService Root - { - [MethodImpl((MethodImplOptions)0x100)] - get - { - Service transient0_Service; - { - var dependency_1 = new Dependency(); - transient0_Service = new Service(dependency_1); - } - return transient0_Service; - } - } - - [MethodImpl((MethodImplOptions)0x100)] - public T Resolve() - { - return Resolver.Value.Resolve(this); - } - - [MethodImpl((MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return Resolver.Value.ResolveByTag(this, tag); - } - - [MethodImpl((MethodImplOptions)0x100)] - public object Resolve(Type type) - { - var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _buckets[index]; - return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); - } - - [MethodImpl((MethodImplOptions)0x8)] - private object Resolve(Type type, int index) - { - var finish = index + _bucketSize; - while (++index < finish) - { - ref var pair = ref _buckets[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); - } - - [MethodImpl((MethodImplOptions)0x100)] - public object Resolve(Type type, object? tag) - { - var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _buckets[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); - } - - [MethodImpl((MethodImplOptions)0x8)] - private object Resolve(Type type, object? tag, int index) - { - var finish = index + _bucketSize; - while (++index < finish) - { - ref var pair = ref _buckets[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new InvalidOperationException($"{CannotResolveMessage} \"{tag}\" {OfTypeMessage} {type}."); - } - - public override string ToString() - { - return - "classDiagram\n" + - " class Composition {\n" + - " +IService Root\n" + - " + T ResolveᐸTᐳ()\n" + - " + T ResolveᐸTᐳ(object? tag)\n" + - " + object Resolve(Type type)\n" + - " + object Resolve(Type type, object? tag)\n" + - " }\n" + - " Service --|> IService : \n" + - " class Service\n" + - " Dependency --|> IDependency : \n" + - " class Dependency {\n" + - " +Dependency()\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " Service *-- Dependency : IDependency\n" + - " Composition ..> Service : IService Root"; - } - - private readonly static int _bucketSize; - private readonly static Pair>[] _buckets; - - static Composition() - { - var valResolver_0000 = new Resolver_0000(); - Resolver.Value = valResolver_0000; - _buckets = Buckets>.Create( - 1, - out _bucketSize, - new Pair>[1] - { - new Pair>(typeof(IService), valResolver_0000) - }); - } - - private const string CannotResolveMessage = "Cannot resolve composition root "; - private const string OfTypeMessage = "of type "; - - private class Resolver: IResolver - { - public static IResolver Value = new Resolver(); - - public virtual T Resolve(Composition composite) - { - throw new InvalidOperationException($"{CannotResolveMessage}{OfTypeMessage}{typeof(T)}."); - } - - public virtual T ResolveByTag(Composition composite, object tag) - { - throw new InvalidOperationException($"{CannotResolveMessage}\"{tag}\" {OfTypeMessage}{typeof(T)}."); - } - } - - private sealed class Resolver_0000: Resolver - { - public override IService Resolve(Composition composition) - { - return composition.Root; - } - - public override IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.Root; - default: - return base.ResolveByTag(composition, tag); - } - } - } -} -``` - -
- diff --git a/readme/injections-of-abstractions.md b/readme/injections-of-abstractions.md index a4f67d5c1..677e38ae9 100644 --- a/readme/injections-of-abstractions.md +++ b/readme/injections-of-abstractions.md @@ -29,7 +29,7 @@ DI.Setup(nameof(Composition)) .Bind().To() .Bind().To() - // Specifies to create a composition root (a property) + // Specifies to create a composition root // of type "Program" with the name "Root" .Root("Root"); @@ -93,7 +93,7 @@ partial class Composition public Program Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return new Program(new Service(new Dependency())); diff --git a/readme/instance-initialization.md b/readme/instance-initialization.md deleted file mode 100644 index b5b28c5cf..000000000 --- a/readme/instance-initialization.md +++ /dev/null @@ -1,266 +0,0 @@ -#### Instance Initialization - -[![CSharp](https://img.shields.io/badge/C%23-code-blue.svg)](../tests/Pure.DI.UsageTests/Advanced/InstanceInitializationScenario.cs) - -This example shows how to build up an instance with all the necessary dependencies and manually prepare it for further use. - -```c# -interface IDependency; - -class Dependency : IDependency; - -interface IService -{ - string ServiceName { get; } - - IDependency Dependency { get; } - - bool IsInitialized { get; } -} - -class Service(string serviceName, IDependency dependency): IService -{ - public string ServiceName { get; } = serviceName; - - public IDependency Dependency { get; } = dependency; - - public bool IsInitialized { get; private set; } - - public void Initialize() => IsInitialized = true; -} - -DI.Setup(nameof(Composition)) - .Bind().To() - .Arg("serviceName") - .Bind() - .To(ctx => - { - // Builds up an instance with all necessary dependencies - ctx.Inject(out var service); - - // Executing all the necessary logic - // to prepare the instance for further use - service.Initialize(); - return service; - }) - - // Composition root - .Root("Root"); - -var composition = new Composition("My Service"); -var service = composition.Root; -service.ServiceName.ShouldBe("My Service"); -service.IsInitialized.ShouldBeTrue(); -``` - -
-Class Diagram - -```mermaid -classDiagram - class Composition { - +IService Root - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - class Service { - +Service(String serviceName, IDependency dependency) - } - class String - Dependency --|> IDependency : - class Dependency { - +Dependency() - } - class IDependency { - <> - } - Service o-- String : Argument "serviceName" - Service *-- Dependency : IDependency - Composition ..> Service : IService Root -``` - -
- -
-Pure.DI-generated partial class Composition
- -```c# -partial class Composition -{ - private readonly Composition _root; - - private readonly string _arg_serviceName; - - public Composition(string serviceName) - { - _arg_serviceName = serviceName ?? throw new ArgumentNullException(nameof(serviceName)); - _root = this; - } - - internal Composition(Composition parentScope) - { - _root = (parentScope ?? throw new ArgumentNullException(nameof(parentScope)))._root; - _arg_serviceName = _root._arg_serviceName; - } - - public IService Root - { - [MethodImpl((MethodImplOptions)0x100)] - get - { - Service transient0_Service; - { - var service_1 = new Service(_arg_serviceName, new Dependency()); - service_1.Initialize(); - transient0_Service = service_1; - } - return transient0_Service; - } - } - - [MethodImpl((MethodImplOptions)0x100)] - public T Resolve() - { - return Resolver.Value.Resolve(this); - } - - [MethodImpl((MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return Resolver.Value.ResolveByTag(this, tag); - } - - [MethodImpl((MethodImplOptions)0x100)] - public object Resolve(Type type) - { - var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _buckets[index]; - return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); - } - - [MethodImpl((MethodImplOptions)0x8)] - private object Resolve(Type type, int index) - { - var finish = index + _bucketSize; - while (++index < finish) - { - ref var pair = ref _buckets[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); - } - - [MethodImpl((MethodImplOptions)0x100)] - public object Resolve(Type type, object? tag) - { - var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _buckets[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); - } - - [MethodImpl((MethodImplOptions)0x8)] - private object Resolve(Type type, object? tag, int index) - { - var finish = index + _bucketSize; - while (++index < finish) - { - ref var pair = ref _buckets[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new InvalidOperationException($"{CannotResolveMessage} \"{tag}\" {OfTypeMessage} {type}."); - } - - public override string ToString() - { - return - "classDiagram\n" + - " class Composition {\n" + - " +IService Root\n" + - " + T ResolveᐸTᐳ()\n" + - " + T ResolveᐸTᐳ(object? tag)\n" + - " + object Resolve(Type type)\n" + - " + object Resolve(Type type, object? tag)\n" + - " }\n" + - " class Service {\n" + - " +Service(String serviceName, IDependency dependency)\n" + - " }\n" + - " class String\n" + - " Dependency --|> IDependency : \n" + - " class Dependency {\n" + - " +Dependency()\n" + - " }\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " Service o-- String : Argument \"serviceName\"\n" + - " Service *-- Dependency : IDependency\n" + - " Composition ..> Service : IService Root"; - } - - private readonly static int _bucketSize; - private readonly static Pair>[] _buckets; - - static Composition() - { - var valResolver_0000 = new Resolver_0000(); - Resolver.Value = valResolver_0000; - _buckets = Buckets>.Create( - 1, - out _bucketSize, - new Pair>[1] - { - new Pair>(typeof(IService), valResolver_0000) - }); - } - - private const string CannotResolveMessage = "Cannot resolve composition root "; - private const string OfTypeMessage = "of type "; - - private class Resolver: IResolver - { - public static IResolver Value = new Resolver(); - - public virtual T Resolve(Composition composite) - { - throw new InvalidOperationException($"{CannotResolveMessage}{OfTypeMessage}{typeof(T)}."); - } - - public virtual T ResolveByTag(Composition composite, object tag) - { - throw new InvalidOperationException($"{CannotResolveMessage}\"{tag}\" {OfTypeMessage}{typeof(T)}."); - } - } - - private sealed class Resolver_0000: Resolver - { - public override IService Resolve(Composition composition) - { - return composition.Root; - } - - public override IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.Root; - default: - return base.ResolveByTag(composition, tag); - } - } - } -} -``` - -
- diff --git a/readme/interception.md b/readme/interception.md index a31e70e87..87e9a723e 100644 --- a/readme/interception.md +++ b/readme/interception.md @@ -97,26 +97,26 @@ partial class Composition public IService Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return OnDependencyInjection(new Service(), null, Lifetime.Transient); } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -124,7 +124,7 @@ partial class Composition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -140,7 +140,7 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -148,7 +148,7 @@ partial class Composition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/keyed-service-provider.md b/readme/keyed-service-provider.md index a48448ea8..abb87d94c 100644 --- a/readme/keyed-service-provider.md +++ b/readme/keyed-service-provider.md @@ -102,7 +102,7 @@ partial class Composition private IDependency Root0001 { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { if (_root._singleton36_Dependency == null) @@ -121,7 +121,7 @@ partial class Composition private IService Root0002 { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { if (_root._singleton36_Dependency == null) @@ -138,19 +138,19 @@ partial class Composition } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object GetService(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 4)); @@ -158,7 +158,7 @@ partial class Composition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -174,7 +174,7 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object GetRequiredKeyedService(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 4)); @@ -182,7 +182,7 @@ partial class Composition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/lazy.md b/readme/lazy.md index e4ba6613b..e4f05b0af 100644 --- a/readme/lazy.md +++ b/readme/lazy.md @@ -88,7 +88,7 @@ partial class Composition public IService Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { var perResolve40_Func = default(Func); @@ -108,19 +108,19 @@ partial class Composition } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -128,7 +128,7 @@ partial class Composition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -144,7 +144,7 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -152,7 +152,7 @@ partial class Composition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/manually-started-tasks.md b/readme/manually-started-tasks.md index ed40b6b2e..0ad978d9e 100644 --- a/readme/manually-started-tasks.md +++ b/readme/manually-started-tasks.md @@ -126,7 +126,7 @@ partial class Composition _lock = _root._lock; } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public IService GetRoot(CancellationToken cancellationToken) { var perResolve42_Func = default(Func); diff --git a/readme/member-ordinal-attribute.md b/readme/member-ordinal-attribute.md index 945f8428b..7adcc84fd 100644 --- a/readme/member-ordinal-attribute.md +++ b/readme/member-ordinal-attribute.md @@ -16,6 +16,9 @@ class Person : IPerson public string Name => _name.ToString(); + // The Ordinal attribute specifies to perform an injection, + // the integer value in the argument specifies + // the ordinal of injection [Ordinal(0)] public int Id; @@ -124,7 +127,7 @@ partial class PersonComposition public IPerson Person { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { Person transient0_Person = new Person(); @@ -135,19 +138,19 @@ partial class PersonComposition } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -155,7 +158,7 @@ partial class PersonComposition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -171,7 +174,7 @@ partial class PersonComposition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -179,7 +182,7 @@ partial class PersonComposition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/method-injection.md b/readme/method-injection.md index 55e3ea340..16019a3e1 100644 --- a/readme/method-injection.md +++ b/readme/method-injection.md @@ -16,6 +16,9 @@ interface IService class Service : IService { + // The Ordinal attribute specifies to perform an injection, + // the integer value in the argument specifies + // the ordinal of injection [Ordinal(0)] public void SetDependency(IDependency dependency) => Dependency = dependency; @@ -88,7 +91,7 @@ partial class Composition public IService Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { Service transient0_Service = new Service(); @@ -97,19 +100,19 @@ partial class Composition } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -117,7 +120,7 @@ partial class Composition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -133,7 +136,7 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -141,7 +144,7 @@ partial class Composition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/multi-contract-bindings.md b/readme/multi-contract-bindings.md deleted file mode 100644 index 0dfde6c78..000000000 --- a/readme/multi-contract-bindings.md +++ /dev/null @@ -1,248 +0,0 @@ -#### Multi-contract bindings - -[![CSharp](https://img.shields.io/badge/C%23-code-blue.svg)](../tests/Pure.DI.UsageTests/Basics/MultiContractBindingsScenario.cs) - -An unlimited number of contracts can be attached to one implementation. Including their combinations with various tags. - -```c# -interface IDependency; - -interface IAdvancedDependency; - -class Dependency : IDependency, IAdvancedDependency; - -interface IService; - -class Service( - IDependency dependency, - IAdvancedDependency advancedDependency) - : IService; - -DI.Setup(nameof(Composition)) - .Bind().To() - // .Bind().Bind().To() - // is also allowed - .Bind().To() - - // Composition root - .Root("Root"); - -var composition = new Composition(); -var service = composition.Root; -``` - -
-Class Diagram - -```mermaid -classDiagram - class Composition { - +IService Root - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - Dependency --|> IDependency : - Dependency --|> IAdvancedDependency : - class Dependency { - +Dependency() - } - Service --|> IService : - class Service { - +Service(IDependency dependency, IAdvancedDependency advancedDependency) - } - class IDependency { - <> - } - class IAdvancedDependency { - <> - } - class IService { - <> - } - Service *-- Dependency : IDependency - Service *-- Dependency : IAdvancedDependency - Composition ..> Service : IService Root -``` - -
- -
-Pure.DI-generated partial class Composition
- -```c# -partial class Composition -{ - private readonly Composition _root; - - public Composition() - { - _root = this; - } - - internal Composition(Composition parentScope) - { - _root = (parentScope ?? throw new ArgumentNullException(nameof(parentScope)))._root; - } - - public IService Root - { - [MethodImpl((MethodImplOptions)0x100)] - get - { - return new Service(new Dependency(), new Dependency()); - } - } - - [MethodImpl((MethodImplOptions)0x100)] - public T Resolve() - { - return Resolver.Value.Resolve(this); - } - - [MethodImpl((MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return Resolver.Value.ResolveByTag(this, tag); - } - - [MethodImpl((MethodImplOptions)0x100)] - public object Resolve(Type type) - { - var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _buckets[index]; - return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); - } - - [MethodImpl((MethodImplOptions)0x8)] - private object Resolve(Type type, int index) - { - var finish = index + _bucketSize; - while (++index < finish) - { - ref var pair = ref _buckets[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); - } - - [MethodImpl((MethodImplOptions)0x100)] - public object Resolve(Type type, object? tag) - { - var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _buckets[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); - } - - [MethodImpl((MethodImplOptions)0x8)] - private object Resolve(Type type, object? tag, int index) - { - var finish = index + _bucketSize; - while (++index < finish) - { - ref var pair = ref _buckets[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new InvalidOperationException($"{CannotResolveMessage} \"{tag}\" {OfTypeMessage} {type}."); - } - - public override string ToString() - { - return - "classDiagram\n" + - " class Composition {\n" + - " +IService Root\n" + - " + T ResolveᐸTᐳ()\n" + - " + T ResolveᐸTᐳ(object? tag)\n" + - " + object Resolve(Type type)\n" + - " + object Resolve(Type type, object? tag)\n" + - " }\n" + - " Dependency --|> IDependency : \n" + - " Dependency --|> IAdvancedDependency : \n" + - " class Dependency {\n" + - " +Dependency()\n" + - " }\n" + - " Service --|> IService : \n" + - " class Service {\n" + - " +Service(IDependency dependency, IAdvancedDependency advancedDependency)\n" + - " }\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " class IAdvancedDependency {\n" + - " <>\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " Service *-- Dependency : IDependency\n" + - " Service *-- Dependency : IAdvancedDependency\n" + - " Composition ..> Service : IService Root"; - } - - private readonly static int _bucketSize; - private readonly static Pair>[] _buckets; - - static Composition() - { - var valResolver_0000 = new Resolver_0000(); - Resolver.Value = valResolver_0000; - _buckets = Buckets>.Create( - 1, - out _bucketSize, - new Pair>[1] - { - new Pair>(typeof(IService), valResolver_0000) - }); - } - - private const string CannotResolveMessage = "Cannot resolve composition root "; - private const string OfTypeMessage = "of type "; - - private class Resolver: IResolver - { - public static IResolver Value = new Resolver(); - - public virtual T Resolve(Composition composite) - { - throw new InvalidOperationException($"{CannotResolveMessage}{OfTypeMessage}{typeof(T)}."); - } - - public virtual T ResolveByTag(Composition composite, object tag) - { - throw new InvalidOperationException($"{CannotResolveMessage}\"{tag}\" {OfTypeMessage}{typeof(T)}."); - } - } - - private sealed class Resolver_0000: Resolver - { - public override IService Resolve(Composition composition) - { - return composition.Root; - } - - public override IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.Root; - default: - return base.ResolveByTag(composition, tag); - } - } - } -} -``` - -
- diff --git a/readme/oncannotresolve-hint.md b/readme/oncannotresolve-hint.md index c57ac57fe..7d590a89a 100644 --- a/readme/oncannotresolve-hint.md +++ b/readme/oncannotresolve-hint.md @@ -110,7 +110,7 @@ partial class Composition public IService Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { string transient2_String = OnCannotResolve(null, Lifetime.Transient); @@ -118,19 +118,19 @@ partial class Composition } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -138,7 +138,7 @@ partial class Composition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -154,7 +154,7 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -162,7 +162,7 @@ partial class Composition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/ondependencyinjection-hint.md b/readme/ondependencyinjection-hint.md index b69f6bc25..5b879ea00 100644 --- a/readme/ondependencyinjection-hint.md +++ b/readme/ondependencyinjection-hint.md @@ -107,26 +107,26 @@ partial class Composition public IService Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return new Service(OnDependencyInjection(new Dependency(), null, Lifetime.Transient)); } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -134,7 +134,7 @@ partial class Composition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -150,7 +150,7 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -158,7 +158,7 @@ partial class Composition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/onnewinstance-hint.md b/readme/onnewinstance-hint.md index 48004b01d..9983391e7 100644 --- a/readme/onnewinstance-hint.md +++ b/readme/onnewinstance-hint.md @@ -113,7 +113,7 @@ partial class Composition public IService Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { if (_root._singleton36_Dependency == null) @@ -136,19 +136,19 @@ partial class Composition } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -156,7 +156,7 @@ partial class Composition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -172,7 +172,7 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -180,7 +180,7 @@ partial class Composition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/overriding-the-bcl-binding.md b/readme/overriding-the-bcl-binding.md index 209f14375..98838bad0 100644 --- a/readme/overriding-the-bcl-binding.md +++ b/readme/overriding-the-bcl-binding.md @@ -87,7 +87,7 @@ partial class Composition public IService Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { IDependency[] transient1_ = new IDependency[] @@ -100,19 +100,19 @@ partial class Composition } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -120,7 +120,7 @@ partial class Composition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -136,7 +136,7 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -144,7 +144,7 @@ partial class Composition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/partial-class.md b/readme/partial-class.md index 479bedf16..05d7e095b 100644 --- a/readme/partial-class.md +++ b/readme/partial-class.md @@ -118,7 +118,7 @@ partial class Composition internal Service Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { long transient5_Int64 = GenerateId(); @@ -128,19 +128,19 @@ partial class Composition } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -148,7 +148,7 @@ partial class Composition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -164,7 +164,7 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -172,7 +172,7 @@ partial class Composition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/perblock.md b/readme/perblock.md index a8fa676a0..bc7370753 100644 --- a/readme/perblock.md +++ b/readme/perblock.md @@ -102,7 +102,7 @@ partial class Composition public Service Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { var perResolve43_Func = default(Func<(IDependency dep3, IDependency dep4)>); @@ -124,19 +124,19 @@ partial class Composition } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -144,7 +144,7 @@ partial class Composition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -160,7 +160,7 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -168,7 +168,7 @@ partial class Composition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/perresolve.md b/readme/perresolve.md index 9ea47e2ae..c8875c3ca 100644 --- a/readme/perresolve.md +++ b/readme/perresolve.md @@ -102,7 +102,7 @@ partial class Composition public Service Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { var perResolve36_Dependency = default(Dependency); @@ -143,19 +143,19 @@ partial class Composition } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -163,7 +163,7 @@ partial class Composition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -179,7 +179,7 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -187,7 +187,7 @@ partial class Composition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/property-injection.md b/readme/property-injection.md index 6c19f7aea..72d00562c 100644 --- a/readme/property-injection.md +++ b/readme/property-injection.md @@ -16,6 +16,9 @@ interface IService class Service : IService { + // The Ordinal attribute specifies to perform an injection, + // the integer value in the argument specifies + // the ordinal of injection [Ordinal(0)] public IDependency? Dependency { get; set; } } @@ -85,7 +88,7 @@ partial class Composition public IService Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { Service transient0_Service = new Service(); @@ -94,19 +97,19 @@ partial class Composition } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -114,7 +117,7 @@ partial class Composition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -130,7 +133,7 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -138,7 +141,7 @@ partial class Composition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/required-properties-or-fields.md b/readme/required-properties-or-fields.md index 2fd4645f9..418ee9dbc 100644 --- a/readme/required-properties-or-fields.md +++ b/readme/required-properties-or-fields.md @@ -22,6 +22,8 @@ class Service : IService public string Name => ServiceNameField; + // The required property will be injected automatically + // without additional effort public required IDependency Dependency { get; init; } } @@ -99,7 +101,7 @@ partial class Composition public IService Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return new Service() @@ -110,19 +112,19 @@ partial class Composition } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -130,7 +132,7 @@ partial class Composition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -146,7 +148,7 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -154,7 +156,7 @@ partial class Composition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/resolve-hint.md b/readme/resolve-hint.md index f597491d5..ed55fe2c1 100644 --- a/readme/resolve-hint.md +++ b/readme/resolve-hint.md @@ -78,7 +78,7 @@ partial class Composition public IDependency DependencyRoot { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return new Dependency(); @@ -87,7 +87,7 @@ partial class Composition public IService Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return new Service(new Dependency()); diff --git a/readme/resolve-methods.md b/readme/resolve-methods.md index 4466da4c2..420a4c7f1 100644 --- a/readme/resolve-methods.md +++ b/readme/resolve-methods.md @@ -1,6 +1,6 @@ #### Resolve methods -[![CSharp](https://img.shields.io/badge/C%23-code-blue.svg)](../tests/Pure.DI.UsageTests/Basics/ResolveScenario.cs) +[![CSharp](https://img.shields.io/badge/C%23-code-blue.svg)](../tests/Pure.DI.UsageTests/Basics/ResolveMethodsScenario.cs) This example shows how to resolve the composition roots using the _Resolve_ methods by _Service Locator_ approach. `Resolve` methods are generated automatically for each registered root. @@ -102,7 +102,7 @@ partial class Composition public IService OtherService { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return new OtherService(); @@ -111,7 +111,7 @@ partial class Composition private IDependency Root0001 { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return new Dependency(); @@ -120,26 +120,26 @@ partial class Composition private IService Root0002 { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return new Service(new Dependency()); } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 4)); @@ -147,7 +147,7 @@ partial class Composition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -163,7 +163,7 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 4)); @@ -171,7 +171,7 @@ partial class Composition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/root-arguments.md b/readme/root-arguments.md index 162ddbb82..1aff23dca 100644 --- a/readme/root-arguments.md +++ b/readme/root-arguments.md @@ -116,7 +116,7 @@ partial class Composition _root = (parentScope ?? throw new ArgumentNullException(nameof(parentScope)))._root; } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public IService CreateService(int id, string dependencyName, string serviceName) { return new Service(serviceName, new Dependency(id, dependencyName)); diff --git a/readme/rootbind.md b/readme/root-binding.md similarity index 93% rename from readme/rootbind.md rename to readme/root-binding.md index 43a573957..3452cd7d5 100644 --- a/readme/rootbind.md +++ b/readme/root-binding.md @@ -1,4 +1,4 @@ -#### RootBind +#### Root binding [![CSharp](https://img.shields.io/badge/C%23-code-blue.svg)](../tests/Pure.DI.UsageTests/Basics/RootBindScenario.cs) @@ -60,26 +60,26 @@ partial class Composition public IService Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return new Service(); } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -87,7 +87,7 @@ partial class Composition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -103,7 +103,7 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -111,7 +111,7 @@ partial class Composition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/scope.md b/readme/scope.md index 0a17deb5f..4fb07b3e8 100644 --- a/readme/scope.md +++ b/readme/scope.md @@ -151,7 +151,7 @@ partial class Composition: IDisposable public IService SessionRoot { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { if (_scoped36_Dependency == null) @@ -171,7 +171,7 @@ partial class Composition: IDisposable public Program ProgramRoot { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { var perResolve43_Func = default(Func); @@ -187,19 +187,19 @@ partial class Composition: IDisposable } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 4)); @@ -207,7 +207,7 @@ partial class Composition: IDisposable return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -223,7 +223,7 @@ partial class Composition: IDisposable throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 4)); @@ -231,7 +231,7 @@ partial class Composition: IDisposable return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/service-collection.md b/readme/service-collection.md index 3ef1d46df..40406b95c 100644 --- a/readme/service-collection.md +++ b/readme/service-collection.md @@ -99,7 +99,7 @@ partial class Composition private IDependency Root0001 { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { if (_root._singleton36_Dependency == null) @@ -118,7 +118,7 @@ partial class Composition private IService Root0002 { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { if (_root._singleton36_Dependency == null) @@ -135,19 +135,19 @@ partial class Composition } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 4)); @@ -155,7 +155,7 @@ partial class Composition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -171,7 +171,7 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 4)); @@ -179,7 +179,7 @@ partial class Composition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/service-provider-with-scope.md b/readme/service-provider-with-scope.md index eba1a8be4..46e7631fb 100644 --- a/readme/service-provider-with-scope.md +++ b/readme/service-provider-with-scope.md @@ -133,7 +133,7 @@ partial class Composition: IDisposable private IDependency Root0001 { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { if (_root._singleton36_Dependency == null) @@ -152,7 +152,7 @@ partial class Composition: IDisposable private IService Root0002 { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { if (_scoped37_Service == null) @@ -174,19 +174,19 @@ partial class Composition: IDisposable } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object GetService(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 4)); @@ -194,7 +194,7 @@ partial class Composition: IDisposable return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -210,7 +210,7 @@ partial class Composition: IDisposable throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object GetRequiredKeyedService(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 4)); @@ -218,7 +218,7 @@ partial class Composition: IDisposable return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/service-provider.md b/readme/service-provider.md index 7df851d96..1690738c7 100644 --- a/readme/service-provider.md +++ b/readme/service-provider.md @@ -97,7 +97,7 @@ partial class Composition private IDependency Root0001 { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { if (_root._singleton36_Dependency == null) @@ -116,7 +116,7 @@ partial class Composition private IService Root0002 { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { if (_root._singleton36_Dependency == null) @@ -133,19 +133,19 @@ partial class Composition } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object GetService(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 4)); @@ -153,7 +153,7 @@ partial class Composition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -169,7 +169,7 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 4)); @@ -177,7 +177,7 @@ partial class Composition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/simplified-binding.md b/readme/simplified-binding.md index 9b9a67c6f..1049c1420 100644 --- a/readme/simplified-binding.md +++ b/readme/simplified-binding.md @@ -102,7 +102,7 @@ partial class Composition public Service MyService { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { Dependency perBlock1_Dependency = new Dependency(); diff --git a/readme/singleton.md b/readme/singleton.md index aee69916d..a97ec23d8 100644 --- a/readme/singleton.md +++ b/readme/singleton.md @@ -94,7 +94,7 @@ partial class Composition public IService Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { if (_root._singleton36_Dependency == null) @@ -111,19 +111,19 @@ partial class Composition } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -131,7 +131,7 @@ partial class Composition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -147,7 +147,7 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -155,7 +155,7 @@ partial class Composition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/span-and-readonlyspan.md b/readme/span-and-readonlyspan.md index 2d563dbc1..64d2f1fe6 100644 --- a/readme/span-and-readonlyspan.md +++ b/readme/span-and-readonlyspan.md @@ -95,7 +95,7 @@ partial class Composition public IService Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ReadOnlySpan transient1_ReadOnlySpan = stackalloc Dependency[3] @@ -108,19 +108,19 @@ partial class Composition } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -128,7 +128,7 @@ partial class Composition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -144,7 +144,7 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -152,7 +152,7 @@ partial class Composition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/tag-attribute.md b/readme/tag-attribute.md index e4e27cf0d..7a3f78f14 100644 --- a/readme/tag-attribute.md +++ b/readme/tag-attribute.md @@ -103,26 +103,26 @@ partial class Composition public IService Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return new Service(new AbcDependency(), new XyzDependency()); } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -130,7 +130,7 @@ partial class Composition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -146,7 +146,7 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -154,7 +154,7 @@ partial class Composition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/tag-type.md b/readme/tag-type.md index d79cac9a3..3dcd42c5f 100644 --- a/readme/tag-type.md +++ b/readme/tag-type.md @@ -119,7 +119,7 @@ partial class Composition public IDependency XyzRoot { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { if (_root._singleton37_XyzDependency == null) @@ -138,7 +138,7 @@ partial class Composition public IService Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { if (_root._singleton37_XyzDependency == null) @@ -155,19 +155,19 @@ partial class Composition } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 4)); @@ -175,7 +175,7 @@ partial class Composition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -191,7 +191,7 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 4)); @@ -199,7 +199,7 @@ partial class Composition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/tag-unique.md b/readme/tag-unique.md index b33f38ce9..62850fbb9 100644 --- a/readme/tag-unique.md +++ b/readme/tag-unique.md @@ -94,10 +94,10 @@ partial class Composition public IService Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] IEnumerable> EnumerationOf_perBlock1_IEnumerable() { yield return new AbcDependency(); @@ -108,19 +108,19 @@ partial class Composition } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -128,7 +128,7 @@ partial class Composition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -144,7 +144,7 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -152,7 +152,7 @@ partial class Composition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/tags.md b/readme/tags.md index 0337a12b7..05c4f95e6 100644 --- a/readme/tags.md +++ b/readme/tags.md @@ -123,7 +123,7 @@ partial class Composition public IDependency XyzRoot { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { if (_root._singleton37_XyzDependency == null) @@ -142,7 +142,7 @@ partial class Composition public IService Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { if (_root._singleton37_XyzDependency == null) @@ -159,19 +159,19 @@ partial class Composition } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 4)); @@ -179,7 +179,7 @@ partial class Composition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -195,7 +195,7 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 4)); @@ -203,7 +203,7 @@ partial class Composition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/task.md b/readme/task.md index 131f653de..8547d9764 100644 --- a/readme/task.md +++ b/readme/task.md @@ -125,7 +125,7 @@ partial class Composition _lock = _root._lock; } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public IService GetRoot(CancellationToken cancellationToken) { var perResolve42_Func = default(Func); diff --git a/readme/threadsafe-hint.md b/readme/threadsafe-hint.md index d8e7d5cdb..d16dede6f 100644 --- a/readme/threadsafe-hint.md +++ b/readme/threadsafe-hint.md @@ -79,26 +79,26 @@ partial class Composition public IService Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return new Service(new Dependency()); } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -106,7 +106,7 @@ partial class Composition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -122,7 +122,7 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -130,7 +130,7 @@ partial class Composition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/tostring-hint.md b/readme/tostring-hint.md index 062307bf7..6624fa121 100644 --- a/readme/tostring-hint.md +++ b/readme/tostring-hint.md @@ -77,26 +77,26 @@ partial class Composition public IService MyService { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return new Service(new Dependency()); } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -104,7 +104,7 @@ partial class Composition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -120,7 +120,7 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -128,7 +128,7 @@ partial class Composition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/tracking-async-disposable-instances-in-delegates.md b/readme/tracking-async-disposable-instances-in-delegates.md index dc49064f2..82ccf3eec 100644 --- a/readme/tracking-async-disposable-instances-in-delegates.md +++ b/readme/tracking-async-disposable-instances-in-delegates.md @@ -1,6 +1,6 @@ #### Tracking async disposable instances in delegates -[![CSharp](https://img.shields.io/badge/C%23-code-blue.svg)](../tests/Pure.DI.UsageTests/Basics/TrackingAsyncDisposableInDelegatesScenario.cs) +[![CSharp](https://img.shields.io/badge/C%23-code-blue.svg)](../tests/Pure.DI.UsageTests/Advanced/TrackingAsyncDisposableInDelegatesScenario.cs) ```c# interface IDependency @@ -134,7 +134,7 @@ partial class Composition public Service Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { var perResolve39_Func = default(Func>); @@ -165,19 +165,19 @@ partial class Composition } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -185,7 +185,7 @@ partial class Composition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -201,7 +201,7 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -209,7 +209,7 @@ partial class Composition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/tracking-async-disposable-instances-per-a-composition-root.md b/readme/tracking-async-disposable-instances-per-a-composition-root.md index 6df243fae..95e222cef 100644 --- a/readme/tracking-async-disposable-instances-per-a-composition-root.md +++ b/readme/tracking-async-disposable-instances-per-a-composition-root.md @@ -1,6 +1,6 @@ #### Tracking async disposable instances per a composition root -[![CSharp](https://img.shields.io/badge/C%23-code-blue.svg)](../tests/Pure.DI.UsageTests/Basics/TrackingAsyncDisposableScenario.cs) +[![CSharp](https://img.shields.io/badge/C%23-code-blue.svg)](../tests/Pure.DI.UsageTests/Advanced/TrackingAsyncDisposableScenario.cs) ```c# interface IDependency @@ -124,7 +124,7 @@ partial class Composition public Owned Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { var accumulator38 = new Owned(); @@ -147,25 +147,25 @@ partial class Composition } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { throw new InvalidOperationException($"{CannotResolveMessage} \"{tag}\" {OfTypeMessage} {type}."); diff --git a/readme/tracking-disposable-instances-in-delegates.md b/readme/tracking-disposable-instances-in-delegates.md index f12fe4c62..9420eeb98 100644 --- a/readme/tracking-disposable-instances-in-delegates.md +++ b/readme/tracking-disposable-instances-in-delegates.md @@ -1,6 +1,6 @@ #### Tracking disposable instances in delegates -[![CSharp](https://img.shields.io/badge/C%23-code-blue.svg)](../tests/Pure.DI.UsageTests/Basics/TrackingDisposableInDelegatesScenario.cs) +[![CSharp](https://img.shields.io/badge/C%23-code-blue.svg)](../tests/Pure.DI.UsageTests/Advanced/TrackingDisposableInDelegatesScenario.cs) ```c# interface IDependency @@ -123,7 +123,7 @@ partial class Composition public Service Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { var perResolve39_Func = default(Func>); @@ -154,19 +154,19 @@ partial class Composition } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -174,7 +174,7 @@ partial class Composition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -190,7 +190,7 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -198,7 +198,7 @@ partial class Composition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/tracking-disposable-instances-per-a-composition-root.md b/readme/tracking-disposable-instances-per-a-composition-root.md index 2c8edcacb..342796368 100644 --- a/readme/tracking-disposable-instances-per-a-composition-root.md +++ b/readme/tracking-disposable-instances-per-a-composition-root.md @@ -1,6 +1,6 @@ #### Tracking disposable instances per a composition root -[![CSharp](https://img.shields.io/badge/C%23-code-blue.svg)](../tests/Pure.DI.UsageTests/Basics/TrackingDisposableScenario.cs) +[![CSharp](https://img.shields.io/badge/C%23-code-blue.svg)](../tests/Pure.DI.UsageTests/Advanced/TrackingDisposableScenario.cs) ```c# interface IDependency @@ -116,7 +116,7 @@ partial class Composition public Owned Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { var accumulator38 = new Owned(); @@ -139,25 +139,25 @@ partial class Composition } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { throw new InvalidOperationException($"{CannotResolveMessage} \"{tag}\" {OfTypeMessage} {type}."); diff --git a/readme/transient.md b/readme/transient.md index 5b22b7429..589fa2fb8 100644 --- a/readme/transient.md +++ b/readme/transient.md @@ -90,26 +90,26 @@ partial class Composition public IService Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return new Service(new Dependency(), new Dependency()); } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -117,7 +117,7 @@ partial class Composition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -133,7 +133,7 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -141,7 +141,7 @@ partial class Composition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/tuple.md b/readme/tuple.md index a9fff0ca0..8cd061fdc 100644 --- a/readme/tuple.md +++ b/readme/tuple.md @@ -91,7 +91,7 @@ partial class Composition public IService Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { Point transient2_Point = new Point(7, 9); @@ -99,19 +99,19 @@ partial class Composition } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -119,7 +119,7 @@ partial class Composition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -135,7 +135,7 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -143,7 +143,7 @@ partial class Composition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/type-attribute.md b/readme/type-attribute.md index 74eb4633d..d3a3b4029 100644 --- a/readme/type-attribute.md +++ b/readme/type-attribute.md @@ -94,26 +94,26 @@ partial class Composition public IService Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return new Service(new AbcDependency(), new XyzDependency()); } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -121,7 +121,7 @@ partial class Composition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -137,7 +137,7 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -145,7 +145,7 @@ partial class Composition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/valuetask.md b/readme/valuetask.md index 2f272b9ad..015a7d958 100644 --- a/readme/valuetask.md +++ b/readme/valuetask.md @@ -93,7 +93,7 @@ partial class Composition public IService Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ValueTask transient1_ValueTask; @@ -105,19 +105,19 @@ partial class Composition } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -125,7 +125,7 @@ partial class Composition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -141,7 +141,7 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -149,7 +149,7 @@ partial class Composition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/readme/weak-reference.md b/readme/weak-reference.md index 44bf8165f..3515c1d9f 100644 --- a/readme/weak-reference.md +++ b/readme/weak-reference.md @@ -84,26 +84,26 @@ partial class Composition public IService Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return new Service(new WeakReference(new Dependency())); } } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve() { return Resolver.Value.Resolve(this); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Resolve(object? tag) { return Resolver.Value.ResolveByTag(this, tag); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -111,7 +111,7 @@ partial class Composition return pair.Key == type ? pair.Value.Resolve(this) : Resolve(type, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, int index) { var finish = index + _bucketSize; @@ -127,7 +127,7 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} {OfTypeMessage} {type}."); } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public object Resolve(Type type, object? tag) { var index = (int)(_bucketSize * ((uint)RuntimeHelpers.GetHashCode(type) % 1)); @@ -135,7 +135,7 @@ partial class Composition return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : Resolve(type, tag, index); } - [MethodImpl((MethodImplOptions)0x8)] + [MethodImpl(MethodImplOptions.NoInlining)] private object Resolve(Type type, object? tag, int index) { var finish = index + _bucketSize; diff --git a/samples/ShroedingersCat/Program.cs b/samples/ShroedingersCat/Program.cs index c3f014328..a17e3f65a 100644 --- a/samples/ShroedingersCat/Program.cs +++ b/samples/ShroedingersCat/Program.cs @@ -61,14 +61,14 @@ void Setup() => DI.Setup(nameof(Composition)) // Models a random subatomic event that may or may not occur .Bind().As(Singleton).To() - // Represents a quantum superposition of 2 states: Alive or Dead + // Quantum superposition of two states: Alive or Dead .Bind().To(ctx => { ctx.Inject(out var random); return (State)random.Next(2); }) .Bind().To() - // Represents a cardboard box with any contents + // Cardboard box with any contents .Bind().To>() // Provides the composition root .Root("Root"); diff --git a/samples/ShroedingersCatTopLevelStatements/Program.cs b/samples/ShroedingersCatTopLevelStatements/Program.cs index b85913766..e9a1aed17 100644 --- a/samples/ShroedingersCatTopLevelStatements/Program.cs +++ b/samples/ShroedingersCatTopLevelStatements/Program.cs @@ -20,14 +20,14 @@ static void Setup() => DI.Setup(nameof(Composition)) // Models a random subatomic event that may or may not occur .Bind().As(Singleton).To() - // Represents a quantum superposition of 2 states: Alive or Dead + // Quantum superposition of two states: Alive or Dead .Bind().To(ctx => { ctx.Inject(out var random); return (State)random.Next(2); }) .Bind().To() - // Represents a cardboard box with any contents + // Cardboard box with any contents .Bind().To>() // Provides the composition root .Root("Root"); diff --git a/tests/Pure.DI.UsageTests/Advanced/InstanceInitializationScenario.cs b/tests/Pure.DI.UsageTests/Advanced/InstanceInitializationScenario.cs deleted file mode 100644 index b05767890..000000000 --- a/tests/Pure.DI.UsageTests/Advanced/InstanceInitializationScenario.cs +++ /dev/null @@ -1,75 +0,0 @@ -/* -$v=true -$p=2 -$d=Instance Initialization -$h=This example shows how to build up an instance with all the necessary dependencies and manually prepare it for further use. -*/ - -// ReSharper disable ClassNeverInstantiated.Local -// ReSharper disable CheckNamespace -// ReSharper disable UnusedMemberInSuper.Global -// ReSharper disable ArrangeTypeModifiers -// ReSharper disable UnusedMember.Global -namespace Pure.DI.UsageTests.Advanced.InstanceInitializationScenario; - -using Shouldly; -using Xunit; - -// { -interface IDependency; - -class Dependency : IDependency; - -interface IService -{ - string ServiceName { get; } - - IDependency Dependency { get; } - - bool IsInitialized { get; } -} - -class Service(string serviceName, IDependency dependency): IService -{ - public string ServiceName { get; } = serviceName; - - public IDependency Dependency { get; } = dependency; - - public bool IsInitialized { get; private set; } - - public void Initialize() => IsInitialized = true; -} -// } - -public class Scenario -{ - [Fact] - public void Run() - { -// { - DI.Setup(nameof(Composition)) - .Bind().To() - .Arg("serviceName") - .Bind() - .To(ctx => - { - // Builds up an instance with all necessary dependencies - ctx.Inject(out var service); - - // Executing all the necessary logic - // to prepare the instance for further use - service.Initialize(); - return service; - }) - - // Composition root - .Root("Root"); - - var composition = new Composition("My Service"); - var service = composition.Root; - service.ServiceName.ShouldBe("My Service"); - service.IsInitialized.ShouldBeTrue(); -// } - composition.SaveClassDiagram(); - } -} \ No newline at end of file diff --git a/tests/Pure.DI.UsageTests/Basics/TrackingAsyncDisposableInDelegatesScenario.cs b/tests/Pure.DI.UsageTests/Advanced/TrackingAsyncDisposableInDelegatesScenario.cs similarity index 96% rename from tests/Pure.DI.UsageTests/Basics/TrackingAsyncDisposableInDelegatesScenario.cs rename to tests/Pure.DI.UsageTests/Advanced/TrackingAsyncDisposableInDelegatesScenario.cs index e6a573354..b83419e12 100644 --- a/tests/Pure.DI.UsageTests/Basics/TrackingAsyncDisposableInDelegatesScenario.cs +++ b/tests/Pure.DI.UsageTests/Advanced/TrackingAsyncDisposableInDelegatesScenario.cs @@ -10,7 +10,7 @@ // ReSharper disable ArrangeTypeModifiers // ReSharper disable ArrangeTypeMemberModifiers // ReSharper disable UnusedMemberInSuper.Global -namespace Pure.DI.UsageTests.Basics.TrackingAsyncDisposableInDelegatesScenario; +namespace Pure.DI.UsageTests.Advanced.TrackingAsyncDisposableInDelegatesScenario; using Xunit; diff --git a/tests/Pure.DI.UsageTests/Basics/TrackingAsyncDisposableScenario.cs b/tests/Pure.DI.UsageTests/Advanced/TrackingAsyncDisposableScenario.cs similarity index 96% rename from tests/Pure.DI.UsageTests/Basics/TrackingAsyncDisposableScenario.cs rename to tests/Pure.DI.UsageTests/Advanced/TrackingAsyncDisposableScenario.cs index 3edacb7c9..ef22d1d5a 100644 --- a/tests/Pure.DI.UsageTests/Basics/TrackingAsyncDisposableScenario.cs +++ b/tests/Pure.DI.UsageTests/Advanced/TrackingAsyncDisposableScenario.cs @@ -9,7 +9,7 @@ // ReSharper disable UnusedParameterInPartialMethod // ReSharper disable ArrangeTypeModifiers // ReSharper disable ArrangeTypeMemberModifiers -namespace Pure.DI.UsageTests.Basics.TrackingAsyncDisposableScenario; +namespace Pure.DI.UsageTests.Advanced.TrackingAsyncDisposableScenario; using Xunit; diff --git a/tests/Pure.DI.UsageTests/Basics/TrackingDisposableInDelegatesScenario.cs b/tests/Pure.DI.UsageTests/Advanced/TrackingDisposableInDelegatesScenario.cs similarity index 96% rename from tests/Pure.DI.UsageTests/Basics/TrackingDisposableInDelegatesScenario.cs rename to tests/Pure.DI.UsageTests/Advanced/TrackingDisposableInDelegatesScenario.cs index f9a716a6c..78830f40e 100644 --- a/tests/Pure.DI.UsageTests/Basics/TrackingDisposableInDelegatesScenario.cs +++ b/tests/Pure.DI.UsageTests/Advanced/TrackingDisposableInDelegatesScenario.cs @@ -10,7 +10,7 @@ // ReSharper disable ArrangeTypeModifiers // ReSharper disable ArrangeTypeMemberModifiers // ReSharper disable UnusedMemberInSuper.Global -namespace Pure.DI.UsageTests.Basics.TrackingDisposableInDelegatesScenario; +namespace Pure.DI.UsageTests.Advanced.TrackingDisposableInDelegatesScenario; using Xunit; diff --git a/tests/Pure.DI.UsageTests/Basics/TrackingDisposableScenario.cs b/tests/Pure.DI.UsageTests/Advanced/TrackingDisposableScenario.cs similarity index 96% rename from tests/Pure.DI.UsageTests/Basics/TrackingDisposableScenario.cs rename to tests/Pure.DI.UsageTests/Advanced/TrackingDisposableScenario.cs index 4d4530588..155c2fd09 100644 --- a/tests/Pure.DI.UsageTests/Basics/TrackingDisposableScenario.cs +++ b/tests/Pure.DI.UsageTests/Advanced/TrackingDisposableScenario.cs @@ -9,7 +9,7 @@ // ReSharper disable UnusedParameterInPartialMethod // ReSharper disable ArrangeTypeModifiers // ReSharper disable ArrangeTypeMemberModifiers -namespace Pure.DI.UsageTests.Basics.TrackingDisposableScenario; +namespace Pure.DI.UsageTests.Advanced.TrackingDisposableScenario; using Xunit; diff --git a/tests/Pure.DI.UsageTests/Attributes/ConstructorOrdinalAttributeScenario.cs b/tests/Pure.DI.UsageTests/Attributes/ConstructorOrdinalAttributeScenario.cs index b87fbc4b6..7ab0006db 100644 --- a/tests/Pure.DI.UsageTests/Attributes/ConstructorOrdinalAttributeScenario.cs +++ b/tests/Pure.DI.UsageTests/Attributes/ConstructorOrdinalAttributeScenario.cs @@ -28,6 +28,8 @@ class Service : IService { private readonly string _name; + // The integer value in the argument specifies + // the ordinal of injection [Ordinal(1)] public Service(IDependency dependency) => _name = "with dependency"; diff --git a/tests/Pure.DI.UsageTests/Attributes/MemberOrdinalAttributeScenario.cs b/tests/Pure.DI.UsageTests/Attributes/MemberOrdinalAttributeScenario.cs index f9f9f9d6f..b40c9634c 100644 --- a/tests/Pure.DI.UsageTests/Attributes/MemberOrdinalAttributeScenario.cs +++ b/tests/Pure.DI.UsageTests/Attributes/MemberOrdinalAttributeScenario.cs @@ -28,6 +28,9 @@ class Person : IPerson public string Name => _name.ToString(); + // The Ordinal attribute specifies to perform an injection, + // the integer value in the argument specifies + // the ordinal of injection [Ordinal(0)] public int Id; diff --git a/tests/Pure.DI.UsageTests/Basics/CompositionRootsScenario.cs b/tests/Pure.DI.UsageTests/Basics/CompositionRootsScenario.cs index 5722d94bc..cdb5c6f76 100644 --- a/tests/Pure.DI.UsageTests/Basics/CompositionRootsScenario.cs +++ b/tests/Pure.DI.UsageTests/Basics/CompositionRootsScenario.cs @@ -58,18 +58,18 @@ public void Run() .Bind("Other").To() .Bind().To() - // Specifies to create a regular public composition root - // of type "IService" with the name "SomeOtherService" - // using the "Other" tag - .Root("SomeOtherService", "Other") - // Specifies to create a regular public composition root // of type "IService" with the name "MyRoot" .Root("MyRoot") // Specifies to create a private composition root // that is only accessible from "Resolve()" methods - .Root(); + .Root() + + // Specifies to create a regular public composition root + // of type "IService" with the name "SomeOtherService" + // using the "Other" tag + .Root("SomeOtherService", "Other"); var composition = new Composition(); @@ -79,6 +79,8 @@ public void Run() // someOtherService = new OtherService(); var someOtherService = composition.SomeOtherService; + // All and only the roots of the composition + // can be obtained by Resolve method var dependency = composition.Resolve(); // } service.ShouldBeOfType(); diff --git a/tests/Pure.DI.UsageTests/Basics/CompositionRootsSimplifiedScenario.cs b/tests/Pure.DI.UsageTests/Basics/CompositionRootsSimplifiedScenario.cs deleted file mode 100644 index 967884da7..000000000 --- a/tests/Pure.DI.UsageTests/Basics/CompositionRootsSimplifiedScenario.cs +++ /dev/null @@ -1,64 +0,0 @@ -/* -$v=true -$p=1 -$d=Composition roots simplified -$h=You can use `RootBind()` method in order to reduce repetitions. -*/ - -// ReSharper disable ClassNeverInstantiated.Local -// ReSharper disable CheckNamespace -// ReSharper disable UnusedParameter.Local -// ReSharper disable ArrangeTypeModifiers -// ReSharper disable ClassNeverInstantiated.Global -// ReSharper disable UnusedVariable -#pragma warning disable CS9113 // Parameter is unread. -namespace Pure.DI.UsageTests.Basics.CompositionRootsSimplifiedScenario; - -using Shouldly; -using Xunit; - -// { -interface IDependency; - -class Dependency : IDependency; - -interface IService; - -class Service(IDependency dependency) : IService; - -class OtherService : IService; -// } - -public class Scenario -{ - [Fact] - public void Run() - { -// { - DI.Setup(nameof(Composition)) - // Specifies to create a regular public composition root - // of type "IService" with the name "MyRoot" and - // it's the equivalent of statements - // .Bind().To().Root("MyRoot") - .RootBind("MyRoot").To() - - // Specifies to create a private composition root - // that is only accessible from "Resolve()" methods and - // it's the equivalent of statements - // .Bind("Other").To().Root("MyRoot") - .RootBind(tags: "Other").To() - - .Bind().To(); - - var composition = new Composition(); - - // service = new Service(new Dependency()); - var service = composition.MyRoot; - - // someOtherService = new OtherService(); - var someOtherService = composition.Resolve("Other"); -// } - service.ShouldBeOfType(); - composition.SaveClassDiagram(); - } -} \ No newline at end of file diff --git a/tests/Pure.DI.UsageTests/Basics/DefaultValuesScenario.cs b/tests/Pure.DI.UsageTests/Basics/DefaultValuesScenario.cs index da772e9db..3ef28a3a9 100644 --- a/tests/Pure.DI.UsageTests/Basics/DefaultValuesScenario.cs +++ b/tests/Pure.DI.UsageTests/Basics/DefaultValuesScenario.cs @@ -25,6 +25,8 @@ interface IService IDependency Dependency { get;} } +// If injection cannot be performed explicitly, +// the default value will be used class Service(string name = "My Service") : IService { public string Name { get; } = name; diff --git a/tests/Pure.DI.UsageTests/Basics/FactoryScenario.cs b/tests/Pure.DI.UsageTests/Basics/FactoryScenario.cs index 69bac2fe0..99a63a53c 100644 --- a/tests/Pure.DI.UsageTests/Basics/FactoryScenario.cs +++ b/tests/Pure.DI.UsageTests/Basics/FactoryScenario.cs @@ -53,8 +53,15 @@ public void Run() .Bind().To(_ => DateTimeOffset.Now) .Bind().To(ctx => { + // Some custom logic for creating an instance. + // For example, here's how you can inject + // an instance of a particular type ctx.Inject(out Dependency dependency); + + // And do something about it dependency.Initialize(); + + // And at the end return an instance return dependency; }) .Bind().To() diff --git a/tests/Pure.DI.UsageTests/Basics/FieldInjectionScenario.cs b/tests/Pure.DI.UsageTests/Basics/FieldInjectionScenario.cs index 0330bd09d..db12d15a6 100644 --- a/tests/Pure.DI.UsageTests/Basics/FieldInjectionScenario.cs +++ b/tests/Pure.DI.UsageTests/Basics/FieldInjectionScenario.cs @@ -26,6 +26,9 @@ interface IService class Service : IService { + // The Ordinal attribute specifies to perform an injection, + // the integer value in the argument specifies + // the ordinal of injection [Ordinal(0)] internal IDependency? DependencyVal; diff --git a/tests/Pure.DI.UsageTests/Basics/InjectionScenario.cs b/tests/Pure.DI.UsageTests/Basics/InjectionScenario.cs deleted file mode 100644 index 45cb478e9..000000000 --- a/tests/Pure.DI.UsageTests/Basics/InjectionScenario.cs +++ /dev/null @@ -1,58 +0,0 @@ -/* -$v=true -$p=3 -$d=Injection -$h=This example shows how to manually create and initialize an instance by injecting the necessary dependencies. -$f=In addition to the dependency type, you can specify the dependency tag in the first parameter. Then the overloaded method `void Inject(object tag, out T value)` is used. Where the first argument is the tag, the second is the dependency instance. -*/ - -// ReSharper disable ClassNeverInstantiated.Local -// ReSharper disable CheckNamespace -// ReSharper disable UnusedVariable -// ReSharper disable UnusedMemberInSuper.Global -// ReSharper disable ArrangeTypeModifiers -// ReSharper disable UnusedMember.Global -namespace Pure.DI.UsageTests.Basics.InjectionScenario; - -using Xunit; - -// { -interface IDependency; - -class Dependency : IDependency; - -interface IService -{ - IDependency Dependency { get; } -} - -class Service(IDependency dependency) : IService -{ - public IDependency Dependency { get; } = dependency; -} -// } - -public class Scenario -{ - [Fact] - public void Run() - { -// { - DI.Setup(nameof(Composition)) - .Bind().To() - .Bind() - .To(ctx => - { - ctx.Inject(out var dependency); - return new Service(dependency); - }) - - // Composition root - .Root("Root"); - - var composition = new Composition(); - var service = composition.Root; -// } - composition.SaveClassDiagram(); - } -} \ No newline at end of file diff --git a/tests/Pure.DI.UsageTests/Basics/InjectionsOfAbstractionsScenario.cs b/tests/Pure.DI.UsageTests/Basics/InjectionsOfAbstractionsScenario.cs index a9c70b986..e2aa2ac14 100644 --- a/tests/Pure.DI.UsageTests/Basics/InjectionsOfAbstractionsScenario.cs +++ b/tests/Pure.DI.UsageTests/Basics/InjectionsOfAbstractionsScenario.cs @@ -48,7 +48,7 @@ public void Run() .Bind().To() .Bind().To() - // Specifies to create a composition root (a property) + // Specifies to create a composition root // of type "Program" with the name "Root" .Root("Root"); diff --git a/tests/Pure.DI.UsageTests/Basics/MethodInjectionScenario.cs b/tests/Pure.DI.UsageTests/Basics/MethodInjectionScenario.cs index 0c93b8693..8e8714793 100644 --- a/tests/Pure.DI.UsageTests/Basics/MethodInjectionScenario.cs +++ b/tests/Pure.DI.UsageTests/Basics/MethodInjectionScenario.cs @@ -26,6 +26,9 @@ interface IService class Service : IService { + // The Ordinal attribute specifies to perform an injection, + // the integer value in the argument specifies + // the ordinal of injection [Ordinal(0)] public void SetDependency(IDependency dependency) => Dependency = dependency; diff --git a/tests/Pure.DI.UsageTests/Basics/MultiContractBindingsScenario.cs b/tests/Pure.DI.UsageTests/Basics/MultiContractBindingsScenario.cs deleted file mode 100644 index 6085cbcac..000000000 --- a/tests/Pure.DI.UsageTests/Basics/MultiContractBindingsScenario.cs +++ /dev/null @@ -1,53 +0,0 @@ -/* -$v=true -$p=8 -$d=Multi-contract bindings -$h=An unlimited number of contracts can be attached to one implementation. Including their combinations with various tags. -*/ - -// ReSharper disable ClassNeverInstantiated.Local -// ReSharper disable CheckNamespace -// ReSharper disable UnusedParameter.Local -// ReSharper disable UnusedVariable -// ReSharper disable ArrangeTypeModifiers -#pragma warning disable CS9113 // Parameter is unread. -namespace Pure.DI.UsageTests.Basics.MultiContractBindingsScenario; - -using Xunit; - -// { -interface IDependency; - -interface IAdvancedDependency; - -class Dependency : IDependency, IAdvancedDependency; - -interface IService; - -class Service( - IDependency dependency, - IAdvancedDependency advancedDependency) - : IService; -// } - -public class Scenario -{ - [Fact] - public void Run() - { -// { - DI.Setup(nameof(Composition)) - .Bind().To() - // .Bind().Bind().To() - // is also allowed - .Bind().To() - - // Composition root - .Root("Root"); - - var composition = new Composition(); - var service = composition.Root; -// } - composition.SaveClassDiagram(); - } -} \ No newline at end of file diff --git a/tests/Pure.DI.UsageTests/Basics/PropertyInjectionScenario.cs b/tests/Pure.DI.UsageTests/Basics/PropertyInjectionScenario.cs index c51c76ac7..60ac1c94c 100644 --- a/tests/Pure.DI.UsageTests/Basics/PropertyInjectionScenario.cs +++ b/tests/Pure.DI.UsageTests/Basics/PropertyInjectionScenario.cs @@ -26,6 +26,9 @@ interface IService class Service : IService { + // The Ordinal attribute specifies to perform an injection, + // the integer value in the argument specifies + // the ordinal of injection [Ordinal(0)] public IDependency? Dependency { get; set; } } diff --git a/tests/Pure.DI.UsageTests/Basics/RequiredPropertiesOrFieldsScenario.cs b/tests/Pure.DI.UsageTests/Basics/RequiredPropertiesOrFieldsScenario.cs index 72791092a..2644e8666 100644 --- a/tests/Pure.DI.UsageTests/Basics/RequiredPropertiesOrFieldsScenario.cs +++ b/tests/Pure.DI.UsageTests/Basics/RequiredPropertiesOrFieldsScenario.cs @@ -32,6 +32,8 @@ class Service : IService public string Name => ServiceNameField; + // The required property will be injected automatically + // without additional effort public required IDependency Dependency { get; init; } } // } diff --git a/tests/Pure.DI.UsageTests/Basics/ResolveScenario.cs b/tests/Pure.DI.UsageTests/Basics/ResolveMethodsScenario.cs similarity index 97% rename from tests/Pure.DI.UsageTests/Basics/ResolveScenario.cs rename to tests/Pure.DI.UsageTests/Basics/ResolveMethodsScenario.cs index 61dd95d8d..15752d53a 100644 --- a/tests/Pure.DI.UsageTests/Basics/ResolveScenario.cs +++ b/tests/Pure.DI.UsageTests/Basics/ResolveMethodsScenario.cs @@ -11,7 +11,7 @@ // ReSharper disable ArrangeTypeModifiers // ReSharper disable UnusedVariable #pragma warning disable CS9113 // Parameter is unread. -namespace Pure.DI.UsageTests.Basics.ResolveScenario; +namespace Pure.DI.UsageTests.Basics.ResolveMethodsScenario; using Shouldly; using Xunit; diff --git a/tests/Pure.DI.UsageTests/Basics/RootBindScenario.cs b/tests/Pure.DI.UsageTests/Basics/RootBindScenario.cs index 418d3aa19..a16041c39 100644 --- a/tests/Pure.DI.UsageTests/Basics/RootBindScenario.cs +++ b/tests/Pure.DI.UsageTests/Basics/RootBindScenario.cs @@ -1,7 +1,7 @@ /* $v=true $p=17 -$d=RootBind +$d=Root binding $h=You might want to register some services as roots. You can use `RootBind()` method in order to reduce repetitions. The registration `composition.RootBind().To()` is an equivalent to `composition.Bind().To().Root()`. */ diff --git a/tests/Pure.DI.UsageTests/Lifetimes/DefaultLifetimeScenario.cs b/tests/Pure.DI.UsageTests/Lifetimes/DefaultLifetimeScenario.cs index cc9b395be..b6dd82610 100644 --- a/tests/Pure.DI.UsageTests/Lifetimes/DefaultLifetimeScenario.cs +++ b/tests/Pure.DI.UsageTests/Lifetimes/DefaultLifetimeScenario.cs @@ -42,7 +42,11 @@ public void Run() { // { DI.Setup(nameof(Composition)) + // Default Lifetime applies + // to all bindings until the end of the chain + // or the next call to the DefaultLifetime method .DefaultLifetime(Lifetime.Singleton) + .Bind().To() .RootBind("Root").To();