From 8e9dba3337affecfb0d80b2f3859bcafb2ff4169 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 | 11 +- docs/README.md | 7 + readme/ArrayDetails.md | 102 +------ readme/EnumDetails.md | 112 ++------ readme/FooterTemplate.md | 5 - readme/FuncDetails.md | 85 +----- readme/ReadmeTemplate.md | 42 ++- readme/SingletonDetails.md | 91 ++---- readme/TransientDetails.md | 83 +----- readme/a-few-partial-classes.md | 48 +--- readme/accumulators.md | 60 +--- readme/advanced-interception.md | 48 +--- readme/arguments.md | 52 +--- readme/array.md | 55 +--- readme/async-disposable-scope.md | 74 +---- readme/async-disposable-singleton.md | 56 +--- readme/async-enumerable.md | 57 +--- readme/auto-bindings.md | 20 +- readme/auto-scoped.md | 58 +--- readme/check-for-a-root.md | 54 +--- readme/complex-generics.md | 62 +--- readme/composition-root-kinds.md | 62 +--- readme/composition-roots-simplified.md | 269 ------------------ readme/composition-roots.md | 84 ++---- readme/constructor-ordinal-attribute.md | 42 +-- readme/custom-attributes.md | 43 +-- readme/decorator.md | 43 +-- readme/default-lifetime.md | 53 +--- readme/default-values.md | 51 +--- readme/dependent-compositions.md | 101 ++----- readme/disposable-singleton.md | 49 +--- readme/enumerable-generics.md | 90 ++---- readme/enumerable.md | 57 +--- readme/factory.md | 51 ++-- readme/field-injection.md | 52 +--- readme/func-with-arguments.md | 56 +--- readme/func-with-tag.md | 52 +--- readme/func.md | 52 +--- ...eric-composition-roots-with-constraints.md | 44 +-- readme/generic-composition-roots.md | 39 +-- readme/generics.md | 58 +--- readme/injection.md | 245 ---------------- readme/injections-of-abstractions.md | 38 +-- readme/instance-initialization.md | 266 ----------------- readme/interception.md | 38 +-- readme/keyed-service-provider.md | 53 +--- readme/lazy.md | 54 +--- readme/manually-started-tasks.md | 45 +-- readme/member-ordinal-attribute.md | 50 +--- readme/method-injection.md | 52 +--- readme/multi-contract-bindings.md | 248 ---------------- readme/oncannotresolve-hint.md | 50 +--- readme/ondependencyinjection-hint.md | 48 +--- readme/onnewinstance-hint.md | 48 +--- readme/overriding-the-bcl-binding.md | 40 +-- readme/partial-class.md | 47 +-- readme/perblock.md | 55 +--- readme/perresolve.md | 55 +--- readme/property-injection.md | 52 +--- readme/required-properties-or-fields.md | 54 +--- readme/resolve-hint.md | 36 +-- readme/resolve-methods.md | 64 +---- readme/root-arguments.md | 37 +-- readme/{rootbind.md => root-binding.md} | 40 +-- readme/scope.md | 67 +---- readme/service-collection.md | 53 +--- readme/service-provider-with-scope.md | 54 +--- readme/service-provider.md | 53 +--- readme/simplified-binding.md | 34 +-- readme/singleton.md | 49 +--- readme/span-and-readonlyspan.md | 46 +-- readme/tag-attribute.md | 53 +--- readme/tag-type.md | 60 +--- readme/tag-unique.md | 57 +--- readme/tags.md | 60 +--- readme/task.md | 53 +--- readme/threadsafe-hint.md | 48 +--- readme/tostring-hint.md | 48 +--- ...async-disposable-instances-in-delegates.md | 64 +---- ...osable-instances-per-a-composition-root.md | 54 +--- ...cking-disposable-instances-in-delegates.md | 58 +--- ...osable-instances-per-a-composition-root.md | 48 +--- readme/transient.md | 49 +--- readme/tuple.md | 54 +--- readme/type-attribute.md | 46 +-- readme/valuetask.md | 50 +--- readme/weak-reference.md | 52 +--- samples/ShroedingersCat/Program.cs | 4 +- .../Program.cs | 4 +- src/Pure.DI.Core/Core/Code/ClassBuilder.cs | 56 ++-- .../Core/Code/ClassDiagramBuilder.cs | 11 +- .../Core/Code/ResolverClassesBuilder.cs | 3 + .../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 + 114 files changed, 997 insertions(+), 4911 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} (82%) 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..85119f87e 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Pure DI for .NET +_Supports .NET starting with .NET Framework 2.0, released 2005-10-27, and all newer versions._ + [![NuGet](https://buildstats.info/nuget/Pure.DI)](https://www.nuget.org/packages/Pure.DI) [![License](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE) @@ -8,6 +10,11 @@ ![](readme/di.gif) +## Usage requirements + +- 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..44ca4421a 100644 --- a/build/ReadmeTarget.cs +++ b/build/ReadmeTarget.cs @@ -335,9 +335,10 @@ private static async Task AddExample(string logsDirectory, string exampleSearchP .SkipWhile(i => i != "{") .Skip(2) .Reverse() - .SkipWhile(i => i != "}") - .Skip(1) + .SkipWhile(i => !i.Contains("public override string ToString()")) + .Skip(5) .Reverse() + .Concat(["}"]) .Where(i => { var line = i.TrimStart(); @@ -361,7 +362,11 @@ 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)256", "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..dcad8f68b 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,5 +1,7 @@ # Pure DI for .NET +_Supports .NET starting with .NET Framework 2.0, released 2005-10-27, and all newer versions._ + [![NuGet](https://buildstats.info/nuget/Pure.DI)](https://www.nuget.org/packages/Pure.DI) [![License](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE) @@ -8,6 +10,11 @@ ![](readme/di.gif) +## Usage requirements + +- 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..ef81d680a 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; @@ -166,85 +166,6 @@ partial class Array throw new InvalidOperationException($"{CannotResolveMessage} \"{tag}\" {OfTypeMessage} {type}."); } - public override string ToString() - { - return - "classDiagram\n" + - " class Array {\n" + - " +CompositionRoot TestPureDIByCR()\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 CompositionRoot {\n" + - " +CompositionRoot(IService1 service1, IService2 service21, IService2 service22, IService2 service23, IService3 service3, IService4 service41, IService4 service42)\n" + - " }\n" + - " Service1 --|> IService1 : \n" + - " class Service1 {\n" + - " +Service1(IService2 service2)\n" + - " }\n" + - " Service2Array --|> IService2 : \n" + - " class Service2Array {\n" + - " +Service2Array(ArrayᐸIService3ᐳ services)\n" + - " }\n" + - " Service3 --|> IService3 : \n" + - " class Service3 {\n" + - " +Service3(IService4 service41, IService4 service42)\n" + - " }\n" + - " Service3v2 --|> IService3 : 2 \n" + - " class Service3v2 {\n" + - " +Service3v2(IService4 service41, IService4 service42)\n" + - " }\n" + - " Service3v3 --|> IService3 : 3 \n" + - " class Service3v3 {\n" + - " +Service3v3(IService4 service41, IService4 service42)\n" + - " }\n" + - " Service3v4 --|> IService3 : 4 \n" + - " class Service3v4 {\n" + - " +Service3v4(IService4 service41, IService4 service42)\n" + - " }\n" + - " Service4 --|> IService4 : \n" + - " class Service4 {\n" + - " +Service4()\n" + - " }\n" + - " class ArrayᐸIService3ᐳ\n" + - " class IService1 {\n" + - " <>\n" + - " }\n" + - " class IService2 {\n" + - " <>\n" + - " }\n" + - " class IService3 {\n" + - " <>\n" + - " }\n" + - " class IService4 {\n" + - " <>\n" + - " }\n" + - " CompositionRoot *-- Service1 : IService1\n" + - " CompositionRoot *-- Service2Array : IService2\n" + - " CompositionRoot *-- Service2Array : IService2\n" + - " CompositionRoot *-- Service2Array : IService2\n" + - " CompositionRoot *-- Service3 : IService3\n" + - " CompositionRoot *-- Service4 : IService4\n" + - " CompositionRoot *-- Service4 : IService4\n" + - " Service1 *-- Service2Array : IService2\n" + - " Service2Array *-- ArrayᐸIService3ᐳ : ArrayᐸIService3ᐳ\n" + - " Service3 *-- Service4 : IService4\n" + - " Service3 *-- Service4 : IService4\n" + - " Service3v2 *-- Service4 : IService4\n" + - " Service3v2 *-- Service4 : IService4\n" + - " Service3v3 *-- Service4 : IService4\n" + - " Service3v3 *-- Service4 : IService4\n" + - " Service3v4 *-- Service4 : IService4\n" + - " Service3v4 *-- Service4 : IService4\n" + - " Array ..> CompositionRoot : CompositionRoot TestPureDIByCR()\n" + - " ArrayᐸIService3ᐳ *-- Service3 : IService3\n" + - " ArrayᐸIService3ᐳ *-- Service3v2 : 2 IService3\n" + - " ArrayᐸIService3ᐳ *-- Service3v3 : 3 IService3\n" + - " ArrayᐸIService3ᐳ *-- Service3v4 : 4 IService3"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -281,17 +202,18 @@ 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) { case null: return composition.TestPureDIByCR(); + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/EnumDetails.md b/readme/EnumDetails.md index 2281068c1..a0f2f06a1 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; @@ -175,85 +175,6 @@ partial class Enum throw new InvalidOperationException($"{CannotResolveMessage} \"{tag}\" {OfTypeMessage} {type}."); } - public override string ToString() - { - return - "classDiagram\n" + - " class Enum {\n" + - " +CompositionRoot TestPureDIByCR()\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 CompositionRoot {\n" + - " +CompositionRoot(IService1 service1, IService2 service21, IService2 service22, IService2 service23, IService3 service3, IService4 service41, IService4 service42)\n" + - " }\n" + - " Service1 --|> IService1 : \n" + - " class Service1 {\n" + - " +Service1(IService2 service2)\n" + - " }\n" + - " Service2Enum --|> IService2 : \n" + - " class Service2Enum {\n" + - " +Service2Enum(IEnumerableᐸIService3ᐳ services)\n" + - " }\n" + - " Service3 --|> IService3 : \n" + - " class Service3 {\n" + - " +Service3(IService4 service41, IService4 service42)\n" + - " }\n" + - " Service3v2 --|> IService3 : 2 \n" + - " class Service3v2 {\n" + - " +Service3v2(IService4 service41, IService4 service42)\n" + - " }\n" + - " Service3v3 --|> IService3 : 3 \n" + - " class Service3v3 {\n" + - " +Service3v3(IService4 service41, IService4 service42)\n" + - " }\n" + - " Service3v4 --|> IService3 : 4 \n" + - " class Service3v4 {\n" + - " +Service3v4(IService4 service41, IService4 service42)\n" + - " }\n" + - " Service4 --|> IService4 : \n" + - " class Service4 {\n" + - " +Service4()\n" + - " }\n" + - " class IEnumerableᐸIService3ᐳ\n" + - " class IService1 {\n" + - " <>\n" + - " }\n" + - " class IService2 {\n" + - " <>\n" + - " }\n" + - " class IService3 {\n" + - " <>\n" + - " }\n" + - " class IService4 {\n" + - " <>\n" + - " }\n" + - " CompositionRoot *-- Service1 : IService1\n" + - " CompositionRoot *-- Service2Enum : IService2\n" + - " CompositionRoot *-- Service2Enum : IService2\n" + - " CompositionRoot *-- Service2Enum : IService2\n" + - " CompositionRoot *-- Service3 : IService3\n" + - " CompositionRoot *-- Service4 : IService4\n" + - " CompositionRoot *-- Service4 : IService4\n" + - " Service1 *-- Service2Enum : IService2\n" + - " Service2Enum o-- \"PerBlock\" IEnumerableᐸIService3ᐳ : IEnumerableᐸIService3ᐳ\n" + - " Service3 *-- Service4 : IService4\n" + - " Service3 *-- Service4 : IService4\n" + - " Service3v2 *-- Service4 : IService4\n" + - " Service3v2 *-- Service4 : IService4\n" + - " Service3v3 *-- Service4 : IService4\n" + - " Service3v3 *-- Service4 : IService4\n" + - " Service3v4 *-- Service4 : IService4\n" + - " Service3v4 *-- Service4 : IService4\n" + - " Enum ..> CompositionRoot : CompositionRoot TestPureDIByCR()\n" + - " IEnumerableᐸIService3ᐳ *-- Service3 : IService3\n" + - " IEnumerableᐸIService3ᐳ *-- Service3v2 : 2 IService3\n" + - " IEnumerableᐸIService3ᐳ *-- Service3v3 : 3 IService3\n" + - " IEnumerableᐸIService3ᐳ *-- Service3v4 : 4 IService3"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -290,17 +211,18 @@ 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) { case null: return composition.TestPureDIByCR(); + default: return base.ResolveByTag(composition, 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..db5950b21 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)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] () => { - 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; @@ -152,64 +152,6 @@ partial class Func throw new InvalidOperationException($"{CannotResolveMessage} \"{tag}\" {OfTypeMessage} {type}."); } - public override string ToString() - { - return - "classDiagram\n" + - " class Func {\n" + - " +CompositionRoot TestPureDIByCR()\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 CompositionRoot {\n" + - " +CompositionRoot(IService1 service1, IService2 service21, IService2 service22, IService2 service23, IService3 service3, IService4 service41, IService4 service42)\n" + - " }\n" + - " Service1 --|> IService1 : \n" + - " class Service1 {\n" + - " +Service1(IService2 service2)\n" + - " }\n" + - " Service2Func --|> IService2 : \n" + - " class Service2Func {\n" + - " +Service2Func(FuncᐸIService3ᐳ service3Factory)\n" + - " }\n" + - " Service3 --|> IService3 : \n" + - " class Service3 {\n" + - " +Service3(IService4 service41, IService4 service42)\n" + - " }\n" + - " Service4 --|> IService4 : \n" + - " class Service4 {\n" + - " +Service4()\n" + - " }\n" + - " class FuncᐸIService3ᐳ\n" + - " class IService1 {\n" + - " <>\n" + - " }\n" + - " class IService2 {\n" + - " <>\n" + - " }\n" + - " class IService3 {\n" + - " <>\n" + - " }\n" + - " class IService4 {\n" + - " <>\n" + - " }\n" + - " CompositionRoot *-- Service1 : IService1\n" + - " CompositionRoot *-- Service2Func : IService2\n" + - " CompositionRoot *-- Service2Func : IService2\n" + - " CompositionRoot *-- Service2Func : IService2\n" + - " CompositionRoot *-- Service3 : IService3\n" + - " CompositionRoot *-- Service4 : IService4\n" + - " CompositionRoot *-- Service4 : IService4\n" + - " Service1 *-- Service2Func : IService2\n" + - " Service2Func o-- \"PerBlock\" FuncᐸIService3ᐳ : FuncᐸIService3ᐳ\n" + - " Service3 *-- Service4 : IService4\n" + - " Service3 *-- Service4 : IService4\n" + - " Func ..> CompositionRoot : CompositionRoot TestPureDIByCR()\n" + - " FuncᐸIService3ᐳ *-- Service3 : IService3"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -246,17 +188,18 @@ 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) { case null: return composition.TestPureDIByCR(); + default: return base.ResolveByTag(composition, 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..52a9870df 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; @@ -157,66 +157,6 @@ partial class Singleton throw new InvalidOperationException($"{CannotResolveMessage} \"{tag}\" {OfTypeMessage} {type}."); } - public override string ToString() - { - return - "classDiagram\n" + - " class Singleton {\n" + - " +CompositionRoot TestPureDIByCR()\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 CompositionRoot {\n" + - " +CompositionRoot(IService1 service1, IService2 service21, IService2 service22, IService2 service23, IService3 service3, IService4 service41, IService4 service42)\n" + - " }\n" + - " Service1 --|> IService1 : \n" + - " class Service1 {\n" + - " +Service1(IService2 service2)\n" + - " }\n" + - " Service2 --|> IService2 : \n" + - " class Service2 {\n" + - " +Service2(IService3 service31, IService3 service32, IService3 service33, IService3 service34, IService3 service35)\n" + - " }\n" + - " Service3 --|> IService3 : \n" + - " class Service3 {\n" + - " +Service3(IService4 service41, IService4 service42)\n" + - " }\n" + - " Service4 --|> IService4 : \n" + - " class Service4 {\n" + - " +Service4()\n" + - " }\n" + - " class IService1 {\n" + - " <>\n" + - " }\n" + - " class IService2 {\n" + - " <>\n" + - " }\n" + - " class IService3 {\n" + - " <>\n" + - " }\n" + - " class IService4 {\n" + - " <>\n" + - " }\n" + - " CompositionRoot o-- \"Scoped\" Service1 : IService1\n" + - " CompositionRoot *-- Service2 : IService2\n" + - " CompositionRoot *-- Service2 : IService2\n" + - " CompositionRoot *-- Service2 : IService2\n" + - " CompositionRoot *-- Service3 : IService3\n" + - " CompositionRoot o-- \"Scoped\" Service4 : IService4\n" + - " CompositionRoot o-- \"Scoped\" Service4 : IService4\n" + - " Service1 *-- Service2 : IService2\n" + - " Service2 *-- Service3 : IService3\n" + - " Service2 *-- Service3 : IService3\n" + - " Service2 *-- Service3 : IService3\n" + - " Service2 *-- Service3 : IService3\n" + - " Service2 *-- Service3 : IService3\n" + - " Service3 o-- \"Scoped\" Service4 : IService4\n" + - " Service3 o-- \"Scoped\" Service4 : IService4\n" + - " Singleton ..> CompositionRoot : CompositionRoot TestPureDIByCR()"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -253,17 +193,18 @@ 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) { case null: return composition.TestPureDIByCR(); + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/TransientDetails.md b/readme/TransientDetails.md index fae00645c..fc9aae9ab 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; @@ -147,66 +147,6 @@ partial class Transient throw new InvalidOperationException($"{CannotResolveMessage} \"{tag}\" {OfTypeMessage} {type}."); } - public override string ToString() - { - return - "classDiagram\n" + - " class Transient {\n" + - " +CompositionRoot TestPureDIByCR()\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 CompositionRoot {\n" + - " +CompositionRoot(IService1 service1, IService2 service21, IService2 service22, IService2 service23, IService3 service3, IService4 service41, IService4 service42)\n" + - " }\n" + - " Service1 --|> IService1 : \n" + - " class Service1 {\n" + - " +Service1(IService2 service2)\n" + - " }\n" + - " Service2 --|> IService2 : \n" + - " class Service2 {\n" + - " +Service2(IService3 service31, IService3 service32, IService3 service33, IService3 service34, IService3 service35)\n" + - " }\n" + - " Service3 --|> IService3 : \n" + - " class Service3 {\n" + - " +Service3(IService4 service41, IService4 service42)\n" + - " }\n" + - " Service4 --|> IService4 : \n" + - " class Service4 {\n" + - " +Service4()\n" + - " }\n" + - " class IService1 {\n" + - " <>\n" + - " }\n" + - " class IService2 {\n" + - " <>\n" + - " }\n" + - " class IService3 {\n" + - " <>\n" + - " }\n" + - " class IService4 {\n" + - " <>\n" + - " }\n" + - " CompositionRoot *-- Service1 : IService1\n" + - " CompositionRoot *-- Service2 : IService2\n" + - " CompositionRoot *-- Service2 : IService2\n" + - " CompositionRoot *-- Service2 : IService2\n" + - " CompositionRoot *-- Service3 : IService3\n" + - " CompositionRoot *-- Service4 : IService4\n" + - " CompositionRoot *-- Service4 : IService4\n" + - " Service1 *-- Service2 : IService2\n" + - " Service2 *-- Service3 : IService3\n" + - " Service2 *-- Service3 : IService3\n" + - " Service2 *-- Service3 : IService3\n" + - " Service2 *-- Service3 : IService3\n" + - " Service2 *-- Service3 : IService3\n" + - " Service3 *-- Service4 : IService4\n" + - " Service3 *-- Service4 : IService4\n" + - " Transient ..> CompositionRoot : CompositionRoot TestPureDIByCR()"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -243,17 +183,18 @@ 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) { case null: return composition.TestPureDIByCR(); + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/a-few-partial-classes.md b/readme/a-few-partial-classes.md index 11cf89026..07757418a 100644 --- a/readme/a-few-partial-classes.md +++ b/readme/a-few-partial-classes.md @@ -62,10 +62,10 @@ classDiagram +Service(IDependency dependency) } class IDependency { - <> + <> } class IService { - <> + <> } Service *-- Dependency : IDependency Composition ..> Service : IService Root @@ -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; @@ -160,35 +160,6 @@ partial class Composition 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" + - " class Dependency {\n" + - " +Dependency()\n" + - " }\n" + - " Service --|> IService : \n" + - " class Service {\n" + - " +Service(IDependency dependency)\n" + - " }\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " Service *-- Dependency : IDependency\n" + - " Composition ..> Service : IService Root"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -236,6 +207,7 @@ partial class Composition { case null: return composition.Root; + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/accumulators.md b/readme/accumulators.md index 85b9f6ce2..16c1e5c45 100644 --- a/readme/accumulators.md +++ b/readme/accumulators.md @@ -69,10 +69,10 @@ classDiagram +Service(IDependency dependency1, IDependency dependency2, IDependency dependency3) } class IDependency { - <> + <> } class IService { - <> + <> } ValueTupleᐸIServiceˏMyAccumulatorᐳ *-- Service : IService ValueTupleᐸIServiceˏMyAccumulatorᐳ *-- MyAccumulator : MyAccumulator @@ -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; @@ -201,47 +201,6 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} \"{tag}\" {OfTypeMessage} {type}."); } - public override string ToString() - { - return - "classDiagram\n" + - " class Composition {\n" + - " +ValueTupleᐸIServiceˏMyAccumulatorᐳ 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 MyAccumulator\n" + - " class ValueTupleᐸIServiceˏMyAccumulatorᐳ {\n" + - " +ValueTuple(IService item1, MyAccumulator item2)\n" + - " }\n" + - " AbcDependency --|> IDependency : \n" + - " class AbcDependency {\n" + - " +AbcDependency()\n" + - " }\n" + - " XyzDependency --|> IDependency : typeof(XyzDependency) \n" + - " class XyzDependency {\n" + - " +XyzDependency()\n" + - " }\n" + - " Service --|> IService : \n" + - " class Service {\n" + - " +Service(IDependency dependency1, IDependency dependency2, IDependency dependency3)\n" + - " }\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " ValueTupleᐸIServiceˏMyAccumulatorᐳ *-- Service : IService\n" + - " ValueTupleᐸIServiceˏMyAccumulatorᐳ *-- MyAccumulator : MyAccumulator\n" + - " Service *-- AbcDependency : typeof(AbcDependency) IDependency\n" + - " Service o-- \"Singleton\" XyzDependency : typeof(XyzDependency) IDependency\n" + - " Service o-- \"PerBlock\" AbcDependency : IDependency\n" + - " Composition ..> ValueTupleᐸIServiceˏMyAccumulatorᐳ : ValueTupleᐸIServiceˏMyAccumulatorᐳ Root"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -289,6 +248,7 @@ partial class Composition { case null: return composition.Root; + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/advanced-interception.md b/readme/advanced-interception.md index 0e975bfa1..404ba04ec 100644 --- a/readme/advanced-interception.md +++ b/readme/advanced-interception.md @@ -130,10 +130,10 @@ classDiagram +Service(IDependency dependency) } class IDependency { - <> + <> } class IService { - <> + <> } Service *-- Dependency : IDependency Composition ..> Service : IService Root @@ -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; @@ -230,35 +230,6 @@ partial class Composition private partial T OnDependencyInjection(in T value, object? tag, Lifetime lifetime); - 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" + - " class Dependency {\n" + - " +Dependency()\n" + - " }\n" + - " Service --|> IService : \n" + - " class Service {\n" + - " +Service(IDependency dependency)\n" + - " }\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " Service *-- Dependency : IDependency\n" + - " Composition ..> Service : IService Root"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -306,6 +277,7 @@ partial class Composition { case null: return composition.Root; + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/arguments.md b/readme/arguments.md index 67c388804..cf9113e9a 100644 --- a/readme/arguments.md +++ b/readme/arguments.md @@ -77,10 +77,10 @@ classDiagram +Service(String name, IDependency dependency) } class IDependency { - <> + <> } class IService { - <> + <> } Dependency o-- Int32 : Argument "id" Service o-- String : "name" Argument "serviceName" @@ -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; @@ -184,39 +184,6 @@ partial class Composition 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 Int32\n" + - " class String\n" + - " Dependency --|> IDependency : \n" + - " class Dependency {\n" + - " +Dependency(Int32 id)\n" + - " }\n" + - " Service --|> IService : \n" + - " class Service {\n" + - " +Service(String name, IDependency dependency)\n" + - " }\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " Dependency o-- Int32 : Argument \"id\"\n" + - " Service o-- String : \"name\" Argument \"serviceName\"\n" + - " Service *-- Dependency : IDependency\n" + - " Composition ..> Service : IService Root"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -264,6 +231,7 @@ partial class Composition { case null: return composition.Root; + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/array.md b/readme/array.md index eb27d19ea..f9cebcb36 100644 --- a/readme/array.md +++ b/readme/array.md @@ -88,10 +88,10 @@ classDiagram } class ArrayᐸIDependencyᐳ class IDependency { - <> + <> } class IService { - <> + <> } Service *-- ArrayᐸIDependencyᐳ : ArrayᐸIDependencyᐳ Composition ..> Service : IService Root @@ -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; @@ -188,42 +188,6 @@ partial class Composition 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" + - " AbcDependency --|> IDependency : \n" + - " class AbcDependency {\n" + - " +AbcDependency()\n" + - " }\n" + - " XyzDependency --|> IDependency : 2 \n" + - " class XyzDependency {\n" + - " +XyzDependency()\n" + - " }\n" + - " Service --|> IService : \n" + - " class Service {\n" + - " +Service(ArrayᐸIDependencyᐳ dependencies)\n" + - " }\n" + - " class ArrayᐸIDependencyᐳ\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " Service *-- ArrayᐸIDependencyᐳ : ArrayᐸIDependencyᐳ\n" + - " Composition ..> Service : IService Root\n" + - " ArrayᐸIDependencyᐳ *-- AbcDependency : IDependency\n" + - " ArrayᐸIDependencyᐳ *-- XyzDependency : 2 IDependency"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -271,6 +235,7 @@ partial class Composition { case null: return composition.Root; + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/async-disposable-scope.md b/readme/async-disposable-scope.md index 96bcfae44..695e119fe 100644 --- a/readme/async-disposable-scope.md +++ b/readme/async-disposable-scope.md @@ -112,13 +112,13 @@ classDiagram class Composition class FuncᐸSessionᐳ class IDependency { - <> + <> } class IAsyncDisposable { - <> + <> } class IService { - <> + <> } Session *-- Composition : Composition Program o-- "PerResolve" FuncᐸSessionᐳ : FuncᐸSessionᐳ @@ -158,7 +158,7 @@ partial class Composition: IDisposable, IAsyncDisposable public IService SessionRoot { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { if (_scoped36_Dependency == null) @@ -178,12 +178,12 @@ partial class Composition: IDisposable, IAsyncDisposable public Program ProgramRoot { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { var perResolve43_Func = default(Func); perResolve43_Func = new Func( - [MethodImpl((MethodImplOptions)256)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] () => { Composition transient2_Composition = this; @@ -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; @@ -324,54 +324,6 @@ partial class Composition: IDisposable, IAsyncDisposable partial void OnDisposeAsyncException(T asyncDisposableInstance, Exception exception) where T : IAsyncDisposable; - public override string ToString() - { - return - "classDiagram\n" + - " class Composition {\n" + - " +Program ProgramRoot\n" + - " +IService SessionRoot\n" + - " + T ResolveᐸTᐳ()\n" + - " + T ResolveᐸTᐳ(object? tag)\n" + - " + object Resolve(Type type)\n" + - " + object Resolve(Type type, object? tag)\n" + - " }\n" + - " Composition --|> IDisposable\n" + - " Composition --|> IAsyncDisposable\n" + - " class Session {\n" + - " +Session(Composition composition)\n" + - " }\n" + - " class Program {\n" + - " +Program(FuncᐸSessionᐳ sessionFactory)\n" + - " }\n" + - " Dependency --|> IDependency : \n" + - " Dependency --|> IAsyncDisposable : \n" + - " class Dependency {\n" + - " +Dependency()\n" + - " }\n" + - " Service --|> IService : \n" + - " class Service {\n" + - " +Service(IDependency dependency)\n" + - " }\n" + - " class Composition\n" + - " class FuncᐸSessionᐳ\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " class IAsyncDisposable {\n" + - " <>\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " Session *-- Composition : Composition\n" + - " Program o-- \"PerResolve\" FuncᐸSessionᐳ : FuncᐸSessionᐳ\n" + - " Service o-- \"Scoped\" Dependency : IDependency\n" + - " Composition ..> Service : IService SessionRoot\n" + - " Composition ..> Program : Program ProgramRoot\n" + - " FuncᐸSessionᐳ *-- Session : Session"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -422,6 +374,7 @@ partial class Composition: IDisposable, IAsyncDisposable { case null: return composition.SessionRoot; + default: return base.ResolveByTag(composition, tag); } @@ -441,6 +394,7 @@ partial class Composition: IDisposable, IAsyncDisposable { case null: return composition.ProgramRoot; + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/async-disposable-singleton.md b/readme/async-disposable-singleton.md index 5ed07b229..4e75d974e 100644 --- a/readme/async-disposable-singleton.md +++ b/readme/async-disposable-singleton.md @@ -69,13 +69,13 @@ classDiagram +Service(IDependency dependency) } class IDependency { - <> + <> } class IAsyncDisposable { - <> + <> } class IService { - <> + <> } Service o-- "Singleton" Dependency : IDependency Composition ..> Service : IService Root @@ -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; @@ -259,41 +259,6 @@ partial class Composition: IDisposable, IAsyncDisposable partial void OnDisposeAsyncException(T asyncDisposableInstance, Exception exception) where T : IAsyncDisposable; - 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" + - " Composition --|> IDisposable\n" + - " Composition --|> IAsyncDisposable\n" + - " Dependency --|> IDependency : \n" + - " Dependency --|> IAsyncDisposable : \n" + - " class Dependency {\n" + - " +Dependency()\n" + - " }\n" + - " Service --|> IService : \n" + - " class Service {\n" + - " +Service(IDependency dependency)\n" + - " }\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " class IAsyncDisposable {\n" + - " <>\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " Service o-- \"Singleton\" Dependency : IDependency\n" + - " Composition ..> Service : IService Root"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -341,6 +306,7 @@ partial class Composition: IDisposable, IAsyncDisposable { case null: return composition.Root; + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/async-enumerable.md b/readme/async-enumerable.md index 770c4f95c..9715fa37f 100644 --- a/readme/async-enumerable.md +++ b/readme/async-enumerable.md @@ -71,10 +71,10 @@ classDiagram } class IAsyncEnumerableᐸIDependencyᐳ class IDependency { - <> + <> } class IService { - <> + <> } Service *-- IAsyncEnumerableᐸIDependencyᐳ : IAsyncEnumerableᐸIDependencyᐳ Composition ..> Service : IService Root @@ -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; @@ -179,42 +179,6 @@ partial class Composition 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" + - " AbcDependency --|> IDependency : \n" + - " class AbcDependency {\n" + - " +AbcDependency()\n" + - " }\n" + - " XyzDependency --|> IDependency : 2 \n" + - " class XyzDependency {\n" + - " +XyzDependency()\n" + - " }\n" + - " Service --|> IService : \n" + - " class Service {\n" + - " +Service(IAsyncEnumerableᐸIDependencyᐳ dependencies)\n" + - " }\n" + - " class IAsyncEnumerableᐸIDependencyᐳ\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " Service *-- IAsyncEnumerableᐸIDependencyᐳ : IAsyncEnumerableᐸIDependencyᐳ\n" + - " Composition ..> Service : IService Root\n" + - " IAsyncEnumerableᐸIDependencyᐳ *-- AbcDependency : IDependency\n" + - " IAsyncEnumerableᐸIDependencyᐳ *-- XyzDependency : 2 IDependency"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -262,6 +226,7 @@ partial class Composition { case null: return composition.Root; + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/auto-bindings.md b/readme/auto-bindings.md index b4d6412ad..70ec1b752 100644 --- a/readme/auto-bindings.md +++ b/readme/auto-bindings.md @@ -65,30 +65,12 @@ partial class Composition public Service MyService { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return new Service(new Dependency()); } } - - public override string ToString() - { - return - "classDiagram\n" + - " class Composition {\n" + - " +Service MyService\n" + - " }\n" + - " class Dependency {\n" + - " +Dependency()\n" + - " }\n" + - " class Service {\n" + - " +Service(Dependency dependency)\n" + - " }\n" + - " Service *-- Dependency : Dependency\n" + - " Composition ..> Service : Service MyService"; - } - } ``` diff --git a/readme/auto-scoped.md b/readme/auto-scoped.md index 5d0644102..a15df8b91 100644 --- a/readme/auto-scoped.md +++ b/readme/auto-scoped.md @@ -88,7 +88,7 @@ classDiagram class FuncᐸIServiceᐳ class Composition class IDependency { - <> + <> } Program o-- "PerResolve" FuncᐸIServiceᐳ : FuncᐸIServiceᐳ Service o-- "Scoped" Dependency : IDependency @@ -124,7 +124,7 @@ partial class Composition private Service SessionRoot { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { if (_scoped36_Dependency == null) @@ -143,12 +143,12 @@ partial class Composition public Program ProgramRoot { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { var perResolve43_Func = default(Func); perResolve43_Func = new Func( - [MethodImpl((MethodImplOptions)256)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] () => { Composition transient2_Composition = this; @@ -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; @@ -226,42 +226,6 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} \"{tag}\" {OfTypeMessage} {type}."); } - public override string ToString() - { - return - "classDiagram\n" + - " class Composition {\n" + - " +Program ProgramRoot\n" + - " +Service SessionRoot\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 Program {\n" + - " +Program(FuncᐸIServiceᐳ serviceFactory)\n" + - " }\n" + - " class Service {\n" + - " +Service(IDependency dependency)\n" + - " }\n" + - " class IService\n" + - " Dependency --|> IDependency : \n" + - " class Dependency {\n" + - " +Dependency()\n" + - " }\n" + - " class FuncᐸIServiceᐳ\n" + - " class Composition\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " Program o-- \"PerResolve\" FuncᐸIServiceᐳ : FuncᐸIServiceᐳ\n" + - " Service o-- \"Scoped\" Dependency : IDependency\n" + - " IService *-- Composition : Composition\n" + - " Composition ..> Service : Service SessionRoot\n" + - " Composition ..> Program : Program ProgramRoot\n" + - " FuncᐸIServiceᐳ *-- IService : IService"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -312,6 +276,7 @@ partial class Composition { case null: return composition.SessionRoot; + default: return base.ResolveByTag(composition, tag); } @@ -331,6 +296,7 @@ partial class Composition { case null: return composition.ProgramRoot; + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/check-for-a-root.md b/readme/check-for-a-root.md index db75845e7..4f1795f73 100644 --- a/readme/check-for-a-root.md +++ b/readme/check-for-a-root.md @@ -81,10 +81,10 @@ classDiagram +IDependency Dependency } class IDependency { - <> + <> } class IService { - <> + <> } Service *-- Dependency : "MyDep" IDependency Composition ..> Dependency : IDependency _ @@ -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; @@ -192,38 +192,6 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} \"{tag}\" {OfTypeMessage} {type}."); } - public override string ToString() - { - return - "classDiagram\n" + - " class Composition {\n" + - " +IService Root\n" + - " -IDependency _\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 : \"MyDep\" \n" + - " class Dependency {\n" + - " +Dependency()\n" + - " }\n" + - " Service --|> IService : \n" + - " class Service {\n" + - " +Service()\n" + - " +IDependency Dependency\n" + - " }\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " Service *-- Dependency : \"MyDep\" IDependency\n" + - " Composition ..> Dependency : IDependency _\n" + - " Composition ..> Service : IService Root"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -278,6 +246,7 @@ partial class Composition { case null: return composition.Root; + default: return base.ResolveByTag(composition, tag); } @@ -297,6 +266,7 @@ partial class Composition { case "MyDep": return composition.Root0001; + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/complex-generics.md b/readme/complex-generics.md index 4fc557550..88f33c928 100644 --- a/readme/complex-generics.md +++ b/readme/complex-generics.md @@ -88,13 +88,13 @@ classDiagram +DependencyStruct() } class IServiceᐸStringˏInt32ˏListᐸStringᐳˏDictionaryᐸStringˏInt32ᐳᐳ { - <> + <> } class IDependencyᐸStringᐳ { - <> + <> } class IDependencyᐸInt32ᐳ { - <> + <> } ProgramᐸStringᐳ *-- ServiceᐸStringˏInt32ˏListᐸStringᐳˏDictionaryᐸStringˏInt32ᐳᐳ : IServiceᐸStringˏInt32ˏListᐸStringᐳˏDictionaryᐸStringˏInt32ᐳᐳ Composition ..> ProgramᐸStringᐳ : ProgramᐸStringᐳ Root @@ -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; @@ -191,47 +191,6 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} \"{tag}\" {OfTypeMessage} {type}."); } - public override string ToString() - { - return - "classDiagram\n" + - " class Composition {\n" + - " +ProgramᐸStringᐳ 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 ProgramᐸStringᐳ {\n" + - " +Program(IServiceᐸStringˏInt32ˏListᐸStringᐳˏDictionaryᐸStringˏInt32ᐳᐳ service)\n" + - " }\n" + - " ServiceᐸStringˏInt32ˏListᐸStringᐳˏDictionaryᐸStringˏInt32ᐳᐳ --|> IServiceᐸStringˏInt32ˏListᐸStringᐳˏDictionaryᐸStringˏInt32ᐳᐳ : \n" + - " class ServiceᐸStringˏInt32ˏListᐸStringᐳˏDictionaryᐸStringˏInt32ᐳᐳ {\n" + - " +Service(IDependencyᐸStringᐳ dependency1, IDependencyᐸInt32ᐳ dependency2)\n" + - " }\n" + - " DependencyᐸStringᐳ --|> IDependencyᐸStringᐳ : \n" + - " class DependencyᐸStringᐳ {\n" + - " +Dependency()\n" + - " }\n" + - " DependencyStructᐸInt32ᐳ --|> IDependencyᐸInt32ᐳ : \"value type\" \n" + - " class DependencyStructᐸInt32ᐳ {\n" + - " +DependencyStruct()\n" + - " }\n" + - " class IServiceᐸStringˏInt32ˏListᐸStringᐳˏDictionaryᐸStringˏInt32ᐳᐳ {\n" + - " <>\n" + - " }\n" + - " class IDependencyᐸStringᐳ {\n" + - " <>\n" + - " }\n" + - " class IDependencyᐸInt32ᐳ {\n" + - " <>\n" + - " }\n" + - " ProgramᐸStringᐳ *-- ServiceᐸStringˏInt32ˏListᐸStringᐳˏDictionaryᐸStringˏInt32ᐳᐳ : IServiceᐸStringˏInt32ˏListᐸStringᐳˏDictionaryᐸStringˏInt32ᐳᐳ\n" + - " Composition ..> ProgramᐸStringᐳ : ProgramᐸStringᐳ Root\n" + - " ServiceᐸStringˏInt32ˏListᐸStringᐳˏDictionaryᐸStringˏInt32ᐳᐳ *-- DependencyᐸStringᐳ : IDependencyᐸStringᐳ\n" + - " ServiceᐸStringˏInt32ˏListᐸStringᐳˏDictionaryᐸStringˏInt32ᐳᐳ *-- DependencyStructᐸInt32ᐳ : \"value type\" IDependencyᐸInt32ᐳ"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -279,6 +238,7 @@ partial class Composition { case null: return composition.Root; + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/composition-root-kinds.md b/readme/composition-root-kinds.md index 592549d08..3d2693bb1 100644 --- a/readme/composition-root-kinds.md +++ b/readme/composition-root-kinds.md @@ -71,10 +71,10 @@ classDiagram +Dependency() } class IService { - <> + <> } class IDependency { - <> + <> } Service *-- Dependency : IDependency Composition ..> OtherService : IService GetOtherService() @@ -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; @@ -183,43 +183,6 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} \"{tag}\" {OfTypeMessage} {type}."); } - public override string ToString() - { - return - "classDiagram\n" + - " class Composition {\n" + - " +IDependency Dependency\n" + - " +IService GetOtherService()\n" + - " +IService GetRoot()\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 ..> OtherService : IService GetOtherService()\n" + - " Composition ..> Service : IService GetRoot()\n" + - " Composition ..> Dependency : IDependency Dependency"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -270,8 +233,10 @@ partial class Composition { case "Other": return composition.GetOtherService(); + case null: return composition.GetRoot(); + default: return base.ResolveByTag(composition, tag); } @@ -291,6 +256,7 @@ partial class Composition { case null: return Composition.Dependency; + default: return base.ResolveByTag(composition, tag); } 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..10a29049f 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(); ``` @@ -90,15 +92,15 @@ classDiagram +Dependency() } class IService { - <> + <> } class IDependency { - <> + <> } 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; @@ -208,43 +210,6 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} \"{tag}\" {OfTypeMessage} {type}."); } - public override string ToString() - { - return - "classDiagram\n" + - " class Composition {\n" + - " +IService MyRoot\n" + - " +IService SomeOtherService\n" + - " -IDependency _\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 ..> OtherService : IService SomeOtherService\n" + - " Composition ..> Service : IService MyRoot\n" + - " Composition ..> Dependency : IDependency _"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -295,8 +260,10 @@ partial class Composition { case "Other": return composition.SomeOtherService; + case null: return composition.MyRoot; + default: return base.ResolveByTag(composition, tag); } @@ -307,7 +274,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 +282,8 @@ 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..08010e494 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"; @@ -60,7 +62,7 @@ classDiagram ~Service(String name) } class IService { - <> + <> } Service o-- String : Argument "serviceName" Composition ..> Service : IService Root @@ -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; @@ -159,29 +161,6 @@ partial class Composition 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 String\n" + - " Service --|> IService : \n" + - " class Service {\n" + - " ~Service(String name)\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " Service o-- String : Argument \"serviceName\"\n" + - " Composition ..> Service : IService Root"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -229,6 +208,7 @@ partial class Composition { case null: return composition.Root; + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/custom-attributes.md b/readme/custom-attributes.md index dc1c3e4b8..e58766eed 100644 --- a/readme/custom-attributes.md +++ b/readme/custom-attributes.md @@ -75,7 +75,7 @@ classDiagram ~Object Id } class IPerson { - <> + <> } Person *-- String : "NikName" String Person o-- Int32 : Argument "personId" @@ -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; @@ -178,32 +178,6 @@ partial class PersonComposition throw new InvalidOperationException($"{CannotResolveMessage} \"{tag}\" {OfTypeMessage} {type}."); } - public override string ToString() - { - return - "classDiagram\n" + - " class PersonComposition {\n" + - " +IPerson Person\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 String\n" + - " class Int32\n" + - " Person --|> IPerson : \n" + - " class Person {\n" + - " +Person(String name)\n" + - " ~Object Id\n" + - " }\n" + - " class IPerson {\n" + - " <>\n" + - " }\n" + - " Person *-- String : \"NikName\" String\n" + - " Person o-- Int32 : Argument \"personId\"\n" + - " PersonComposition ..> Person : IPerson Person"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -251,6 +225,7 @@ partial class PersonComposition { case null: return composition.Person; + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/decorator.md b/readme/decorator.md index 2121a9a1f..f3dd2a866 100644 --- a/readme/decorator.md +++ b/readme/decorator.md @@ -50,7 +50,7 @@ classDiagram +GreetingService(IService baseService) } class IService { - <> + <> } GreetingService *-- Service : "base" IService Composition ..> GreetingService : IService Root @@ -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; @@ -145,32 +145,6 @@ partial class Composition 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 : \"base\" \n" + - " class Service {\n" + - " +Service()\n" + - " }\n" + - " GreetingService --|> IService : \n" + - " class GreetingService {\n" + - " +GreetingService(IService baseService)\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " GreetingService *-- Service : \"base\" IService\n" + - " Composition ..> GreetingService : IService Root"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -218,6 +192,7 @@ partial class Composition { case null: return composition.Root; + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/default-lifetime.md b/readme/default-lifetime.md index 1aaa0df4f..8417c0228 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(); @@ -59,10 +63,10 @@ classDiagram +Service(IDependency dependency1, IDependency dependency2) } class IDependency { - <> + <> } class IService { - <> + <> } Service o-- "Singleton" Dependency : IDependency Service o-- "Singleton" Dependency : IDependency @@ -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; @@ -177,36 +181,6 @@ partial class Composition 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" + - " class Dependency {\n" + - " +Dependency()\n" + - " }\n" + - " Service --|> IService : \n" + - " class Service {\n" + - " +Service(IDependency dependency1, IDependency dependency2)\n" + - " }\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " Service o-- \"Singleton\" Dependency : IDependency\n" + - " Service o-- \"Singleton\" Dependency : IDependency\n" + - " Composition ..> Service : IService Root"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -254,6 +228,7 @@ partial class Composition { case null: return composition.Root; + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/default-values.md b/readme/default-values.md index 82b0d5a63..397986475 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; @@ -56,10 +58,10 @@ classDiagram +IDependency Dependency } class IDependency { - <> + <> } class IService { - <> + <> } Service *-- Dependency : IDependency Composition ..> Service : IService Root @@ -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; @@ -157,36 +159,6 @@ partial class Composition 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" + - " class Dependency {\n" + - " +Dependency()\n" + - " }\n" + - " Service --|> IService : \n" + - " class Service {\n" + - " +Service(String name)\n" + - " +IDependency Dependency\n" + - " }\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " Service *-- Dependency : IDependency\n" + - " Composition ..> Service : IService Root"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -234,6 +206,7 @@ partial class Composition { case null: return composition.Root; + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/dependent-compositions.md b/readme/dependent-compositions.md index f96dced37..9b6087982 100644 --- a/readme/dependent-compositions.md +++ b/readme/dependent-compositions.md @@ -71,10 +71,10 @@ classDiagram +Dependency() } class IService { - <> + <> } class IDependency { - <> + <> } Program *-- Service : IService Service *-- Dependency : IDependency @@ -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; @@ -171,35 +171,6 @@ partial class Composition 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" + - " class Dependency {\n" + - " +Dependency()\n" + - " }\n" + - " Service --|> IService : \n" + - " class Service {\n" + - " +Service(IDependency dependency)\n" + - " }\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " Service *-- Dependency : IDependency\n" + - " Composition ..> Service : IService Root"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -247,6 +218,7 @@ partial class Composition { case null: return composition.Root; + default: return base.ResolveByTag(composition, tag); } @@ -277,7 +249,7 @@ partial class OtherComposition public IService Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return new Service(new Dependency()); @@ -286,26 +258,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 +285,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 +301,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 +309,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; @@ -353,41 +325,6 @@ partial class OtherComposition throw new InvalidOperationException($"{CannotResolveMessage} \"{tag}\" {OfTypeMessage} {type}."); } - public override string ToString() - { - return - "classDiagram\n" + - " class OtherComposition {\n" + - " +Program Program\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 Program {\n" + - " +Program(IService service)\n" + - " }\n" + - " Service --|> IService : \n" + - " class Service {\n" + - " +Service(IDependency dependency)\n" + - " }\n" + - " Dependency --|> IDependency : \n" + - " class Dependency {\n" + - " +Dependency()\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " Program *-- Service : IService\n" + - " Service *-- Dependency : IDependency\n" + - " OtherComposition ..> Service : IService Root\n" + - " OtherComposition ..> Program : Program Program"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -438,6 +375,7 @@ partial class OtherComposition { case null: return composition.Root; + default: return base.ResolveByTag(composition, tag); } @@ -457,6 +395,7 @@ partial class OtherComposition { case null: return composition.Program; + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/disposable-singleton.md b/readme/disposable-singleton.md index afe0bb22d..519def92f 100644 --- a/readme/disposable-singleton.md +++ b/readme/disposable-singleton.md @@ -65,10 +65,10 @@ classDiagram +Service(IDependency dependency) } class IDependency { - <> + <> } class IService { - <> + <> } Service o-- "Singleton" Dependency : IDependency Composition ..> Service : IService Root @@ -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; @@ -215,36 +215,6 @@ partial class Composition: IDisposable partial void OnDisposeException(T disposableInstance, Exception exception) where T : IDisposable; - 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" + - " Composition --|> IDisposable\n" + - " Dependency --|> IDependency : \n" + - " class Dependency {\n" + - " +Dependency()\n" + - " }\n" + - " Service --|> IService : \n" + - " class Service {\n" + - " +Service(IDependency dependency)\n" + - " }\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " Service o-- \"Singleton\" Dependency : IDependency\n" + - " Composition ..> Service : IService Root"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -292,6 +262,7 @@ partial class Composition: IDisposable { case null: return composition.Root; + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/enumerable-generics.md b/readme/enumerable-generics.md index ffbd22122..8e8ea3e3f 100644 --- a/readme/enumerable-generics.md +++ b/readme/enumerable-generics.md @@ -82,16 +82,16 @@ classDiagram +XyzDependency() } class IServiceᐸInt32ᐳ { - <> + <> } class IServiceᐸStringᐳ { - <> + <> } class IDependencyᐸInt32ᐳ { - <> + <> } class IDependencyᐸStringᐳ { - <> + <> } Composition ..> ServiceᐸInt32ᐳ : IServiceᐸInt32ᐳ IntRoot Composition ..> ServiceᐸStringᐳ : IServiceᐸStringᐳ StringRoot @@ -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; @@ -215,66 +215,6 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} \"{tag}\" {OfTypeMessage} {type}."); } - public override string ToString() - { - return - "classDiagram\n" + - " class Composition {\n" + - " +IServiceᐸInt32ᐳ IntRoot\n" + - " +IServiceᐸStringᐳ StringRoot\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ᐸInt32ᐳ --|> IServiceᐸInt32ᐳ : \n" + - " class ServiceᐸInt32ᐳ {\n" + - " +Service(IEnumerableᐸIDependencyᐸInt32ᐳᐳ dependencies)\n" + - " }\n" + - " ServiceᐸStringᐳ --|> IServiceᐸStringᐳ : \n" + - " class ServiceᐸStringᐳ {\n" + - " +Service(IEnumerableᐸIDependencyᐸStringᐳᐳ dependencies)\n" + - " }\n" + - " class IEnumerableᐸIDependencyᐸInt32ᐳᐳ\n" + - " class IEnumerableᐸIDependencyᐸStringᐳᐳ\n" + - " AbcDependencyᐸInt32ᐳ --|> IDependencyᐸInt32ᐳ : \n" + - " class AbcDependencyᐸInt32ᐳ {\n" + - " +AbcDependency()\n" + - " }\n" + - " XyzDependencyᐸInt32ᐳ --|> IDependencyᐸInt32ᐳ : \"Xyz\" \n" + - " class XyzDependencyᐸInt32ᐳ {\n" + - " +XyzDependency()\n" + - " }\n" + - " AbcDependencyᐸStringᐳ --|> IDependencyᐸStringᐳ : \n" + - " class AbcDependencyᐸStringᐳ {\n" + - " +AbcDependency()\n" + - " }\n" + - " XyzDependencyᐸStringᐳ --|> IDependencyᐸStringᐳ : \"Xyz\" \n" + - " class XyzDependencyᐸStringᐳ {\n" + - " +XyzDependency()\n" + - " }\n" + - " class IServiceᐸInt32ᐳ {\n" + - " <>\n" + - " }\n" + - " class IServiceᐸStringᐳ {\n" + - " <>\n" + - " }\n" + - " class IDependencyᐸInt32ᐳ {\n" + - " <>\n" + - " }\n" + - " class IDependencyᐸStringᐳ {\n" + - " <>\n" + - " }\n" + - " Composition ..> ServiceᐸInt32ᐳ : IServiceᐸInt32ᐳ IntRoot\n" + - " Composition ..> ServiceᐸStringᐳ : IServiceᐸStringᐳ StringRoot\n" + - " ServiceᐸInt32ᐳ o-- \"PerBlock\" IEnumerableᐸIDependencyᐸInt32ᐳᐳ : IEnumerableᐸIDependencyᐸInt32ᐳᐳ\n" + - " ServiceᐸStringᐳ o-- \"PerBlock\" IEnumerableᐸIDependencyᐸStringᐳᐳ : IEnumerableᐸIDependencyᐸStringᐳᐳ\n" + - " IEnumerableᐸIDependencyᐸInt32ᐳᐳ *-- AbcDependencyᐸInt32ᐳ : IDependencyᐸInt32ᐳ\n" + - " IEnumerableᐸIDependencyᐸInt32ᐳᐳ *-- XyzDependencyᐸInt32ᐳ : \"Xyz\" IDependencyᐸInt32ᐳ\n" + - " IEnumerableᐸIDependencyᐸStringᐳᐳ *-- AbcDependencyᐸStringᐳ : IDependencyᐸStringᐳ\n" + - " IEnumerableᐸIDependencyᐸStringᐳᐳ *-- XyzDependencyᐸStringᐳ : \"Xyz\" IDependencyᐸStringᐳ"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -325,6 +265,7 @@ partial class Composition { case null: return composition.IntRoot; + default: return base.ResolveByTag(composition, tag); } @@ -344,6 +285,7 @@ partial class Composition { case null: return composition.StringRoot; + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/enumerable.md b/readme/enumerable.md index dedf0b3ac..766f7dc5d 100644 --- a/readme/enumerable.md +++ b/readme/enumerable.md @@ -63,10 +63,10 @@ classDiagram } class IEnumerableᐸIDependencyᐳ class IDependency { - <> + <> } class IService { - <> + <> } Service o-- "PerBlock" IEnumerableᐸIDependencyᐳ : IEnumerableᐸIDependencyᐳ Composition ..> Service : IService Root @@ -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; @@ -170,42 +170,6 @@ partial class Composition 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" + - " AbcDependency --|> IDependency : \n" + - " class AbcDependency {\n" + - " +AbcDependency()\n" + - " }\n" + - " XyzDependency --|> IDependency : 2 \n" + - " class XyzDependency {\n" + - " +XyzDependency()\n" + - " }\n" + - " Service --|> IService : \n" + - " class Service {\n" + - " +Service(IEnumerableᐸIDependencyᐳ dependencies)\n" + - " }\n" + - " class IEnumerableᐸIDependencyᐳ\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " Service o-- \"PerBlock\" IEnumerableᐸIDependencyᐳ : IEnumerableᐸIDependencyᐳ\n" + - " Composition ..> Service : IService Root\n" + - " IEnumerableᐸIDependencyᐳ *-- AbcDependency : IDependency\n" + - " IEnumerableᐸIDependencyᐳ *-- XyzDependency : 2 IDependency"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -253,6 +217,7 @@ partial class Composition { case null: return composition.Root; + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/factory.md b/readme/factory.md index e528d1722..2ab53c756 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() @@ -70,7 +77,7 @@ classDiagram +Service(IDependency dependency) } class IService { - <> + <> } Dependency *-- DateTimeOffset : DateTimeOffset Service *-- Dependency : IDependency @@ -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; @@ -173,33 +180,6 @@ partial class Composition 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 Dependency {\n" + - " +Dependency(DateTimeOffset time)\n" + - " }\n" + - " class DateTimeOffset\n" + - " Service --|> IService : \n" + - " class Service {\n" + - " +Service(IDependency dependency)\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " Dependency *-- DateTimeOffset : DateTimeOffset\n" + - " Service *-- Dependency : IDependency\n" + - " Composition ..> Service : IService Root"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -247,6 +227,7 @@ partial class Composition { case null: return composition.Root; + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/field-injection.md b/readme/field-injection.md index 720077ebb..3c1c50de6 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; @@ -56,10 +59,10 @@ classDiagram ~IDependency DependencyVal } class IDependency { - <> + <> } class IService { - <> + <> } Service *-- Dependency : IDependency Composition ..> Service : IService Root @@ -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; @@ -156,36 +159,6 @@ partial class Composition 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" + - " class Dependency {\n" + - " +Dependency()\n" + - " }\n" + - " Service --|> IService : \n" + - " class Service {\n" + - " +Service()\n" + - " ~IDependency DependencyVal\n" + - " }\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " Service *-- Dependency : IDependency\n" + - " Composition ..> Service : IService Root"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -233,6 +206,7 @@ partial class Composition { case null: return composition.Root; + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/func-with-arguments.md b/readme/func-with-arguments.md index 75bdc3e57..9f5ae0e27 100644 --- a/readme/func-with-arguments.md +++ b/readme/func-with-arguments.md @@ -91,10 +91,10 @@ classDiagram +Service(FuncᐸInt32ˏIDependencyᐳ dependencyFactory) } class IClock { - <> + <> } class IService { - <> + <> } Dependency o-- "Singleton" Clock : IClock Dependency *-- Int32 : Int32 @@ -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; @@ -212,43 +212,6 @@ partial class Composition 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 Dependency {\n" + - " +Dependency(IClock clock, Int32 id)\n" + - " }\n" + - " class Int32\n" + - " class FuncᐸInt32ˏIDependencyᐳ\n" + - " Clock --|> IClock : \n" + - " class Clock {\n" + - " +Clock()\n" + - " }\n" + - " Service --|> IService : \n" + - " class Service {\n" + - " +Service(FuncᐸInt32ˏIDependencyᐳ dependencyFactory)\n" + - " }\n" + - " class IClock {\n" + - " <>\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " Dependency o-- \"Singleton\" Clock : IClock\n" + - " Dependency *-- Int32 : Int32\n" + - " FuncᐸInt32ˏIDependencyᐳ *-- Dependency : Dependency\n" + - " Service *-- FuncᐸInt32ˏIDependencyᐳ : FuncᐸInt32ˏIDependencyᐳ\n" + - " Composition ..> Service : IService Root"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -296,6 +259,7 @@ partial class Composition { case null: return composition.Root; + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/func-with-tag.md b/readme/func-with-tag.md index 0ac155b90..97c9e394b 100644 --- a/readme/func-with-tag.md +++ b/readme/func-with-tag.md @@ -57,10 +57,10 @@ classDiagram } class FuncᐸIDependencyᐳ class IDependency { - <> + <> } class IService { - <> + <> } Service o-- "PerResolve" FuncᐸIDependencyᐳ : "my tag" FuncᐸIDependencyᐳ Composition ..> Service : IService Root @@ -92,12 +92,12 @@ partial class Composition public IService Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { var perResolve39_Func = default(Func); perResolve39_Func = new Func( - [MethodImpl((MethodImplOptions)256)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] () => { var value_1 = new Dependency(); @@ -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; @@ -167,37 +167,6 @@ partial class Composition 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 : \"my tag\" \n" + - " class Dependency {\n" + - " +Dependency()\n" + - " }\n" + - " Service --|> IService : \n" + - " class Service {\n" + - " +Service(FuncᐸIDependencyᐳ dependencyFactory)\n" + - " }\n" + - " class FuncᐸIDependencyᐳ\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " Service o-- \"PerResolve\" FuncᐸIDependencyᐳ : \"my tag\" FuncᐸIDependencyᐳ\n" + - " Composition ..> Service : IService Root\n" + - " FuncᐸIDependencyᐳ *-- Dependency : \"my tag\" IDependency"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -245,6 +214,7 @@ partial class Composition { case null: return composition.Root; + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/func.md b/readme/func.md index 5760597c4..6c2547c22 100644 --- a/readme/func.md +++ b/readme/func.md @@ -60,10 +60,10 @@ classDiagram } class FuncᐸIDependencyᐳ class IDependency { - <> + <> } class IService { - <> + <> } Service o-- "PerResolve" FuncᐸIDependencyᐳ : FuncᐸIDependencyᐳ Composition ..> Service : IService Root @@ -95,12 +95,12 @@ partial class Composition public IService Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { var perResolve39_Func = default(Func); perResolve39_Func = new Func( - [MethodImpl((MethodImplOptions)256)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] () => { var value_1 = new Dependency(); @@ -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; @@ -170,37 +170,6 @@ partial class Composition 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" + - " class Dependency {\n" + - " +Dependency()\n" + - " }\n" + - " Service --|> IService : \n" + - " class Service {\n" + - " +Service(FuncᐸIDependencyᐳ dependencyFactory)\n" + - " }\n" + - " class FuncᐸIDependencyᐳ\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " Service o-- \"PerResolve\" FuncᐸIDependencyᐳ : FuncᐸIDependencyᐳ\n" + - " Composition ..> Service : IService Root\n" + - " FuncᐸIDependencyᐳ *-- Dependency : IDependency"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -248,6 +217,7 @@ partial class Composition { case null: return composition.Root; + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/generic-composition-roots-with-constraints.md b/readme/generic-composition-roots-with-constraints.md index a5ba2d667..aa6f36c59 100644 --- a/readme/generic-composition-roots-with-constraints.md +++ b/readme/generic-composition-roots-with-constraints.md @@ -73,13 +73,13 @@ classDiagram +Dependency() } class IServiceᐸTˏT4ᐳ { - <> + <> } class IServiceᐸTˏBooleanᐳ { - <> + <> } class IDependencyᐸTᐳ { - <> + <> } Composition ..> ServiceᐸTˏT4ᐳ : IServiceᐸTˏT4ᐳ GetMyRootᐸTˏT4ᐳ() Composition ..> OtherServiceᐸTᐳ : IServiceᐸTˏBooleanᐳ GetOtherServiceᐸTᐳ() @@ -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 { @@ -126,40 +126,6 @@ partial class Composition } return transient0_OtherService; } - - public override string ToString() - { - return - "classDiagram\n" + - " class Composition {\n" + - " +IServiceᐸTˏT4ᐳ GetMyRootᐸTˏT4ᐳ()\n" + - " +IServiceᐸTˏBooleanᐳ GetOtherServiceᐸTᐳ()\n" + - " }\n" + - " ServiceᐸTˏT4ᐳ --|> IServiceᐸTˏT4ᐳ : \n" + - " class ServiceᐸTˏT4ᐳ {\n" + - " +Service(IDependencyᐸTᐳ dependency)\n" + - " }\n" + - " OtherServiceᐸTᐳ --|> IServiceᐸTˏBooleanᐳ : \"Other\" \n" + - " class OtherServiceᐸTᐳ\n" + - " DependencyᐸTᐳ --|> IDependencyᐸTᐳ : \n" + - " class DependencyᐸTᐳ {\n" + - " +Dependency()\n" + - " }\n" + - " class IServiceᐸTˏT4ᐳ {\n" + - " <>\n" + - " }\n" + - " class IServiceᐸTˏBooleanᐳ {\n" + - " <>\n" + - " }\n" + - " class IDependencyᐸTᐳ {\n" + - " <>\n" + - " }\n" + - " Composition ..> ServiceᐸTˏT4ᐳ : IServiceᐸTˏT4ᐳ GetMyRootᐸTˏT4ᐳ()\n" + - " Composition ..> OtherServiceᐸTᐳ : IServiceᐸTˏBooleanᐳ GetOtherServiceᐸTᐳ()\n" + - " ServiceᐸTˏT4ᐳ *-- DependencyᐸTᐳ : IDependencyᐸTᐳ\n" + - " OtherServiceᐸTᐳ *-- DependencyᐸTᐳ : IDependencyᐸTᐳ"; - } - } ``` diff --git a/readme/generic-composition-roots.md b/readme/generic-composition-roots.md index 3d91467f0..ed1f8900d 100644 --- a/readme/generic-composition-roots.md +++ b/readme/generic-composition-roots.md @@ -70,10 +70,10 @@ classDiagram +Dependency() } class IServiceᐸT54ᐳ { - <> + <> } class IDependencyᐸT54ᐳ { - <> + <> } Composition ..> ServiceᐸT54ᐳ : IServiceᐸT54ᐳ GetMyRootᐸT54ᐳ() Composition ..> OtherServiceᐸT54ᐳ : IServiceᐸT54ᐳ GetOtherServiceᐸT54ᐳ() @@ -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; @@ -117,37 +117,6 @@ partial class Composition } return transient0_OtherService; } - - public override string ToString() - { - return - "classDiagram\n" + - " class Composition {\n" + - " +IServiceᐸT54ᐳ GetMyRootᐸT54ᐳ()\n" + - " +IServiceᐸT54ᐳ GetOtherServiceᐸT54ᐳ()\n" + - " }\n" + - " ServiceᐸT54ᐳ --|> IServiceᐸT54ᐳ : \n" + - " class ServiceᐸT54ᐳ {\n" + - " +Service(IDependencyᐸT54ᐳ dependency)\n" + - " }\n" + - " OtherServiceᐸT54ᐳ --|> IServiceᐸT54ᐳ : \"Other\" \n" + - " class OtherServiceᐸT54ᐳ\n" + - " DependencyᐸT54ᐳ --|> IDependencyᐸT54ᐳ : \n" + - " class DependencyᐸT54ᐳ {\n" + - " +Dependency()\n" + - " }\n" + - " class IServiceᐸT54ᐳ {\n" + - " <>\n" + - " }\n" + - " class IDependencyᐸT54ᐳ {\n" + - " <>\n" + - " }\n" + - " Composition ..> ServiceᐸT54ᐳ : IServiceᐸT54ᐳ GetMyRootᐸT54ᐳ()\n" + - " Composition ..> OtherServiceᐸT54ᐳ : IServiceᐸT54ᐳ GetOtherServiceᐸT54ᐳ()\n" + - " ServiceᐸT54ᐳ *-- DependencyᐸT54ᐳ : IDependencyᐸT54ᐳ\n" + - " OtherServiceᐸT54ᐳ *-- DependencyᐸT54ᐳ : IDependencyᐸT54ᐳ"; - } - } ``` diff --git a/readme/generics.md b/readme/generics.md index 213a8968d..27cd72040 100644 --- a/readme/generics.md +++ b/readme/generics.md @@ -75,13 +75,13 @@ classDiagram +Dependency() } class IService { - <> + <> } class IDependencyᐸInt32ᐳ { - <> + <> } class IDependencyᐸStringᐳ { - <> + <> } Service *-- DependencyᐸInt32ᐳ : IDependencyᐸInt32ᐳ Service *-- DependencyᐸStringᐳ : IDependencyᐸStringᐳ @@ -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; @@ -177,43 +177,6 @@ partial class Composition 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" + - " +Service(IDependencyᐸInt32ᐳ intDependency, IDependencyᐸStringᐳ stringDependency)\n" + - " }\n" + - " DependencyᐸInt32ᐳ --|> IDependencyᐸInt32ᐳ : \n" + - " class DependencyᐸInt32ᐳ {\n" + - " +Dependency()\n" + - " }\n" + - " DependencyᐸStringᐳ --|> IDependencyᐸStringᐳ : \n" + - " class DependencyᐸStringᐳ {\n" + - " +Dependency()\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " class IDependencyᐸInt32ᐳ {\n" + - " <>\n" + - " }\n" + - " class IDependencyᐸStringᐳ {\n" + - " <>\n" + - " }\n" + - " Service *-- DependencyᐸInt32ᐳ : IDependencyᐸInt32ᐳ\n" + - " Service *-- DependencyᐸStringᐳ : IDependencyᐸStringᐳ\n" + - " Composition ..> Service : IService Root"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -261,6 +224,7 @@ partial class Composition { case null: return composition.Root; + default: return base.ResolveByTag(composition, tag); } 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..bdb267a62 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"); @@ -61,10 +61,10 @@ classDiagram +Service(IDependency dependency) } class IDependency { - <> + <> } class IService { - <> + <> } Program *-- Service : IService Service *-- Dependency : IDependency @@ -93,42 +93,12 @@ partial class Composition public Program Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return new Program(new Service(new Dependency())); } } - - public override string ToString() - { - return - "classDiagram\n" + - " class Composition {\n" + - " +Program Root\n" + - " }\n" + - " class Program {\n" + - " +Program(IService service)\n" + - " }\n" + - " Dependency --|> IDependency : \n" + - " class Dependency {\n" + - " +Dependency()\n" + - " }\n" + - " Service --|> IService : \n" + - " class Service {\n" + - " +Service(IDependency dependency)\n" + - " }\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " Program *-- Service : IService\n" + - " Service *-- Dependency : IDependency\n" + - " Composition ..> Program : Program Root"; - } - } ``` 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..ff3c92845 100644 --- a/readme/interception.md +++ b/readme/interception.md @@ -70,7 +70,7 @@ classDiagram +Service() } class IService { - <> + <> } Composition ..> Service : IService Root ``` @@ -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; @@ -166,27 +166,6 @@ partial class Composition private partial T OnDependencyInjection(in T value, object? tag, Lifetime lifetime); - 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" + - " +Service()\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " Composition ..> Service : IService Root"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -234,6 +213,7 @@ partial class Composition { case null: return composition.Root; + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/keyed-service-provider.md b/readme/keyed-service-provider.md index a48448ea8..1ec8ed087 100644 --- a/readme/keyed-service-provider.md +++ b/readme/keyed-service-provider.md @@ -66,10 +66,10 @@ classDiagram +Service(IDependency dependency) } class IDependency { - <> + <> } class IService { - <> + <> } Service o-- "Singleton" Dependency : "Dependency Key" IDependency Composition ..> Dependency : IDependency _ @@ -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; @@ -198,37 +198,6 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} \"{tag}\" {OfTypeMessage} {type}."); } - public override string ToString() - { - return - "classDiagram\n" + - " class Composition {\n" + - " -IDependency _\n" + - " -IService _\n" + - " + T ResolveᐸTᐳ()\n" + - " + T ResolveᐸTᐳ(object? tag)\n" + - " + object GetService(Type type)\n" + - " + object GetRequiredKeyedService(Type type, object? tag)\n" + - " }\n" + - " Dependency --|> IDependency : \"Dependency Key\" \n" + - " class Dependency {\n" + - " +Dependency()\n" + - " }\n" + - " Service --|> IService : \"Service Key\" \n" + - " class Service {\n" + - " +Service(IDependency dependency)\n" + - " }\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " Service o-- \"Singleton\" Dependency : \"Dependency Key\" IDependency\n" + - " Composition ..> Dependency : IDependency _\n" + - " Composition ..> Service : IService _"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -279,6 +248,7 @@ partial class Composition { case "Dependency Key": return composition.Root0001; + default: return base.ResolveByTag(composition, tag); } @@ -298,6 +268,7 @@ partial class Composition { case "Service Key": return composition.Root0002; + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/lazy.md b/readme/lazy.md index e4ba6613b..608dc7977 100644 --- a/readme/lazy.md +++ b/readme/lazy.md @@ -52,10 +52,10 @@ classDiagram class LazyᐸIDependencyᐳ class FuncᐸIDependencyᐳ class IDependency { - <> + <> } class IService { - <> + <> } Service *-- LazyᐸIDependencyᐳ : LazyᐸIDependencyᐳ Composition ..> Service : IService Root @@ -88,12 +88,12 @@ partial class Composition public IService Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { var perResolve40_Func = default(Func); perResolve40_Func = new Func( - [MethodImpl((MethodImplOptions)256)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] () => { var value_1 = new Dependency(); @@ -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; @@ -168,39 +168,6 @@ partial class Composition 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" + - " class Dependency {\n" + - " +Dependency()\n" + - " }\n" + - " Service --|> IService : \n" + - " class Service {\n" + - " +Service(LazyᐸIDependencyᐳ dependency)\n" + - " }\n" + - " class LazyᐸIDependencyᐳ\n" + - " class FuncᐸIDependencyᐳ\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " Service *-- LazyᐸIDependencyᐳ : LazyᐸIDependencyᐳ\n" + - " Composition ..> Service : IService Root\n" + - " LazyᐸIDependencyᐳ o-- \"PerResolve\" FuncᐸIDependencyᐳ : FuncᐸIDependencyᐳ\n" + - " FuncᐸIDependencyᐳ *-- Dependency : IDependency"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -248,6 +215,7 @@ partial class Composition { case null: return composition.Root; + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/manually-started-tasks.md b/readme/manually-started-tasks.md index ed40b6b2e..20737ee28 100644 --- a/readme/manually-started-tasks.md +++ b/readme/manually-started-tasks.md @@ -87,10 +87,10 @@ classDiagram class TaskᐸIDependencyᐳ class FuncᐸIDependencyᐳ class IDependency { - <> + <> } class IService { - <> + <> } TaskFactory o-- CancellationToken : Argument "cancellationToken" TaskFactory *-- TaskCreationOptions : TaskCreationOptions @@ -126,12 +126,12 @@ partial class Composition _lock = _root._lock; } - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public IService GetRoot(CancellationToken cancellationToken) { var perResolve42_Func = default(Func); perResolve42_Func = new Func( - [MethodImpl((MethodImplOptions)256)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] () => { var value_1 = new Dependency(); @@ -145,43 +145,6 @@ partial class Composition } return new Service(transient1_Task); } - - public override string ToString() - { - return - "classDiagram\n" + - " class Composition {\n" + - " +IService GetRoot(CancellationToken cancellationToken)\n" + - " }\n" + - " class TaskFactory\n" + - " class CancellationToken\n" + - " Dependency --|> IDependency : \n" + - " class Dependency {\n" + - " +Dependency()\n" + - " }\n" + - " Service --|> IService : \n" + - " class Service {\n" + - " +Service(TaskᐸIDependencyᐳ dependencyTask)\n" + - " }\n" + - " class TaskᐸIDependencyᐳ\n" + - " class FuncᐸIDependencyᐳ\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " TaskFactory o-- CancellationToken : Argument \"cancellationToken\"\n" + - " TaskFactory *-- TaskCreationOptions : TaskCreationOptions\n" + - " TaskFactory *-- TaskContinuationOptions : TaskContinuationOptions\n" + - " TaskFactory *-- TaskScheduler : TaskScheduler\n" + - " Service *-- TaskᐸIDependencyᐳ : TaskᐸIDependencyᐳ\n" + - " Composition ..> Service : IService GetRoot(CancellationToken cancellationToken)\n" + - " TaskᐸIDependencyᐳ o-- \"PerResolve\" FuncᐸIDependencyᐳ : FuncᐸIDependencyᐳ\n" + - " TaskᐸIDependencyᐳ o-- CancellationToken : Argument \"cancellationToken\"\n" + - " FuncᐸIDependencyᐳ *-- Dependency : IDependency"; - } - } ``` diff --git a/readme/member-ordinal-attribute.md b/readme/member-ordinal-attribute.md index 945f8428b..57f3c5bb9 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; @@ -84,7 +87,7 @@ classDiagram +DateTime Birthday } class IPerson { - <> + <> } Person o-- Int32 : Argument "personId" Person o-- String : Argument "personName" @@ -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; @@ -195,36 +198,6 @@ partial class PersonComposition throw new InvalidOperationException($"{CannotResolveMessage} \"{tag}\" {OfTypeMessage} {type}."); } - public override string ToString() - { - return - "classDiagram\n" + - " class PersonComposition {\n" + - " +IPerson Person\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 Int32\n" + - " class String\n" + - " class DateTime\n" + - " Person --|> IPerson : \n" + - " class Person {\n" + - " +Person()\n" + - " +Int32 Id\n" + - " +String FirstName\n" + - " +DateTime Birthday\n" + - " }\n" + - " class IPerson {\n" + - " <>\n" + - " }\n" + - " Person o-- Int32 : Argument \"personId\"\n" + - " Person o-- String : Argument \"personName\"\n" + - " Person o-- DateTime : Argument \"personBirthday\"\n" + - " PersonComposition ..> Person : IPerson Person"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -272,6 +245,7 @@ partial class PersonComposition { case null: return composition.Person; + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/method-injection.md b/readme/method-injection.md index 55e3ea340..7139b79d8 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; @@ -57,10 +60,10 @@ classDiagram +SetDependency(IDependency dependency) : Void } class IDependency { - <> + <> } class IService { - <> + <> } Service *-- Dependency : IDependency Composition ..> Service : IService Root @@ -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; @@ -157,36 +160,6 @@ partial class Composition 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" + - " class Dependency {\n" + - " +Dependency()\n" + - " }\n" + - " Service --|> IService : \n" + - " class Service {\n" + - " +Service()\n" + - " +SetDependency(IDependency dependency) : Void\n" + - " }\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " Service *-- Dependency : IDependency\n" + - " Composition ..> Service : IService Root"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -234,6 +207,7 @@ partial class Composition { case null: return composition.Root; + default: return base.ResolveByTag(composition, tag); } 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..0db701f29 100644 --- a/readme/oncannotresolve-hint.md +++ b/readme/oncannotresolve-hint.md @@ -78,10 +78,10 @@ classDiagram +Service(IDependency dependency) } class IDependency { - <> + <> } class IService { - <> + <> } Dependency *-- String : String Service *-- Dependency : IDependency @@ -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; @@ -180,37 +180,6 @@ partial class Composition private partial T OnCannotResolve(object? tag, Lifetime lifetime); - 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 String\n" + - " Dependency --|> IDependency : \n" + - " class Dependency {\n" + - " +Dependency(String name)\n" + - " }\n" + - " Service --|> IService : \n" + - " class Service {\n" + - " +Service(IDependency dependency)\n" + - " }\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " Dependency *-- String : String\n" + - " Service *-- Dependency : IDependency\n" + - " Composition ..> Service : IService Root"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -258,6 +227,7 @@ partial class Composition { case null: return composition.Root; + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/ondependencyinjection-hint.md b/readme/ondependencyinjection-hint.md index b69f6bc25..01515fdf5 100644 --- a/readme/ondependencyinjection-hint.md +++ b/readme/ondependencyinjection-hint.md @@ -76,10 +76,10 @@ classDiagram +Service(IDependency dependency) } class IDependency { - <> + <> } class IService { - <> + <> } Service *-- Dependency : IDependency Composition ..> Service : IService Root @@ -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; @@ -176,35 +176,6 @@ partial class Composition private partial T OnDependencyInjection(in T value, object? tag, Lifetime lifetime); - 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" + - " class Dependency {\n" + - " +Dependency()\n" + - " }\n" + - " Service --|> IService : \n" + - " class Service {\n" + - " +Service(IDependency dependency)\n" + - " }\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " Service *-- Dependency : IDependency\n" + - " Composition ..> Service : IService Root"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -252,6 +223,7 @@ partial class Composition { case null: return composition.Root; + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/onnewinstance-hint.md b/readme/onnewinstance-hint.md index 48004b01d..093dc9cb2 100644 --- a/readme/onnewinstance-hint.md +++ b/readme/onnewinstance-hint.md @@ -78,10 +78,10 @@ classDiagram +Service(IDependency dependency) } class IDependency { - <> + <> } class IService { - <> + <> } Service o-- "Singleton" Dependency : IDependency Composition ..> Service : IService Root @@ -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; @@ -198,35 +198,6 @@ partial class Composition partial void OnNewInstance(ref T value, object? tag, Lifetime lifetime); - 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" + - " class Dependency {\n" + - " +Dependency()\n" + - " }\n" + - " Service --|> IService : \n" + - " class Service {\n" + - " +Service(IDependency dependency)\n" + - " }\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " Service o-- \"Singleton\" Dependency : IDependency\n" + - " Composition ..> Service : IService Root"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -274,6 +245,7 @@ partial class Composition { case null: return composition.Root; + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/overriding-the-bcl-binding.md b/readme/overriding-the-bcl-binding.md index 209f14375..63610639c 100644 --- a/readme/overriding-the-bcl-binding.md +++ b/readme/overriding-the-bcl-binding.md @@ -59,7 +59,7 @@ classDiagram +Service(ArrayᐸIDependencyᐳ dependencies) } class IService { - <> + <> } Service *-- ArrayᐸIDependencyᐳ : ArrayᐸIDependencyᐳ Composition ..> Service : IService Root @@ -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; @@ -160,29 +160,6 @@ partial class Composition 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 ArrayᐸIDependencyᐳ\n" + - " Service --|> IService : \n" + - " class Service {\n" + - " +Service(ArrayᐸIDependencyᐳ dependencies)\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " Service *-- ArrayᐸIDependencyᐳ : ArrayᐸIDependencyᐳ\n" + - " Composition ..> Service : IService Root"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -230,6 +207,7 @@ partial class Composition { case null: return composition.Root; + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/partial-class.md b/readme/partial-class.md index 479bedf16..c11d5abb5 100644 --- a/readme/partial-class.md +++ b/readme/partial-class.md @@ -87,7 +87,7 @@ classDiagram +Dependency(Int64 id) } class IDependency { - <> + <> } Service *-- String : "name with id" String Service *-- Dependency : IDependency @@ -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; @@ -188,36 +188,6 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} \"{tag}\" {OfTypeMessage} {type}."); } - public override string ToString() - { - return - "classDiagram\n" + - " class Composition {\n" + - " +Service 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 name, IDependency dependency1, IDependency dependency2)\n" + - " }\n" + - " class Int64\n" + - " class String\n" + - " Dependency --|> IDependency : \n" + - " class Dependency {\n" + - " +Dependency(Int64 id)\n" + - " }\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " Service *-- String : \"name with id\" String\n" + - " Service *-- Dependency : IDependency\n" + - " Service *-- Dependency : IDependency\n" + - " Dependency *-- Int64 : Int64\n" + - " Composition ..> Service : Service Root"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -265,6 +235,7 @@ partial class Composition { case null: return composition.Root; + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/perblock.md b/readme/perblock.md index a8fa676a0..f492a4faa 100644 --- a/readme/perblock.md +++ b/readme/perblock.md @@ -65,7 +65,7 @@ classDiagram class LazyᐸValueTupleᐸIDependencyˏIDependencyᐳᐳ class FuncᐸValueTupleᐸIDependencyˏIDependencyᐳᐳ class IDependency { - <> + <> } ValueTupleᐸIDependencyˏIDependencyᐳ o-- "PerBlock" Dependency : IDependency ValueTupleᐸIDependencyˏIDependencyᐳ o-- "PerBlock" Dependency : IDependency @@ -102,12 +102,12 @@ partial class Composition public Service Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { var perResolve43_Func = default(Func<(IDependency dep3, IDependency dep4)>); perResolve43_Func = new Func<(IDependency dep3, IDependency dep4)>( - [MethodImpl((MethodImplOptions)256)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] () => { Dependency perBlock4_Dependency = new Dependency(); @@ -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; @@ -184,42 +184,6 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} \"{tag}\" {OfTypeMessage} {type}."); } - public override string ToString() - { - return - "classDiagram\n" + - " class Composition {\n" + - " +Service 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 ValueTupleᐸIDependencyˏIDependencyᐳ {\n" + - " +ValueTuple(IDependency item1, IDependency item2)\n" + - " }\n" + - " class Service {\n" + - " +Service(IDependency dep1, IDependency dep2, LazyᐸValueTupleᐸIDependencyˏIDependencyᐳᐳ deps)\n" + - " }\n" + - " Dependency --|> IDependency : \n" + - " class Dependency {\n" + - " +Dependency()\n" + - " }\n" + - " class LazyᐸValueTupleᐸIDependencyˏIDependencyᐳᐳ\n" + - " class FuncᐸValueTupleᐸIDependencyˏIDependencyᐳᐳ\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " ValueTupleᐸIDependencyˏIDependencyᐳ o-- \"PerBlock\" Dependency : IDependency\n" + - " ValueTupleᐸIDependencyˏIDependencyᐳ o-- \"PerBlock\" Dependency : IDependency\n" + - " Service o-- \"PerBlock\" Dependency : IDependency\n" + - " Service o-- \"PerBlock\" Dependency : IDependency\n" + - " Service *-- LazyᐸValueTupleᐸIDependencyˏIDependencyᐳᐳ : LazyᐸValueTupleᐸIDependencyˏIDependencyᐳᐳ\n" + - " Composition ..> Service : Service Root\n" + - " LazyᐸValueTupleᐸIDependencyˏIDependencyᐳᐳ o-- \"PerResolve\" FuncᐸValueTupleᐸIDependencyˏIDependencyᐳᐳ : FuncᐸValueTupleᐸIDependencyˏIDependencyᐳᐳ\n" + - " FuncᐸValueTupleᐸIDependencyˏIDependencyᐳᐳ *-- ValueTupleᐸIDependencyˏIDependencyᐳ : ValueTupleᐸIDependencyˏIDependencyᐳ"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -267,6 +231,7 @@ partial class Composition { case null: return composition.Root; + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/perresolve.md b/readme/perresolve.md index 9ea47e2ae..c9bc5f2b9 100644 --- a/readme/perresolve.md +++ b/readme/perresolve.md @@ -65,7 +65,7 @@ classDiagram class LazyᐸValueTupleᐸIDependencyˏIDependencyᐳᐳ class FuncᐸValueTupleᐸIDependencyˏIDependencyᐳᐳ class IDependency { - <> + <> } ValueTupleᐸIDependencyˏIDependencyᐳ o-- "PerResolve" Dependency : IDependency ValueTupleᐸIDependencyˏIDependencyᐳ o-- "PerResolve" Dependency : IDependency @@ -102,13 +102,13 @@ partial class Composition public Service Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { var perResolve36_Dependency = default(Dependency); var perResolve43_Func = default(Func<(IDependency dep3, IDependency dep4)>); perResolve43_Func = new Func<(IDependency dep3, IDependency dep4)>( - [MethodImpl((MethodImplOptions)256)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] () => { if (perResolve36_Dependency == null) @@ -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; @@ -203,42 +203,6 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} \"{tag}\" {OfTypeMessage} {type}."); } - public override string ToString() - { - return - "classDiagram\n" + - " class Composition {\n" + - " +Service 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 ValueTupleᐸIDependencyˏIDependencyᐳ {\n" + - " +ValueTuple(IDependency item1, IDependency item2)\n" + - " }\n" + - " class Service {\n" + - " +Service(IDependency dep1, IDependency dep2, LazyᐸValueTupleᐸIDependencyˏIDependencyᐳᐳ deps)\n" + - " }\n" + - " Dependency --|> IDependency : \n" + - " class Dependency {\n" + - " +Dependency()\n" + - " }\n" + - " class LazyᐸValueTupleᐸIDependencyˏIDependencyᐳᐳ\n" + - " class FuncᐸValueTupleᐸIDependencyˏIDependencyᐳᐳ\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " ValueTupleᐸIDependencyˏIDependencyᐳ o-- \"PerResolve\" Dependency : IDependency\n" + - " ValueTupleᐸIDependencyˏIDependencyᐳ o-- \"PerResolve\" Dependency : IDependency\n" + - " Service o-- \"PerResolve\" Dependency : IDependency\n" + - " Service o-- \"PerResolve\" Dependency : IDependency\n" + - " Service *-- LazyᐸValueTupleᐸIDependencyˏIDependencyᐳᐳ : LazyᐸValueTupleᐸIDependencyˏIDependencyᐳᐳ\n" + - " Composition ..> Service : Service Root\n" + - " LazyᐸValueTupleᐸIDependencyˏIDependencyᐳᐳ o-- \"PerResolve\" FuncᐸValueTupleᐸIDependencyˏIDependencyᐳᐳ : FuncᐸValueTupleᐸIDependencyˏIDependencyᐳᐳ\n" + - " FuncᐸValueTupleᐸIDependencyˏIDependencyᐳᐳ *-- ValueTupleᐸIDependencyˏIDependencyᐳ : ValueTupleᐸIDependencyˏIDependencyᐳ"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -286,6 +250,7 @@ partial class Composition { case null: return composition.Root; + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/property-injection.md b/readme/property-injection.md index 6c19f7aea..2b47735f2 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; } } @@ -54,10 +57,10 @@ classDiagram +IDependency Dependency } class IDependency { - <> + <> } class IService { - <> + <> } Service *-- Dependency : IDependency Composition ..> Service : IService Root @@ -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; @@ -154,36 +157,6 @@ partial class Composition 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" + - " class Dependency {\n" + - " +Dependency()\n" + - " }\n" + - " Service --|> IService : \n" + - " class Service {\n" + - " +Service()\n" + - " +IDependency Dependency\n" + - " }\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " Service *-- Dependency : IDependency\n" + - " Composition ..> Service : IService Root"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -231,6 +204,7 @@ partial class Composition { case null: return composition.Root; + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/required-properties-or-fields.md b/readme/required-properties-or-fields.md index 2fd4645f9..4db5c3e13 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; } } @@ -63,10 +65,10 @@ classDiagram +IDependency Dependency } class IDependency { - <> + <> } class IService { - <> + <> } Service o-- String : Argument "name" Service *-- Dependency : IDependency @@ -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; @@ -170,39 +172,6 @@ partial class Composition 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 String\n" + - " Dependency --|> IDependency : \n" + - " class Dependency {\n" + - " +Dependency()\n" + - " }\n" + - " Service --|> IService : \n" + - " class Service {\n" + - " +Service()\n" + - " +String ServiceNameField\n" + - " +IDependency Dependency\n" + - " }\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " Service o-- String : Argument \"name\"\n" + - " Service *-- Dependency : IDependency\n" + - " Composition ..> Service : IService Root"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -250,6 +219,7 @@ partial class Composition { case null: return composition.Root; + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/resolve-hint.md b/readme/resolve-hint.md index f597491d5..3d98931c1 100644 --- a/readme/resolve-hint.md +++ b/readme/resolve-hint.md @@ -46,10 +46,10 @@ classDiagram +Service(IDependency dependency) } class IDependency { - <> + <> } class IService { - <> + <> } Service *-- Dependency : IDependency Composition ..> Dependency : IDependency DependencyRoot @@ -78,7 +78,7 @@ partial class Composition public IDependency DependencyRoot { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return new Dependency(); @@ -87,40 +87,12 @@ partial class Composition public IService Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return new Service(new Dependency()); } } - - public override string ToString() - { - return - "classDiagram\n" + - " class Composition {\n" + - " +IDependency DependencyRoot\n" + - " +IService Root\n" + - " }\n" + - " Dependency --|> IDependency : \n" + - " class Dependency {\n" + - " +Dependency()\n" + - " }\n" + - " Service --|> IService : \n" + - " class Service {\n" + - " +Service(IDependency dependency)\n" + - " }\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " Service *-- Dependency : IDependency\n" + - " Composition ..> Dependency : IDependency DependencyRoot\n" + - " Composition ..> Service : IService Root"; - } - } ``` diff --git a/readme/resolve-methods.md b/readme/resolve-methods.md index 4466da4c2..98d573d6c 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. @@ -69,10 +69,10 @@ classDiagram +OtherService() } class IDependency { - <> + <> } class IService { - <> + <> } Service *-- Dependency : IDependency Composition ..> Dependency : IDependency _ @@ -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; @@ -187,43 +187,6 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} \"{tag}\" {OfTypeMessage} {type}."); } - public override string ToString() - { - return - "classDiagram\n" + - " class Composition {\n" + - " +IService OtherService\n" + - " -IDependency _\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" + - " Dependency --|> IDependency : \n" + - " class Dependency {\n" + - " +Dependency()\n" + - " }\n" + - " Service --|> IService : \n" + - " class Service {\n" + - " +Service(IDependency dependency)\n" + - " }\n" + - " OtherService --|> IService : \"Other\" \n" + - " class OtherService {\n" + - " +OtherService()\n" + - " }\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " Service *-- Dependency : IDependency\n" + - " Composition ..> Dependency : IDependency _\n" + - " Composition ..> Service : IService _\n" + - " Composition ..> OtherService : IService OtherService"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -274,8 +237,10 @@ partial class Composition { case "Other": return composition.OtherService; + case null: return composition.Root0002; + default: return base.ResolveByTag(composition, tag); } @@ -295,6 +260,7 @@ partial class Composition { case null: return composition.Root0001; + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/root-arguments.md b/readme/root-arguments.md index 162ddbb82..6c23d7ebf 100644 --- a/readme/root-arguments.md +++ b/readme/root-arguments.md @@ -84,10 +84,10 @@ classDiagram +Service(String name, IDependency dependency) } class IDependency { - <> + <> } class IService { - <> + <> } Dependency o-- Int32 : Argument "id" Dependency o-- String : Argument "dependencyName" @@ -116,42 +116,11 @@ 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)); } - - public override string ToString() - { - return - "classDiagram\n" + - " class Composition {\n" + - " +IService CreateService(int id, string dependencyName, string serviceName)\n" + - " }\n" + - " class Int32\n" + - " class String\n" + - " Dependency --|> IDependency : \n" + - " class Dependency {\n" + - " +Dependency(Int32 id, String dependencyName)\n" + - " }\n" + - " Service --|> IService : \n" + - " class Service {\n" + - " +Service(String name, IDependency dependency)\n" + - " }\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " Dependency o-- Int32 : Argument \"id\"\n" + - " Dependency o-- String : Argument \"dependencyName\"\n" + - " Service o-- String : \"forService\" Argument \"serviceName\"\n" + - " Service *-- Dependency : IDependency\n" + - " Composition ..> Service : IService CreateService(int id, string dependencyName, string serviceName)"; - } - } ``` diff --git a/readme/rootbind.md b/readme/root-binding.md similarity index 82% rename from readme/rootbind.md rename to readme/root-binding.md index 43a573957..5c812b089 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) @@ -33,7 +33,7 @@ classDiagram +Service() } class IService { - <> + <> } Composition ..> Service : IService Root ``` @@ -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; @@ -127,27 +127,6 @@ partial class Composition 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" + - " +Service()\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " Composition ..> Service : IService Root"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -195,6 +174,7 @@ partial class Composition { case null: return composition.Root; + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/scope.md b/readme/scope.md index 0a17deb5f..dbc503234 100644 --- a/readme/scope.md +++ b/readme/scope.md @@ -108,10 +108,10 @@ classDiagram class Composition class FuncᐸSessionᐳ class IDependency { - <> + <> } class IService { - <> + <> } Session *-- Composition : Composition Program o-- "PerResolve" FuncᐸSessionᐳ : FuncᐸSessionᐳ @@ -151,7 +151,7 @@ partial class Composition: IDisposable public IService SessionRoot { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { if (_scoped36_Dependency == null) @@ -171,12 +171,12 @@ partial class Composition: IDisposable public Program ProgramRoot { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { var perResolve43_Func = default(Func); perResolve43_Func = new Func( - [MethodImpl((MethodImplOptions)256)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] () => { Composition transient2_Composition = this; @@ -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; @@ -280,49 +280,6 @@ partial class Composition: IDisposable partial void OnDisposeException(T disposableInstance, Exception exception) where T : IDisposable; - public override string ToString() - { - return - "classDiagram\n" + - " class Composition {\n" + - " +Program ProgramRoot\n" + - " +IService SessionRoot\n" + - " + T ResolveᐸTᐳ()\n" + - " + T ResolveᐸTᐳ(object? tag)\n" + - " + object Resolve(Type type)\n" + - " + object Resolve(Type type, object? tag)\n" + - " }\n" + - " Composition --|> IDisposable\n" + - " class Session {\n" + - " +Session(Composition composition)\n" + - " }\n" + - " class Program {\n" + - " +Program(FuncᐸSessionᐳ sessionFactory)\n" + - " }\n" + - " Dependency --|> IDependency : \n" + - " class Dependency {\n" + - " +Dependency()\n" + - " }\n" + - " Service --|> IService : \n" + - " class Service {\n" + - " +Service(IDependency dependency)\n" + - " }\n" + - " class Composition\n" + - " class FuncᐸSessionᐳ\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " Session *-- Composition : Composition\n" + - " Program o-- \"PerResolve\" FuncᐸSessionᐳ : FuncᐸSessionᐳ\n" + - " Service o-- \"Scoped\" Dependency : IDependency\n" + - " Composition ..> Service : IService SessionRoot\n" + - " Composition ..> Program : Program ProgramRoot\n" + - " FuncᐸSessionᐳ *-- Session : Session"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -373,6 +330,7 @@ partial class Composition: IDisposable { case null: return composition.SessionRoot; + default: return base.ResolveByTag(composition, tag); } @@ -392,6 +350,7 @@ partial class Composition: IDisposable { case null: return composition.ProgramRoot; + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/service-collection.md b/readme/service-collection.md index 3ef1d46df..6c75050ff 100644 --- a/readme/service-collection.md +++ b/readme/service-collection.md @@ -63,10 +63,10 @@ classDiagram +Service(IDependency dependency) } class IDependency { - <> + <> } class IService { - <> + <> } Service o-- "Singleton" Dependency : "Dependency Key" IDependency Composition ..> Dependency : IDependency _ @@ -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; @@ -195,37 +195,6 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} \"{tag}\" {OfTypeMessage} {type}."); } - public override string ToString() - { - return - "classDiagram\n" + - " class Composition {\n" + - " -IDependency _\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" + - " Dependency --|> IDependency : \"Dependency Key\" \n" + - " class Dependency {\n" + - " +Dependency()\n" + - " }\n" + - " Service --|> IService : \n" + - " class Service {\n" + - " +Service(IDependency dependency)\n" + - " }\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " Service o-- \"Singleton\" Dependency : \"Dependency Key\" IDependency\n" + - " Composition ..> Dependency : IDependency _\n" + - " Composition ..> Service : IService _"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -278,6 +247,7 @@ partial class Composition { case "Dependency Key": return composition.Root0001; + default: return base.ResolveByTag(composition, tag); } @@ -297,6 +267,7 @@ partial class Composition { case null: return composition.Root0002; + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/service-provider-with-scope.md b/readme/service-provider-with-scope.md index eba1a8be4..29f020731 100644 --- a/readme/service-provider-with-scope.md +++ b/readme/service-provider-with-scope.md @@ -92,10 +92,10 @@ classDiagram +Service(IDependency dependency) } class IDependency { - <> + <> } class IService { - <> + <> } Service o-- "Singleton" Dependency : IDependency Composition ..> Dependency : IDependency _ @@ -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; @@ -268,38 +268,6 @@ partial class Composition: IDisposable partial void OnDisposeException(T disposableInstance, Exception exception) where T : IDisposable; - public override string ToString() - { - return - "classDiagram\n" + - " class Composition {\n" + - " -IDependency _\n" + - " -IService _\n" + - " + T ResolveᐸTᐳ()\n" + - " + T ResolveᐸTᐳ(object? tag)\n" + - " + object GetService(Type type)\n" + - " + object GetRequiredKeyedService(Type type, object? tag)\n" + - " }\n" + - " Composition --|> IDisposable\n" + - " Dependency --|> IDependency : \n" + - " class Dependency {\n" + - " +Dependency()\n" + - " }\n" + - " Service --|> IService : \n" + - " class Service {\n" + - " +Service(IDependency dependency)\n" + - " }\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " Service o-- \"Singleton\" Dependency : IDependency\n" + - " Composition ..> Dependency : IDependency _\n" + - " Composition ..> Service : IService _"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -350,6 +318,7 @@ partial class Composition: IDisposable { case null: return composition.Root0001; + default: return base.ResolveByTag(composition, tag); } @@ -369,6 +338,7 @@ partial class Composition: IDisposable { case null: return composition.Root0002; + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/service-provider.md b/readme/service-provider.md index 7df851d96..4eff86df8 100644 --- a/readme/service-provider.md +++ b/readme/service-provider.md @@ -61,10 +61,10 @@ classDiagram +Service(IDependency dependency) } class IDependency { - <> + <> } class IService { - <> + <> } Service o-- "Singleton" Dependency : IDependency Composition ..> Dependency : IDependency _ @@ -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; @@ -193,37 +193,6 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} \"{tag}\" {OfTypeMessage} {type}."); } - public override string ToString() - { - return - "classDiagram\n" + - " class Composition {\n" + - " -IDependency _\n" + - " -IService _\n" + - " + T ResolveᐸTᐳ()\n" + - " + T ResolveᐸTᐳ(object? tag)\n" + - " + object GetService(Type type)\n" + - " + object Resolve(Type type, object? tag)\n" + - " }\n" + - " Dependency --|> IDependency : \n" + - " class Dependency {\n" + - " +Dependency()\n" + - " }\n" + - " Service --|> IService : \n" + - " class Service {\n" + - " +Service(IDependency dependency)\n" + - " }\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " Service o-- \"Singleton\" Dependency : IDependency\n" + - " Composition ..> Dependency : IDependency _\n" + - " Composition ..> Service : IService _"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -274,6 +243,7 @@ partial class Composition { case null: return composition.Root0001; + default: return base.ResolveByTag(composition, tag); } @@ -293,6 +263,7 @@ partial class Composition { case null: return composition.Root0002; + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/simplified-binding.md b/readme/simplified-binding.md index 9b9a67c6f..67ab60397 100644 --- a/readme/simplified-binding.md +++ b/readme/simplified-binding.md @@ -69,10 +69,10 @@ classDiagram +Dependency() } class IDependency { - <> + <> } class IOtherDependency { - <> + <> } Service o-- "PerBlock" Dependency : Dependency Service o-- "PerBlock" Dependency : IDependency @@ -102,41 +102,13 @@ partial class Composition public Service MyService { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { Dependency perBlock1_Dependency = new Dependency(); return new Service(perBlock1_Dependency, perBlock1_Dependency, perBlock1_Dependency); } } - - public override string ToString() - { - return - "classDiagram\n" + - " class Composition {\n" + - " +Service MyService\n" + - " }\n" + - " class Service {\n" + - " +Service(Dependency dependencyImpl, IDependency dependency, IOtherDependency otherDependency)\n" + - " }\n" + - " Dependency --|> IDependency : \n" + - " Dependency --|> IOtherDependency : \n" + - " class Dependency {\n" + - " +Dependency()\n" + - " }\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " class IOtherDependency {\n" + - " <>\n" + - " }\n" + - " Service o-- \"PerBlock\" Dependency : Dependency\n" + - " Service o-- \"PerBlock\" Dependency : IDependency\n" + - " Service o-- \"PerBlock\" Dependency : IOtherDependency\n" + - " Composition ..> Service : Service MyService"; - } - } ``` diff --git a/readme/singleton.md b/readme/singleton.md index aee69916d..fed2a850a 100644 --- a/readme/singleton.md +++ b/readme/singleton.md @@ -58,10 +58,10 @@ classDiagram +Service(IDependency dependency1, IDependency dependency2) } class IDependency { - <> + <> } class IService { - <> + <> } Service o-- "Singleton" Dependency : IDependency Service o-- "Singleton" Dependency : IDependency @@ -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; @@ -171,36 +171,6 @@ partial class Composition 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" + - " class Dependency {\n" + - " +Dependency()\n" + - " }\n" + - " Service --|> IService : \n" + - " class Service {\n" + - " +Service(IDependency dependency1, IDependency dependency2)\n" + - " }\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " Service o-- \"Singleton\" Dependency : IDependency\n" + - " Service o-- \"Singleton\" Dependency : IDependency\n" + - " Composition ..> Service : IService Root"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -248,6 +218,7 @@ partial class Composition { case null: return composition.Root; + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/span-and-readonlyspan.md b/readme/span-and-readonlyspan.md index 2d563dbc1..68de0822c 100644 --- a/readme/span-and-readonlyspan.md +++ b/readme/span-and-readonlyspan.md @@ -64,7 +64,7 @@ classDiagram } class ReadOnlySpanᐸDependencyᐳ class IService { - <> + <> } Service *-- ReadOnlySpanᐸDependencyᐳ : ReadOnlySpanᐸDependencyᐳ Composition ..> Service : IService Root @@ -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; @@ -168,35 +168,6 @@ partial class Composition 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 Dependency {\n" + - " +Dependency()\n" + - " }\n" + - " Service --|> IService : \n" + - " class Service {\n" + - " +Service(ReadOnlySpanᐸDependencyᐳ dependencies)\n" + - " }\n" + - " class ReadOnlySpanᐸDependencyᐳ\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " Service *-- ReadOnlySpanᐸDependencyᐳ : ReadOnlySpanᐸDependencyᐳ\n" + - " Composition ..> Service : IService Root\n" + - " ReadOnlySpanᐸDependencyᐳ *-- Dependency : 'a' Dependency\n" + - " ReadOnlySpanᐸDependencyᐳ *-- Dependency : 'b' Dependency\n" + - " ReadOnlySpanᐸDependencyᐳ *-- Dependency : 'c' Dependency"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -244,6 +215,7 @@ partial class Composition { case null: return composition.Root; + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/tag-attribute.md b/readme/tag-attribute.md index e4e27cf0d..97350041e 100644 --- a/readme/tag-attribute.md +++ b/readme/tag-attribute.md @@ -71,10 +71,10 @@ classDiagram +Service(IDependency dependency1, IDependency dependency2) } class IDependency { - <> + <> } class IService { - <> + <> } Service *-- AbcDependency : "Abc" IDependency Service *-- XyzDependency : "Xyz" IDependency @@ -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; @@ -170,40 +170,6 @@ partial class Composition 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" + - " AbcDependency --|> IDependency : \"Abc\" \n" + - " class AbcDependency {\n" + - " +AbcDependency()\n" + - " }\n" + - " XyzDependency --|> IDependency : \"Xyz\" \n" + - " class XyzDependency {\n" + - " +XyzDependency()\n" + - " }\n" + - " Service --|> IService : \n" + - " class Service {\n" + - " +Service(IDependency dependency1, IDependency dependency2)\n" + - " }\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " Service *-- AbcDependency : \"Abc\" IDependency\n" + - " Service *-- XyzDependency : \"Xyz\" IDependency\n" + - " Composition ..> Service : IService Root"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -251,6 +217,7 @@ partial class Composition { case null: return composition.Root; + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/tag-type.md b/readme/tag-type.md index d79cac9a3..d0a1cae89 100644 --- a/readme/tag-type.md +++ b/readme/tag-type.md @@ -81,10 +81,10 @@ classDiagram +Service(IDependency dependency1, IDependency dependency2, IDependency dependency3) } class IDependency { - <> + <> } class IService { - <> + <> } Service *-- AbcDependency : typeof(Pure.DI.UsageTests.Advanced.TagTypeScenario.AbcDependency) IDependency Service o-- "Singleton" XyzDependency : typeof(Pure.DI.UsageTests.Advanced.TagTypeScenario.XyzDependency) IDependency @@ -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; @@ -215,44 +215,6 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} \"{tag}\" {OfTypeMessage} {type}."); } - public override string ToString() - { - return - "classDiagram\n" + - " class Composition {\n" + - " +IService Root\n" + - " +IDependency XyzRoot\n" + - " + T ResolveᐸTᐳ()\n" + - " + T ResolveᐸTᐳ(object? tag)\n" + - " + object Resolve(Type type)\n" + - " + object Resolve(Type type, object? tag)\n" + - " }\n" + - " AbcDependency --|> IDependency : typeof(AbcDependency) \n" + - " AbcDependency --|> IDependency : \n" + - " class AbcDependency {\n" + - " +AbcDependency()\n" + - " }\n" + - " XyzDependency --|> IDependency : typeof(XyzDependency) \n" + - " class XyzDependency {\n" + - " +XyzDependency()\n" + - " }\n" + - " Service --|> IService : \n" + - " class Service {\n" + - " +Service(IDependency dependency1, IDependency dependency2, IDependency dependency3)\n" + - " }\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " Service *-- AbcDependency : typeof(AbcDependency) IDependency\n" + - " Service o-- \"Singleton\" XyzDependency : typeof(XyzDependency) IDependency\n" + - " Service *-- AbcDependency : IDependency\n" + - " Composition ..> Service : IService Root\n" + - " Composition ..> XyzDependency : IDependency XyzRoot"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -300,6 +262,7 @@ partial class Composition public override IDependency ResolveByTag(Composition composition, object tag) { if (Equals(tag, typeof(XyzDependency))) return composition.XyzRoot; + switch (tag) { default: @@ -321,6 +284,7 @@ partial class Composition { case null: return composition.Root; + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/tag-unique.md b/readme/tag-unique.md index b33f38ce9..d4f970e51 100644 --- a/readme/tag-unique.md +++ b/readme/tag-unique.md @@ -61,10 +61,10 @@ classDiagram +XyzDependency() } class IServiceᐸStringᐳ { - <> + <> } class IDependencyᐸStringᐳ { - <> + <> } Composition ..> ServiceᐸStringᐳ : IServiceᐸStringᐳ Root ServiceᐸStringᐳ o-- "PerBlock" IEnumerableᐸIDependencyᐸStringᐳᐳ : IEnumerableᐸIDependencyᐸStringᐳᐳ @@ -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; @@ -168,42 +168,6 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} \"{tag}\" {OfTypeMessage} {type}."); } - public override string ToString() - { - return - "classDiagram\n" + - " class Composition {\n" + - " +IServiceᐸStringᐳ 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ᐸStringᐳ --|> IServiceᐸStringᐳ : \n" + - " class ServiceᐸStringᐳ {\n" + - " +Service(IEnumerableᐸIDependencyᐸStringᐳᐳ dependencies)\n" + - " }\n" + - " class IEnumerableᐸIDependencyᐸStringᐳᐳ\n" + - " AbcDependencyᐸStringᐳ --|> IDependencyᐸStringᐳ : Unique tag 1 \n" + - " class AbcDependencyᐸStringᐳ {\n" + - " +AbcDependency()\n" + - " }\n" + - " XyzDependencyᐸStringᐳ --|> IDependencyᐸStringᐳ : Unique tag 2 \n" + - " class XyzDependencyᐸStringᐳ {\n" + - " +XyzDependency()\n" + - " }\n" + - " class IServiceᐸStringᐳ {\n" + - " <>\n" + - " }\n" + - " class IDependencyᐸStringᐳ {\n" + - " <>\n" + - " }\n" + - " Composition ..> ServiceᐸStringᐳ : IServiceᐸStringᐳ Root\n" + - " ServiceᐸStringᐳ o-- \"PerBlock\" IEnumerableᐸIDependencyᐸStringᐳᐳ : IEnumerableᐸIDependencyᐸStringᐳᐳ\n" + - " IEnumerableᐸIDependencyᐸStringᐳᐳ *-- AbcDependencyᐸStringᐳ : Unique tag 1 IDependencyᐸStringᐳ\n" + - " IEnumerableᐸIDependencyᐸStringᐳᐳ *-- XyzDependencyᐸStringᐳ : Unique tag 2 IDependencyᐸStringᐳ"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -251,6 +215,7 @@ partial class Composition { case null: return composition.Root; + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/tags.md b/readme/tags.md index 0337a12b7..f51ba6d8b 100644 --- a/readme/tags.md +++ b/readme/tags.md @@ -85,10 +85,10 @@ classDiagram +Service(IDependency dependency1, IDependency dependency2, IDependency dependency3) } class IDependency { - <> + <> } class IService { - <> + <> } Service *-- AbcDependency : "Abc" IDependency Service o-- "Singleton" XyzDependency : "Xyz" IDependency @@ -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; @@ -219,44 +219,6 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} \"{tag}\" {OfTypeMessage} {type}."); } - public override string ToString() - { - return - "classDiagram\n" + - " class Composition {\n" + - " +IService Root\n" + - " +IDependency XyzRoot\n" + - " + T ResolveᐸTᐳ()\n" + - " + T ResolveᐸTᐳ(object? tag)\n" + - " + object Resolve(Type type)\n" + - " + object Resolve(Type type, object? tag)\n" + - " }\n" + - " AbcDependency --|> IDependency : \"Abc\" \n" + - " AbcDependency --|> IDependency : \n" + - " class AbcDependency {\n" + - " +AbcDependency()\n" + - " }\n" + - " XyzDependency --|> IDependency : \"Xyz\" \n" + - " class XyzDependency {\n" + - " +XyzDependency()\n" + - " }\n" + - " Service --|> IService : \n" + - " class Service {\n" + - " +Service(IDependency dependency1, IDependency dependency2, IDependency dependency3)\n" + - " }\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " Service *-- AbcDependency : \"Abc\" IDependency\n" + - " Service o-- \"Singleton\" XyzDependency : \"Xyz\" IDependency\n" + - " Service *-- AbcDependency : IDependency\n" + - " Composition ..> XyzDependency : IDependency XyzRoot\n" + - " Composition ..> Service : IService Root"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -307,6 +269,7 @@ partial class Composition { case "Xyz": return composition.XyzRoot; + default: return base.ResolveByTag(composition, tag); } @@ -326,6 +289,7 @@ partial class Composition { case null: return composition.Root; + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/task.md b/readme/task.md index 131f653de..16da1d2eb 100644 --- a/readme/task.md +++ b/readme/task.md @@ -82,10 +82,10 @@ classDiagram class FuncᐸIDependencyᐳ class TaskFactoryᐸIDependencyᐳ class IDependency { - <> + <> } class IService { - <> + <> } TaskFactory o-- CancellationToken : Argument "cancellationToken" TaskFactory *-- TaskCreationOptions : TaskCreationOptions @@ -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); @@ -141,7 +141,7 @@ partial class Composition perBlock2_TaskFactory = new TaskFactory(cancellationToken_1, taskCreationOptions_2, taskContinuationOptions_3, taskScheduler_4); } perResolve42_Func = new Func( - [MethodImpl((MethodImplOptions)256)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] () => { var value_5 = new Dependency(); @@ -155,51 +155,6 @@ partial class Composition } return new Service(transient1_Task); } - - public override string ToString() - { - return - "classDiagram\n" + - " class Composition {\n" + - " +IService GetRoot(CancellationToken cancellationToken)\n" + - " }\n" + - " class TaskCreationOptions\n" + - " class TaskContinuationOptions\n" + - " class TaskFactory\n" + - " class TaskScheduler\n" + - " class CancellationToken\n" + - " Dependency --|> IDependency : \n" + - " class Dependency {\n" + - " +Dependency()\n" + - " }\n" + - " Service --|> IService : \n" + - " class Service {\n" + - " +Service(TaskᐸIDependencyᐳ dependencyTask)\n" + - " }\n" + - " class TaskᐸIDependencyᐳ\n" + - " class FuncᐸIDependencyᐳ\n" + - " class TaskFactoryᐸIDependencyᐳ\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " TaskFactory o-- CancellationToken : Argument \"cancellationToken\"\n" + - " TaskFactory *-- TaskCreationOptions : TaskCreationOptions\n" + - " TaskFactory *-- TaskContinuationOptions : TaskContinuationOptions\n" + - " TaskFactory *-- TaskScheduler : TaskScheduler\n" + - " Service *-- TaskᐸIDependencyᐳ : TaskᐸIDependencyᐳ\n" + - " Composition ..> Service : IService GetRoot(CancellationToken cancellationToken)\n" + - " TaskᐸIDependencyᐳ o-- \"PerResolve\" FuncᐸIDependencyᐳ : FuncᐸIDependencyᐳ\n" + - " TaskᐸIDependencyᐳ o-- \"PerBlock\" TaskFactoryᐸIDependencyᐳ : TaskFactoryᐸIDependencyᐳ\n" + - " FuncᐸIDependencyᐳ *-- Dependency : IDependency\n" + - " TaskFactoryᐸIDependencyᐳ o-- CancellationToken : Argument \"cancellationToken\"\n" + - " TaskFactoryᐸIDependencyᐳ *-- TaskCreationOptions : TaskCreationOptions\n" + - " TaskFactoryᐸIDependencyᐳ *-- TaskContinuationOptions : TaskContinuationOptions\n" + - " TaskFactoryᐸIDependencyᐳ *-- TaskScheduler : TaskScheduler"; - } - } ``` diff --git a/readme/threadsafe-hint.md b/readme/threadsafe-hint.md index d8e7d5cdb..9d988272f 100644 --- a/readme/threadsafe-hint.md +++ b/readme/threadsafe-hint.md @@ -48,10 +48,10 @@ classDiagram +Service(IDependency dependency) } class IDependency { - <> + <> } class IService { - <> + <> } Service *-- Dependency : IDependency Composition ..> Service : IService Root @@ -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; @@ -146,35 +146,6 @@ partial class Composition 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" + - " class Dependency {\n" + - " +Dependency()\n" + - " }\n" + - " Service --|> IService : \n" + - " class Service {\n" + - " +Service(IDependency dependency)\n" + - " }\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " Service *-- Dependency : IDependency\n" + - " Composition ..> Service : IService Root"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -222,6 +193,7 @@ partial class Composition { case null: return composition.Root; + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/tostring-hint.md b/readme/tostring-hint.md index 062307bf7..e77053158 100644 --- a/readme/tostring-hint.md +++ b/readme/tostring-hint.md @@ -46,10 +46,10 @@ classDiagram +Service(IDependency dependency) } class IDependency { - <> + <> } class IService { - <> + <> } Service *-- Dependency : IDependency Composition ..> Service : IService MyService @@ -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; @@ -144,35 +144,6 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} \"{tag}\" {OfTypeMessage} {type}."); } - public override string ToString() - { - return - "classDiagram\n" + - " class Composition {\n" + - " +IService MyService\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" + - " class Dependency {\n" + - " +Dependency()\n" + - " }\n" + - " Service --|> IService : \n" + - " class Service {\n" + - " +Service(IDependency dependency)\n" + - " }\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " Service *-- Dependency : IDependency\n" + - " Composition ..> Service : IService MyService"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -220,6 +191,7 @@ partial class Composition { case null: return composition.MyService; + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/tracking-async-disposable-instances-in-delegates.md b/readme/tracking-async-disposable-instances-in-delegates.md index dc49064f2..533ef11e1 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 @@ -94,13 +94,13 @@ classDiagram class FuncᐸOwnedᐸIDependencyᐳᐳ class OwnedᐸIDependencyᐳ class IDependency { - <> + <> } class IService { - <> + <> } class IAsyncDisposable { - <> + <> } Service o-- "PerResolve" FuncᐸOwnedᐸIDependencyᐳᐳ : FuncᐸOwnedᐸIDependencyᐳᐳ Composition ..> Service : Service Root @@ -134,12 +134,12 @@ partial class Composition public Service Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { var perResolve39_Func = default(Func>); perResolve39_Func = new Func>( - [MethodImpl((MethodImplOptions)256)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] () => { var accumulator38 = new Owned(); @@ -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; @@ -225,45 +225,6 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} \"{tag}\" {OfTypeMessage} {type}."); } - public override string ToString() - { - return - "classDiagram\n" + - " class Composition {\n" + - " +Service 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 Owned\n" + - " Dependency --|> IDependency : \n" + - " class Dependency {\n" + - " +Dependency()\n" + - " }\n" + - " Service --|> IService : \n" + - " Service --|> IAsyncDisposable : \n" + - " class Service {\n" + - " +Service(FuncᐸOwnedᐸIDependencyᐳᐳ dependencyFactory)\n" + - " }\n" + - " class FuncᐸOwnedᐸIDependencyᐳᐳ\n" + - " class OwnedᐸIDependencyᐳ\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " class IAsyncDisposable {\n" + - " <>\n" + - " }\n" + - " Service o-- \"PerResolve\" FuncᐸOwnedᐸIDependencyᐳᐳ : FuncᐸOwnedᐸIDependencyᐳᐳ\n" + - " Composition ..> Service : Service Root\n" + - " FuncᐸOwnedᐸIDependencyᐳᐳ o-- \"PerBlock\" OwnedᐸIDependencyᐳ : OwnedᐸIDependencyᐳ\n" + - " OwnedᐸIDependencyᐳ *-- Owned : Owned\n" + - " OwnedᐸIDependencyᐳ *-- Dependency : IDependency"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -311,6 +272,7 @@ partial class Composition { case null: return composition.Root; + default: return base.ResolveByTag(composition, tag); } 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..0767d54eb 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 @@ -85,13 +85,13 @@ classDiagram +Service(IDependency dependency) } class IDependency { - <> + <> } class IAsyncDisposable { - <> + <> } class IService { - <> + <> } Service *-- Dependency : IDependency Composition ..> OwnedᐸIServiceᐳ : OwnedᐸIServiceᐳ Root @@ -124,7 +124,7 @@ partial class Composition public Owned Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { var accumulator38 = new Owned(); @@ -147,66 +147,30 @@ 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}."); } - public override string ToString() - { - return - "classDiagram\n" + - " class Composition {\n" + - " +Ownedᐸ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 Owned\n" + - " Dependency --|> IDependency : \n" + - " Dependency --|> IAsyncDisposable : \n" + - " class Dependency {\n" + - " +Dependency()\n" + - " }\n" + - " Service --|> IService : \n" + - " class Service {\n" + - " +Service(IDependency dependency)\n" + - " }\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " class IAsyncDisposable {\n" + - " <>\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " Service *-- Dependency : IDependency\n" + - " Composition ..> OwnedᐸIServiceᐳ : OwnedᐸIServiceᐳ Root\n" + - " OwnedᐸIServiceᐳ *-- Owned : Owned\n" + - " OwnedᐸIServiceᐳ *-- Service : IService"; - } - private const string CannotResolveMessage = "Cannot resolve composition root "; private const string OfTypeMessage = "of type "; diff --git a/readme/tracking-disposable-instances-in-delegates.md b/readme/tracking-disposable-instances-in-delegates.md index f12fe4c62..8c8b7a50e 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 @@ -86,10 +86,10 @@ classDiagram class FuncᐸOwnedᐸIDependencyᐳᐳ class OwnedᐸIDependencyᐳ class IDependency { - <> + <> } class IService { - <> + <> } Service o-- "PerResolve" FuncᐸOwnedᐸIDependencyᐳᐳ : FuncᐸOwnedᐸIDependencyᐳᐳ Composition ..> Service : Service Root @@ -123,12 +123,12 @@ partial class Composition public Service Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { var perResolve39_Func = default(Func>); perResolve39_Func = new Func>( - [MethodImpl((MethodImplOptions)256)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] () => { var accumulator38 = new Owned(); @@ -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; @@ -214,41 +214,6 @@ partial class Composition throw new InvalidOperationException($"{CannotResolveMessage} \"{tag}\" {OfTypeMessage} {type}."); } - public override string ToString() - { - return - "classDiagram\n" + - " class Composition {\n" + - " +Service 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 Owned\n" + - " Dependency --|> IDependency : \n" + - " class Dependency {\n" + - " +Dependency()\n" + - " }\n" + - " Service --|> IService : \n" + - " class Service {\n" + - " +Service(FuncᐸOwnedᐸIDependencyᐳᐳ dependencyFactory)\n" + - " }\n" + - " class FuncᐸOwnedᐸIDependencyᐳᐳ\n" + - " class OwnedᐸIDependencyᐳ\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " Service o-- \"PerResolve\" FuncᐸOwnedᐸIDependencyᐳᐳ : FuncᐸOwnedᐸIDependencyᐳᐳ\n" + - " Composition ..> Service : Service Root\n" + - " FuncᐸOwnedᐸIDependencyᐳᐳ o-- \"PerBlock\" OwnedᐸIDependencyᐳ : OwnedᐸIDependencyᐳ\n" + - " OwnedᐸIDependencyᐳ *-- Owned : Owned\n" + - " OwnedᐸIDependencyᐳ *-- Dependency : IDependency"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -296,6 +261,7 @@ partial class Composition { case null: return composition.Root; + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/tracking-disposable-instances-per-a-composition-root.md b/readme/tracking-disposable-instances-per-a-composition-root.md index 2c8edcacb..4712e4793 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 @@ -80,10 +80,10 @@ classDiagram +Service(IDependency dependency) } class IDependency { - <> + <> } class IService { - <> + <> } Service *-- Dependency : IDependency Composition ..> OwnedᐸIServiceᐳ : OwnedᐸIServiceᐳ Root @@ -116,7 +116,7 @@ partial class Composition public Owned Root { - [MethodImpl((MethodImplOptions)0x100)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { var accumulator38 = new Owned(); @@ -139,62 +139,30 @@ 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}."); } - public override string ToString() - { - return - "classDiagram\n" + - " class Composition {\n" + - " +Ownedᐸ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 Owned\n" + - " Dependency --|> IDependency : \n" + - " class Dependency {\n" + - " +Dependency()\n" + - " }\n" + - " Service --|> IService : \n" + - " class Service {\n" + - " +Service(IDependency dependency)\n" + - " }\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " Service *-- Dependency : IDependency\n" + - " Composition ..> OwnedᐸIServiceᐳ : OwnedᐸIServiceᐳ Root\n" + - " OwnedᐸIServiceᐳ *-- Owned : Owned\n" + - " OwnedᐸIServiceᐳ *-- Service : IService"; - } - private const string CannotResolveMessage = "Cannot resolve composition root "; private const string OfTypeMessage = "of type "; diff --git a/readme/transient.md b/readme/transient.md index 5b22b7429..c5cc4fecf 100644 --- a/readme/transient.md +++ b/readme/transient.md @@ -58,10 +58,10 @@ classDiagram +Service(IDependency dependency1, IDependency dependency2) } class IDependency { - <> + <> } class IService { - <> + <> } Service *-- Dependency : IDependency Service *-- Dependency : IDependency @@ -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; @@ -157,36 +157,6 @@ partial class Composition 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" + - " class Dependency {\n" + - " +Dependency()\n" + - " }\n" + - " Service --|> IService : \n" + - " class Service {\n" + - " +Service(IDependency dependency1, IDependency dependency2)\n" + - " }\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " Service *-- Dependency : IDependency\n" + - " Service *-- Dependency : IDependency\n" + - " Composition ..> Service : IService Root"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -234,6 +204,7 @@ partial class Composition { case null: return composition.Root; + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/tuple.md b/readme/tuple.md index a9fff0ca0..96bae638e 100644 --- a/readme/tuple.md +++ b/readme/tuple.md @@ -58,10 +58,10 @@ classDiagram +Service(ValueTupleᐸPointˏIDependencyᐳ tuple) } class IDependency { - <> + <> } class IService { - <> + <> } ValueTupleᐸPointˏIDependencyᐳ *-- Point : Point ValueTupleᐸPointˏIDependencyᐳ *-- Dependency : IDependency @@ -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; @@ -159,41 +159,6 @@ partial class Composition 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 ValueTupleᐸPointˏIDependencyᐳ {\n" + - " +ValueTuple(Point item1, IDependency item2)\n" + - " }\n" + - " class Point\n" + - " Dependency --|> IDependency : \n" + - " class Dependency {\n" + - " +Dependency()\n" + - " }\n" + - " Service --|> IService : \n" + - " class Service {\n" + - " +Service(ValueTupleᐸPointˏIDependencyᐳ tuple)\n" + - " }\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " ValueTupleᐸPointˏIDependencyᐳ *-- Point : Point\n" + - " ValueTupleᐸPointˏIDependencyᐳ *-- Dependency : IDependency\n" + - " Service *-- ValueTupleᐸPointˏIDependencyᐳ : ValueTupleᐸPointˏIDependencyᐳ\n" + - " Composition ..> Service : IService Root"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -241,6 +206,7 @@ partial class Composition { case null: return composition.Root; + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/type-attribute.md b/readme/type-attribute.md index 74eb4633d..188a339c9 100644 --- a/readme/type-attribute.md +++ b/readme/type-attribute.md @@ -65,7 +65,7 @@ classDiagram +Service(IDependency dependency1, IDependency dependency2) } class IService { - <> + <> } Service *-- AbcDependency : AbcDependency Service *-- XyzDependency : XyzDependency @@ -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; @@ -161,35 +161,6 @@ partial class Composition 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 XyzDependency {\n" + - " +XyzDependency()\n" + - " }\n" + - " class AbcDependency {\n" + - " +AbcDependency()\n" + - " }\n" + - " Service --|> IService : \n" + - " class Service {\n" + - " +Service(IDependency dependency1, IDependency dependency2)\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " Service *-- AbcDependency : AbcDependency\n" + - " Service *-- XyzDependency : XyzDependency\n" + - " Composition ..> Service : IService Root"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -237,6 +208,7 @@ partial class Composition { case null: return composition.Root; + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/valuetask.md b/readme/valuetask.md index 2f272b9ad..4c4d3a1da 100644 --- a/readme/valuetask.md +++ b/readme/valuetask.md @@ -61,10 +61,10 @@ classDiagram } class ValueTaskᐸIDependencyᐳ class IDependency { - <> + <> } class IService { - <> + <> } Service *-- ValueTaskᐸIDependencyᐳ : ValueTaskᐸIDependencyᐳ Composition ..> Service : IService Root @@ -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; @@ -165,37 +165,6 @@ partial class Composition 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" + - " class Dependency {\n" + - " +Dependency()\n" + - " }\n" + - " Service --|> IService : \n" + - " class Service {\n" + - " +Service(ValueTaskᐸIDependencyᐳ dependencyTask)\n" + - " }\n" + - " class ValueTaskᐸIDependencyᐳ\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " Service *-- ValueTaskᐸIDependencyᐳ : ValueTaskᐸIDependencyᐳ\n" + - " Composition ..> Service : IService Root\n" + - " ValueTaskᐸIDependencyᐳ *-- Dependency : IDependency"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -243,6 +212,7 @@ partial class Composition { case null: return composition.Root; + default: return base.ResolveByTag(composition, tag); } diff --git a/readme/weak-reference.md b/readme/weak-reference.md index 44bf8165f..5484aebdc 100644 --- a/readme/weak-reference.md +++ b/readme/weak-reference.md @@ -52,10 +52,10 @@ classDiagram +Service(WeakReferenceᐸIDependencyᐳ dependency) } class IDependency { - <> + <> } class IService { - <> + <> } WeakReferenceᐸIDependencyᐳ *-- Dependency : IDependency Service *-- WeakReferenceᐸIDependencyᐳ : WeakReferenceᐸIDependencyᐳ @@ -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; @@ -151,39 +151,6 @@ partial class Composition 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 WeakReferenceᐸIDependencyᐳ {\n" + - " +WeakReference(IDependency target)\n" + - " }\n" + - " Dependency --|> IDependency : \n" + - " class Dependency {\n" + - " +Dependency()\n" + - " }\n" + - " Service --|> IService : \n" + - " class Service {\n" + - " +Service(WeakReferenceᐸIDependencyᐳ dependency)\n" + - " }\n" + - " class IDependency {\n" + - " <>\n" + - " }\n" + - " class IService {\n" + - " <>\n" + - " }\n" + - " WeakReferenceᐸIDependencyᐳ *-- Dependency : IDependency\n" + - " Service *-- WeakReferenceᐸIDependencyᐳ : WeakReferenceᐸIDependencyᐳ\n" + - " Composition ..> Service : IService Root"; - } - private readonly static int _bucketSize; private readonly static Pair>[] _buckets; @@ -231,6 +198,7 @@ partial class Composition { case null: return composition.Root; + default: return base.ResolveByTag(composition, tag); } 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/src/Pure.DI.Core/Core/Code/ClassBuilder.cs b/src/Pure.DI.Core/Core/Code/ClassBuilder.cs index 4e6901413..6bbbbe40c 100644 --- a/src/Pure.DI.Core/Core/Code/ClassBuilder.cs +++ b/src/Pure.DI.Core/Core/Code/ClassBuilder.cs @@ -2,37 +2,39 @@ namespace Pure.DI.Core.Code; internal sealed class ClassBuilder( - [Tag(typeof(UsingDeclarationsBuilder))] IBuilder usingDeclarationsBuilder, - [Tag(typeof(FieldsBuilder))] IBuilder fieldsBuilder, - [Tag(typeof(ArgFieldsBuilder))] IBuilder argFieldsBuilder, - [Tag(typeof(ParameterizedConstructorBuilder))] IBuilder parameterizedConstructorBuilder, - [Tag(typeof(DefaultConstructorBuilder))] IBuilder defaultConstructorBuilder, - [Tag(typeof(ScopeConstructorBuilder))] IBuilder scopeConstructorBuilder, - [Tag(typeof(RootMethodsBuilder))] IBuilder rootPropertiesBuilder, - [Tag(typeof(ApiMembersBuilder))] IBuilder apiMembersBuilder, - [Tag(typeof(DisposeMethodBuilder))] IBuilder disposeMethodBuilder, - [Tag(typeof(ToStringMethodBuilder))] IBuilder toStringBuilder, - [Tag(typeof(ResolversFieldsBuilder))] IBuilder resolversFieldsBuilder, - [Tag(typeof(StaticConstructorBuilder))] IBuilder staticConstructorBuilder, - [Tag(typeof(ResolverClassesBuilder))] IBuilder resolversClassesBuilder, + [Tag(typeof(UsingDeclarationsBuilder))] IBuilder usingDeclarations, + [Tag(typeof(FieldsBuilder))] IBuilder fields, + [Tag(typeof(ArgFieldsBuilder))] IBuilder argFields, + [Tag(typeof(ParameterizedConstructorBuilder))] IBuilder parameterizedConstructor, + [Tag(typeof(DefaultConstructorBuilder))] IBuilder defaultConstructor, + [Tag(typeof(ScopeConstructorBuilder))] IBuilder scopeConstructor, + [Tag(typeof(RootMethodsBuilder))] IBuilder rootProperties, + [Tag(typeof(ApiMembersBuilder))] IBuilder apiMembers, + [Tag(typeof(DisposeMethodBuilder))] IBuilder disposeMethod, + [Tag(typeof(ResolversFieldsBuilder))] IBuilder resolversFields, + [Tag(typeof(StaticConstructorBuilder))] IBuilder staticConstructor, + [Tag(typeof(ResolverClassesBuilder))] IBuilder resolversClasses, + [Tag(typeof(ToStringMethodBuilder))] IBuilder toString, [Tag(typeof(ClassCommenter))] ICommenter classCommenter, IInformation information, CancellationToken cancellationToken) : IBuilder { - private readonly ImmutableArray> _codeBuilders = ImmutableArray.Create( - fieldsBuilder, - argFieldsBuilder, - parameterizedConstructorBuilder, - defaultConstructorBuilder, - scopeConstructorBuilder, - rootPropertiesBuilder, - apiMembersBuilder, - disposeMethodBuilder, - toStringBuilder, - resolversFieldsBuilder, - staticConstructorBuilder, - resolversClassesBuilder); + private readonly IBuilder[] _codeBuilders = + [ + fields, + argFields, + parameterizedConstructor, + defaultConstructor, + scopeConstructor, + rootProperties, + apiMembers, + disposeMethod, + resolversFields, + staticConstructor, + resolversClasses, + toString + ]; public CompositionCode Build(CompositionCode composition) { @@ -45,7 +47,7 @@ public CompositionCode Build(CompositionCode composition) } code.AppendLine(); - composition = usingDeclarationsBuilder.Build(composition); + composition = usingDeclarations.Build(composition); var nsIndent = Disposables.Empty; var name = composition.Source.Source.Name; diff --git a/src/Pure.DI.Core/Core/Code/ClassDiagramBuilder.cs b/src/Pure.DI.Core/Core/Code/ClassDiagramBuilder.cs index 51735d5b6..ac676bcf7 100644 --- a/src/Pure.DI.Core/Core/Code/ClassDiagramBuilder.cs +++ b/src/Pure.DI.Core/Core/Code/ClassDiagramBuilder.cs @@ -100,9 +100,16 @@ public LinesBuilder Build(CompositionCode composition) } else { - if (type.IsAbstract) + if (type.TypeKind == TypeKind.Interface) { - typeKind = "abstract"; + typeKind = "interface"; + } + else + { + if (type.IsAbstract) + { + typeKind = "abstract"; + } } } } diff --git a/src/Pure.DI.Core/Core/Code/ResolverClassesBuilder.cs b/src/Pure.DI.Core/Core/Code/ResolverClassesBuilder.cs index 92ab7dc7a..074832e13 100644 --- a/src/Pure.DI.Core/Core/Code/ResolverClassesBuilder.cs +++ b/src/Pure.DI.Core/Core/Code/ResolverClassesBuilder.cs @@ -133,6 +133,7 @@ private static void ImplementInterface(CompositionCode composition, ResolverInfo foreach (var taggedRoot in taggedRoots.Where(i => !CanBeUsedInSwitch(i))) { code.AppendLine($"if (Equals(tag, {taggedRoot.Injection.Tag.ValueToString()})) return {GetRoot(composition, taggedRoot)};"); + code.AppendLine(); } code.AppendLine("switch (tag)"); @@ -146,6 +147,8 @@ private static void ImplementInterface(CompositionCode composition, ResolverInfo { code.AppendLine($"return {GetRoot(composition, taggedRoot)};"); } + + code.AppendLine(); } code.AppendLine("default:"); 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();