diff --git a/readme/ArrayDetails.md b/readme/ArrayDetails.md index 053a3c022..4ca383c44 100644 --- a/readme/ArrayDetails.md +++ b/readme/ArrayDetails.md @@ -5,79 +5,79 @@ Creating an object graph of 27 transient objects, including 4 transient array ob ### Class diagram ```mermaid classDiagram - class Array { - +CompositionRoot TestPureDIByCR() - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - class CompositionRoot { - +CompositionRoot(IService1 service1, IService2 service21, IService2 service22, IService2 service23, IService3 service3, IService4 service41, IService4 service42) - } - Service1 --|> IService1 : - class Service1 { - +Service1(IService2 service2) - } - Service2Array --|> IService2 : - class Service2Array { - +Service2Array(ArrayᐸIService3ᐳ services) - } - Service3 --|> IService3 : - class Service3 { - +Service3(IService4 service41, IService4 service42) - } - Service3v2 --|> IService3 : 2 - class Service3v2 { - +Service3v2(IService4 service41, IService4 service42) - } - Service3v3 --|> IService3 : 3 - class Service3v3 { - +Service3v3(IService4 service41, IService4 service42) - } - Service3v4 --|> IService3 : 4 - class Service3v4 { - +Service3v4(IService4 service41, IService4 service42) - } - Service4 --|> IService4 : - class Service4 { - +Service4() - } - class ArrayᐸIService3ᐳ - class IService1 { - <> - } - class IService2 { - <> - } - class IService3 { - <> - } - class IService4 { - <> - } - CompositionRoot *-- Service1 : IService1 - CompositionRoot *-- Service2Array : IService2 - CompositionRoot *-- Service2Array : IService2 - CompositionRoot *-- Service2Array : IService2 - CompositionRoot *-- Service3 : IService3 - CompositionRoot *-- Service4 : IService4 - CompositionRoot *-- Service4 : IService4 - Service1 *-- Service2Array : IService2 - Service2Array *-- ArrayᐸIService3ᐳ : ArrayᐸIService3ᐳ - Service3 *-- Service4 : IService4 - Service3 *-- Service4 : IService4 - Service3v2 *-- Service4 : IService4 - Service3v2 *-- Service4 : IService4 - Service3v3 *-- Service4 : IService4 - Service3v3 *-- Service4 : IService4 - Service3v4 *-- Service4 : IService4 - Service3v4 *-- Service4 : IService4 - Array ..> CompositionRoot : CompositionRoot TestPureDIByCR() - ArrayᐸIService3ᐳ *-- Service3 : IService3 - ArrayᐸIService3ᐳ *-- Service3v2 : 2 IService3 - ArrayᐸIService3ᐳ *-- Service3v3 : 3 IService3 - ArrayᐸIService3ᐳ *-- Service3v4 : 4 IService3 + class Array { + +CompositionRoot TestPureDIByCR() + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + class CompositionRoot { + +CompositionRoot(IService1 service1, IService2 service21, IService2 service22, IService2 service23, IService3 service3, IService4 service41, IService4 service42) + } + Service1 --|> IService1 : + class Service1 { + +Service1(IService2 service2) + } + Service2Array --|> IService2 : + class Service2Array { + +Service2Array(ArrayᐸIService3ᐳ services) + } + Service3 --|> IService3 : + class Service3 { + +Service3(IService4 service41, IService4 service42) + } + Service3v2 --|> IService3 : 2 + class Service3v2 { + +Service3v2(IService4 service41, IService4 service42) + } + Service3v3 --|> IService3 : 3 + class Service3v3 { + +Service3v3(IService4 service41, IService4 service42) + } + Service3v4 --|> IService3 : 4 + class Service3v4 { + +Service3v4(IService4 service41, IService4 service42) + } + Service4 --|> IService4 : + class Service4 { + +Service4() + } + class ArrayᐸIService3ᐳ + class IService1 { + <> + } + class IService2 { + <> + } + class IService3 { + <> + } + class IService4 { + <> + } + CompositionRoot *-- Service1 : IService1 + CompositionRoot *-- Service2Array : IService2 + CompositionRoot *-- Service2Array : IService2 + CompositionRoot *-- Service2Array : IService2 + CompositionRoot *-- Service3 : IService3 + CompositionRoot *-- Service4 : IService4 + CompositionRoot *-- Service4 : IService4 + Service1 *-- Service2Array : IService2 + Service2Array *-- ArrayᐸIService3ᐳ : ArrayᐸIService3ᐳ + Service3 *-- Service4 : IService4 + Service3 *-- Service4 : IService4 + Service3v2 *-- Service4 : IService4 + Service3v2 *-- Service4 : IService4 + Service3v3 *-- Service4 : IService4 + Service3v3 *-- Service4 : IService4 + Service3v4 *-- Service4 : IService4 + Service3v4 *-- Service4 : IService4 + Array ..> CompositionRoot : CompositionRoot TestPureDIByCR() + ArrayᐸIService3ᐳ *-- Service3 : IService3 + ArrayᐸIService3ᐳ *-- Service3v2 : 2 IService3 + ArrayᐸIService3ᐳ *-- Service3v3 : 3 IService3 + ArrayᐸIService3ᐳ *-- Service3v4 : 4 IService3 ``` ### Generated code @@ -86,215 +86,215 @@ classDiagram Pure.DI-generated partial class Array
```c# -partial class Array +artial class Array + { +private readonly Array _rootM04D27di; + +public Array() { - private readonly Array _rootM04D27di; - - public Array() - { - _rootM04D27di = this; - } - - internal Array(Array baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public partial Pure.DI.Benchmarks.Model.CompositionRoot TestPureDIByCR() - { - return new Pure.DI.Benchmarks.Model.CompositionRoot(new Pure.DI.Benchmarks.Model.Service1(new Pure.DI.Benchmarks.Model.Service2Array(new Pure.DI.Benchmarks.Model.IService3[4] { new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3v2(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3v3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3v4(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()) })), new Pure.DI.Benchmarks.Model.Service2Array(new Pure.DI.Benchmarks.Model.IService3[4] { new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3v2(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3v3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3v4(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()) }), new Pure.DI.Benchmarks.Model.Service2Array(new Pure.DI.Benchmarks.Model.IService3[4] { new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3v2(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3v3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3v4(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()) }), new Pure.DI.Benchmarks.Model.Service2Array(new Pure.DI.Benchmarks.Model.IService3[4] { new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3v2(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3v3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3v4(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()) }), new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Array() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.Benchmarks.Model.CompositionRoot), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Array composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Array composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.Benchmarks.Model.CompositionRoot Resolve(Array composition) - { - return composition.TestPureDIByCR(); - } - - public Pure.DI.Benchmarks.Model.CompositionRoot ResolveByTag(Array composition, object tag) - { - switch (tag) - { - case null: - return composition.TestPureDIByCR(); - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.Benchmarks.Model.CompositionRoot."); - } - } - } + _rootM04D27di = this; } + +internal Array(Array baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public partial Pure.DI.Benchmarks.Model.CompositionRoot TestPureDIByCR() +{ + return new Pure.DI.Benchmarks.Model.CompositionRoot(new Pure.DI.Benchmarks.Model.Service1(new Pure.DI.Benchmarks.Model.Service2Array(new Pure.DI.Benchmarks.Model.IService3[4] { new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3v2(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3v3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3v4(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()) })), new Pure.DI.Benchmarks.Model.Service2Array(new Pure.DI.Benchmarks.Model.IService3[4] { new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3v2(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3v3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3v4(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()) }), new Pure.DI.Benchmarks.Model.Service2Array(new Pure.DI.Benchmarks.Model.IService3[4] { new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3v2(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3v3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3v4(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()) }), new Pure.DI.Benchmarks.Model.Service2Array(new Pure.DI.Benchmarks.Model.IService3[4] { new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3v2(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3v3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3v4(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()) }), new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Array() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.Benchmarks.Model.CompositionRoot), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Array composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Array composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.Benchmarks.Model.CompositionRoot Resolve(Array composition) + { + return composition.TestPureDIByCR(); + } + + public Pure.DI.Benchmarks.Model.CompositionRoot ResolveByTag(Array composition, object tag) + { + switch (tag) + { + case null: + return composition.TestPureDIByCR(); + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.Benchmarks.Model.CompositionRoot."); + } + } +} + } ```
diff --git a/readme/Avalonia.md b/readme/Avalonia.md index abb2035a4..68b6ea81d 100644 --- a/readme/Avalonia.md +++ b/readme/Avalonia.md @@ -107,7 +107,7 @@ The [project file](/samples/AvaloniaApp/AvaloniaApp.csproj) looks like this: - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/readme/BlazorServerApp.md b/readme/BlazorServerApp.md index f98f33cc1..bfedde85c 100644 --- a/readme/BlazorServerApp.md +++ b/readme/BlazorServerApp.md @@ -68,7 +68,7 @@ The [project file](/samples/BlazorServerApp/BlazorServerApp.csproj) looks like t - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/readme/BlazorWebAssemblyApp.md b/readme/BlazorWebAssemblyApp.md index a6ca479f0..46a4efe72 100644 --- a/readme/BlazorWebAssemblyApp.md +++ b/readme/BlazorWebAssemblyApp.md @@ -67,7 +67,7 @@ The [project file](/samples/BlazorWebAssemblyApp/BlazorWebAssemblyApp.csproj) lo - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/readme/Console.md b/readme/Console.md index 3dc5b13ab..ab054df8b 100644 --- a/readme/Console.md +++ b/readme/Console.md @@ -90,7 +90,7 @@ The [project file](/samples/ShroedingersCat/ShroedingersCat.csproj) looks like t - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/readme/ConsoleNativeAOT.md b/readme/ConsoleNativeAOT.md index f459c2e7e..1a9580f13 100644 --- a/readme/ConsoleNativeAOT.md +++ b/readme/ConsoleNativeAOT.md @@ -16,7 +16,7 @@ The [project file](/samples/ShroedingersCatNativeAOT/ShroedingersCatNativeAOT.cs - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/readme/ConsoleTopLevelStatements.md b/readme/ConsoleTopLevelStatements.md index ddde0b45f..54daff943 100644 --- a/readme/ConsoleTopLevelStatements.md +++ b/readme/ConsoleTopLevelStatements.md @@ -78,7 +78,7 @@ The [project file](/samples/ShroedingersCatTopLevelStatements/ShroedingersCatTop - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/readme/EnumDetails.md b/readme/EnumDetails.md index a90363770..68dc3f1c4 100644 --- a/readme/EnumDetails.md +++ b/readme/EnumDetails.md @@ -5,79 +5,79 @@ Creating an object graph of 12 transient objects, including 1 transient enumerab ### Class diagram ```mermaid classDiagram - class Enum { - +CompositionRoot TestPureDIByCR() - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - class CompositionRoot { - +CompositionRoot(IService1 service1, IService2 service21, IService2 service22, IService2 service23, IService3 service3, IService4 service41, IService4 service42) - } - Service1 --|> IService1 : - class Service1 { - +Service1(IService2 service2) - } - Service2Enum --|> IService2 : - class Service2Enum { - +Service2Enum(IEnumerableᐸIService3ᐳ services) - } - Service3 --|> IService3 : - class Service3 { - +Service3(IService4 service41, IService4 service42) - } - Service3v2 --|> IService3 : 2 - class Service3v2 { - +Service3v2(IService4 service41, IService4 service42) - } - Service3v3 --|> IService3 : 3 - class Service3v3 { - +Service3v3(IService4 service41, IService4 service42) - } - Service3v4 --|> IService3 : 4 - class Service3v4 { - +Service3v4(IService4 service41, IService4 service42) - } - Service4 --|> IService4 : - class Service4 { - +Service4() - } - class IEnumerableᐸIService3ᐳ - class IService1 { - <> - } - class IService2 { - <> - } - class IService3 { - <> - } - class IService4 { - <> - } - CompositionRoot *-- Service1 : IService1 - CompositionRoot *-- Service2Enum : IService2 - CompositionRoot *-- Service2Enum : IService2 - CompositionRoot *-- Service2Enum : IService2 - CompositionRoot *-- Service3 : IService3 - CompositionRoot *-- Service4 : IService4 - CompositionRoot *-- Service4 : IService4 - Service1 *-- Service2Enum : IService2 - Service2Enum o-- "PerBlock" IEnumerableᐸIService3ᐳ : IEnumerableᐸIService3ᐳ - Service3 *-- Service4 : IService4 - Service3 *-- Service4 : IService4 - Service3v2 *-- Service4 : IService4 - Service3v2 *-- Service4 : IService4 - Service3v3 *-- Service4 : IService4 - Service3v3 *-- Service4 : IService4 - Service3v4 *-- Service4 : IService4 - Service3v4 *-- Service4 : IService4 - Enum ..> CompositionRoot : CompositionRoot TestPureDIByCR() - IEnumerableᐸIService3ᐳ *-- Service3 : IService3 - IEnumerableᐸIService3ᐳ *-- Service3v2 : 2 IService3 - IEnumerableᐸIService3ᐳ *-- Service3v3 : 3 IService3 - IEnumerableᐸIService3ᐳ *-- Service3v4 : 4 IService3 + class Enum { + +CompositionRoot TestPureDIByCR() + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + class CompositionRoot { + +CompositionRoot(IService1 service1, IService2 service21, IService2 service22, IService2 service23, IService3 service3, IService4 service41, IService4 service42) + } + Service1 --|> IService1 : + class Service1 { + +Service1(IService2 service2) + } + Service2Enum --|> IService2 : + class Service2Enum { + +Service2Enum(IEnumerableᐸIService3ᐳ services) + } + Service3 --|> IService3 : + class Service3 { + +Service3(IService4 service41, IService4 service42) + } + Service3v2 --|> IService3 : 2 + class Service3v2 { + +Service3v2(IService4 service41, IService4 service42) + } + Service3v3 --|> IService3 : 3 + class Service3v3 { + +Service3v3(IService4 service41, IService4 service42) + } + Service3v4 --|> IService3 : 4 + class Service3v4 { + +Service3v4(IService4 service41, IService4 service42) + } + Service4 --|> IService4 : + class Service4 { + +Service4() + } + class IEnumerableᐸIService3ᐳ + class IService1 { + <> + } + class IService2 { + <> + } + class IService3 { + <> + } + class IService4 { + <> + } + CompositionRoot *-- Service1 : IService1 + CompositionRoot *-- Service2Enum : IService2 + CompositionRoot *-- Service2Enum : IService2 + CompositionRoot *-- Service2Enum : IService2 + CompositionRoot *-- Service3 : IService3 + CompositionRoot *-- Service4 : IService4 + CompositionRoot *-- Service4 : IService4 + Service1 *-- Service2Enum : IService2 + Service2Enum o-- "PerBlock" IEnumerableᐸIService3ᐳ : IEnumerableᐸIService3ᐳ + Service3 *-- Service4 : IService4 + Service3 *-- Service4 : IService4 + Service3v2 *-- Service4 : IService4 + Service3v2 *-- Service4 : IService4 + Service3v3 *-- Service4 : IService4 + Service3v3 *-- Service4 : IService4 + Service3v4 *-- Service4 : IService4 + Service3v4 *-- Service4 : IService4 + Enum ..> CompositionRoot : CompositionRoot TestPureDIByCR() + IEnumerableᐸIService3ᐳ *-- Service3 : IService3 + IEnumerableᐸIService3ᐳ *-- Service3v2 : 2 IService3 + IEnumerableᐸIService3ᐳ *-- Service3v3 : 3 IService3 + IEnumerableᐸIService3ᐳ *-- Service3v4 : 4 IService3 ``` ### Generated code @@ -86,224 +86,224 @@ classDiagram Pure.DI-generated partial class Enum
```c# -partial class Enum +artial class Enum + { +private readonly Enum _rootM04D27di; + +public Enum() { - private readonly Enum _rootM04D27di; - - public Enum() - { - _rootM04D27di = this; - } - - internal Enum(Enum baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public partial Pure.DI.Benchmarks.Model.CompositionRoot TestPureDIByCR() - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x200)] - System.Collections.Generic.IEnumerable LocalperBlockM04D27di10_IEnumerable() - { - yield return new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()); - yield return new Pure.DI.Benchmarks.Model.Service3v2(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()); - yield return new Pure.DI.Benchmarks.Model.Service3v3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()); - yield return new Pure.DI.Benchmarks.Model.Service3v4(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()); - } - System.Collections.Generic.IEnumerable perBlockM04D27di10_IEnumerable = LocalperBlockM04D27di10_IEnumerable(); - return new Pure.DI.Benchmarks.Model.CompositionRoot(new Pure.DI.Benchmarks.Model.Service1(new Pure.DI.Benchmarks.Model.Service2Enum(perBlockM04D27di10_IEnumerable)), new Pure.DI.Benchmarks.Model.Service2Enum(perBlockM04D27di10_IEnumerable), new Pure.DI.Benchmarks.Model.Service2Enum(perBlockM04D27di10_IEnumerable), new Pure.DI.Benchmarks.Model.Service2Enum(perBlockM04D27di10_IEnumerable), new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Enum() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.Benchmarks.Model.CompositionRoot), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Enum composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Enum composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.Benchmarks.Model.CompositionRoot Resolve(Enum composition) - { - return composition.TestPureDIByCR(); - } - - public Pure.DI.Benchmarks.Model.CompositionRoot ResolveByTag(Enum composition, object tag) - { - switch (tag) - { - case null: - return composition.TestPureDIByCR(); - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.Benchmarks.Model.CompositionRoot."); - } - } - } + _rootM04D27di = this; } + +internal Enum(Enum baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public partial Pure.DI.Benchmarks.Model.CompositionRoot TestPureDIByCR() +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x200)] + System.Collections.Generic.IEnumerable LocalperBlockM04D27di10_IEnumerable() + { + yield return new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()); + yield return new Pure.DI.Benchmarks.Model.Service3v2(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()); + yield return new Pure.DI.Benchmarks.Model.Service3v3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()); + yield return new Pure.DI.Benchmarks.Model.Service3v4(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()); + } + System.Collections.Generic.IEnumerable perBlockM04D27di10_IEnumerable = LocalperBlockM04D27di10_IEnumerable(); + return new Pure.DI.Benchmarks.Model.CompositionRoot(new Pure.DI.Benchmarks.Model.Service1(new Pure.DI.Benchmarks.Model.Service2Enum(perBlockM04D27di10_IEnumerable)), new Pure.DI.Benchmarks.Model.Service2Enum(perBlockM04D27di10_IEnumerable), new Pure.DI.Benchmarks.Model.Service2Enum(perBlockM04D27di10_IEnumerable), new Pure.DI.Benchmarks.Model.Service2Enum(perBlockM04D27di10_IEnumerable), new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Enum() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.Benchmarks.Model.CompositionRoot), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Enum composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Enum composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.Benchmarks.Model.CompositionRoot Resolve(Enum composition) + { + return composition.TestPureDIByCR(); + } + + public Pure.DI.Benchmarks.Model.CompositionRoot ResolveByTag(Enum composition, object tag) + { + switch (tag) + { + case null: + return composition.TestPureDIByCR(); + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.Benchmarks.Model.CompositionRoot."); + } + } +} + } ```
diff --git a/readme/FuncDetails.md b/readme/FuncDetails.md index 799f048a8..0fdec6c7c 100644 --- a/readme/FuncDetails.md +++ b/readme/FuncDetails.md @@ -5,58 +5,58 @@ Creating an object graph of 7 transition objects plus 1 `Func` with additiona ### Class diagram ```mermaid classDiagram - class Func { - +CompositionRoot TestPureDIByCR() - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - class CompositionRoot { - +CompositionRoot(IService1 service1, IService2 service21, IService2 service22, IService2 service23, IService3 service3, IService4 service41, IService4 service42) - } - Service1 --|> IService1 : - class Service1 { - +Service1(IService2 service2) - } - Service2Func --|> IService2 : - class Service2Func { - +Service2Func(FuncᐸIService3ᐳ service3Factory) - } - Service3 --|> IService3 : - class Service3 { - +Service3(IService4 service41, IService4 service42) - } - Service4 --|> IService4 : - class Service4 { - +Service4() - } - class FuncᐸIService3ᐳ - class IService1 { - <> - } - class IService2 { - <> - } - class IService3 { - <> - } - class IService4 { - <> - } - CompositionRoot *-- Service1 : IService1 - CompositionRoot *-- Service2Func : IService2 - CompositionRoot *-- Service2Func : IService2 - CompositionRoot *-- Service2Func : IService2 - CompositionRoot *-- Service3 : IService3 - CompositionRoot *-- Service4 : IService4 - CompositionRoot *-- Service4 : IService4 - Service1 *-- Service2Func : IService2 - Service2Func o-- "PerBlock" FuncᐸIService3ᐳ : FuncᐸIService3ᐳ - Service3 *-- Service4 : IService4 - Service3 *-- Service4 : IService4 - Func ..> CompositionRoot : CompositionRoot TestPureDIByCR() - FuncᐸIService3ᐳ *-- Service3 : IService3 + class Func { + +CompositionRoot TestPureDIByCR() + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + class CompositionRoot { + +CompositionRoot(IService1 service1, IService2 service21, IService2 service22, IService2 service23, IService3 service3, IService4 service41, IService4 service42) + } + Service1 --|> IService1 : + class Service1 { + +Service1(IService2 service2) + } + Service2Func --|> IService2 : + class Service2Func { + +Service2Func(FuncᐸIService3ᐳ service3Factory) + } + Service3 --|> IService3 : + class Service3 { + +Service3(IService4 service41, IService4 service42) + } + Service4 --|> IService4 : + class Service4 { + +Service4() + } + class FuncᐸIService3ᐳ + class IService1 { + <> + } + class IService2 { + <> + } + class IService3 { + <> + } + class IService4 { + <> + } + CompositionRoot *-- Service1 : IService1 + CompositionRoot *-- Service2Func : IService2 + CompositionRoot *-- Service2Func : IService2 + CompositionRoot *-- Service2Func : IService2 + CompositionRoot *-- Service3 : IService3 + CompositionRoot *-- Service4 : IService4 + CompositionRoot *-- Service4 : IService4 + Service1 *-- Service2Func : IService2 + Service2Func o-- "PerBlock" FuncᐸIService3ᐳ : FuncᐸIService3ᐳ + Service3 *-- Service4 : IService4 + Service3 *-- Service4 : IService4 + Func ..> CompositionRoot : CompositionRoot TestPureDIByCR() + FuncᐸIService3ᐳ *-- Service3 : IService3 ``` ### Generated code @@ -65,201 +65,201 @@ classDiagram Pure.DI-generated partial class Func
```c# -partial class Func +artial class Func + { +private readonly Func _rootM04D27di; + +public Func() { - private readonly Func _rootM04D27di; - - public Func() - { - _rootM04D27di = this; - } - - internal Func(Func baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public partial Pure.DI.Benchmarks.Model.CompositionRoot TestPureDIByCR() - { - System.Func perBlockM04D27di10_Func = new Func( - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)768)] - () => - { - var value_M04D27di1 = new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()); - return value_M04D27di1; - }); - return new Pure.DI.Benchmarks.Model.CompositionRoot(new Pure.DI.Benchmarks.Model.Service1(new Pure.DI.Benchmarks.Model.Service2Func(perBlockM04D27di10_Func)), new Pure.DI.Benchmarks.Model.Service2Func(perBlockM04D27di10_Func), new Pure.DI.Benchmarks.Model.Service2Func(perBlockM04D27di10_Func), new Pure.DI.Benchmarks.Model.Service2Func(perBlockM04D27di10_Func), new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Func() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.Benchmarks.Model.CompositionRoot), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Func composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Func composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.Benchmarks.Model.CompositionRoot Resolve(Func composition) - { - return composition.TestPureDIByCR(); - } - - public Pure.DI.Benchmarks.Model.CompositionRoot ResolveByTag(Func composition, object tag) - { - switch (tag) - { - case null: - return composition.TestPureDIByCR(); - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.Benchmarks.Model.CompositionRoot."); - } - } - } + _rootM04D27di = this; } + +internal Func(Func baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public partial Pure.DI.Benchmarks.Model.CompositionRoot TestPureDIByCR() +{ + System.Func perBlockM04D27di10_Func = new Func( + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)768)] + () => + { + var value_M04D27di1 = new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()); + return value_M04D27di1; + }); + return new Pure.DI.Benchmarks.Model.CompositionRoot(new Pure.DI.Benchmarks.Model.Service1(new Pure.DI.Benchmarks.Model.Service2Func(perBlockM04D27di10_Func)), new Pure.DI.Benchmarks.Model.Service2Func(perBlockM04D27di10_Func), new Pure.DI.Benchmarks.Model.Service2Func(perBlockM04D27di10_Func), new Pure.DI.Benchmarks.Model.Service2Func(perBlockM04D27di10_Func), new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Func() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.Benchmarks.Model.CompositionRoot), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Func composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Func composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.Benchmarks.Model.CompositionRoot Resolve(Func composition) + { + return composition.TestPureDIByCR(); + } + + public Pure.DI.Benchmarks.Model.CompositionRoot ResolveByTag(Func composition, object tag) + { + switch (tag) + { + case null: + return composition.TestPureDIByCR(); + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.Benchmarks.Model.CompositionRoot."); + } + } +} + } ```
diff --git a/readme/GrpcService.md b/readme/GrpcService.md index 3b382ef85..811b367ec 100644 --- a/readme/GrpcService.md +++ b/readme/GrpcService.md @@ -53,7 +53,7 @@ The [project file](/samples/GrpcService/GrpcService.csproj) looks like this: - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/readme/Maui.md b/readme/Maui.md index 0da773c45..e0807a807 100644 --- a/readme/Maui.md +++ b/readme/Maui.md @@ -208,7 +208,7 @@ The [project file](/samples/MAUIApp/MAUIApp.csproj) looks like this: - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/readme/MinimalWebAPI.md b/readme/MinimalWebAPI.md index 381a44f7f..e365c9027 100644 --- a/readme/MinimalWebAPI.md +++ b/readme/MinimalWebAPI.md @@ -76,7 +76,7 @@ The [project file](/samples/WebAPI/WebAPI.csproj) looks like this: - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/readme/SingletonDetails.md b/readme/SingletonDetails.md index b36af2640..3f3c2c4c8 100644 --- a/readme/SingletonDetails.md +++ b/readme/SingletonDetails.md @@ -5,60 +5,60 @@ Creating an object graph of 20 transition objects plus 1 singleton with an addit ### Class diagram ```mermaid classDiagram - class Singleton { - +CompositionRoot TestPureDIByCR() - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - class CompositionRoot { - +CompositionRoot(IService1 service1, IService2 service21, IService2 service22, IService2 service23, IService3 service3, IService4 service41, IService4 service42) - } - Service1 --|> IService1 : - class Service1 { - +Service1(IService2 service2) - } - Service2 --|> IService2 : - class Service2 { - +Service2(IService3 service31, IService3 service32, IService3 service33, IService3 service34, IService3 service35) - } - Service3 --|> IService3 : - class Service3 { - +Service3(IService4 service41, IService4 service42) - } - Service4 --|> IService4 : - class Service4 { - +Service4() - } - class IService1 { - <> - } - class IService2 { - <> - } - class IService3 { - <> - } - class IService4 { - <> - } - CompositionRoot o-- "Scoped" Service1 : IService1 - CompositionRoot *-- Service2 : IService2 - CompositionRoot *-- Service2 : IService2 - CompositionRoot *-- Service2 : IService2 - CompositionRoot *-- Service3 : IService3 - CompositionRoot o-- "Scoped" Service4 : IService4 - CompositionRoot o-- "Scoped" Service4 : IService4 - Service1 *-- Service2 : IService2 - Service2 *-- Service3 : IService3 - Service2 *-- Service3 : IService3 - Service2 *-- Service3 : IService3 - Service2 *-- Service3 : IService3 - Service2 *-- Service3 : IService3 - Service3 o-- "Scoped" Service4 : IService4 - Service3 o-- "Scoped" Service4 : IService4 - Singleton ..> CompositionRoot : CompositionRoot TestPureDIByCR() + class Singleton { + +CompositionRoot TestPureDIByCR() + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + class CompositionRoot { + +CompositionRoot(IService1 service1, IService2 service21, IService2 service22, IService2 service23, IService3 service3, IService4 service41, IService4 service42) + } + Service1 --|> IService1 : + class Service1 { + +Service1(IService2 service2) + } + Service2 --|> IService2 : + class Service2 { + +Service2(IService3 service31, IService3 service32, IService3 service33, IService3 service34, IService3 service35) + } + Service3 --|> IService3 : + class Service3 { + +Service3(IService4 service41, IService4 service42) + } + Service4 --|> IService4 : + class Service4 { + +Service4() + } + class IService1 { + <> + } + class IService2 { + <> + } + class IService3 { + <> + } + class IService4 { + <> + } + CompositionRoot o-- "Scoped" Service1 : IService1 + CompositionRoot *-- Service2 : IService2 + CompositionRoot *-- Service2 : IService2 + CompositionRoot *-- Service2 : IService2 + CompositionRoot *-- Service3 : IService3 + CompositionRoot o-- "Scoped" Service4 : IService4 + CompositionRoot o-- "Scoped" Service4 : IService4 + Service1 *-- Service2 : IService2 + Service2 *-- Service3 : IService3 + Service2 *-- Service3 : IService3 + Service2 *-- Service3 : IService3 + Service2 *-- Service3 : IService3 + Service2 *-- Service3 : IService3 + Service3 o-- "Scoped" Service4 : IService4 + Service3 o-- "Scoped" Service4 : IService4 + Singleton ..> CompositionRoot : CompositionRoot TestPureDIByCR() ``` ### Generated code @@ -67,206 +67,206 @@ classDiagram Pure.DI-generated partial class Singleton
```c# -partial class Singleton +artial class Singleton + { +private readonly Singleton _rootM04D27di; +private Pure.DI.Benchmarks.Model.Service1 _scopedM04D27di37_Service1; +private Pure.DI.Benchmarks.Model.Service4 _scopedM04D27di40_Service4; + +public Singleton() { - private readonly Singleton _rootM04D27di; - private Pure.DI.Benchmarks.Model.Service1 _scopedM04D27di37_Service1; - private Pure.DI.Benchmarks.Model.Service4 _scopedM04D27di40_Service4; - - public Singleton() - { - _rootM04D27di = this; - } - - internal Singleton(Singleton baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public partial Pure.DI.Benchmarks.Model.CompositionRoot TestPureDIByCR() - { - if (_scopedM04D27di40_Service4 == null) - { - _scopedM04D27di40_Service4 = new Pure.DI.Benchmarks.Model.Service4(); - } - if (_scopedM04D27di37_Service1 == null) - { - _scopedM04D27di37_Service1 = new Pure.DI.Benchmarks.Model.Service1(new Pure.DI.Benchmarks.Model.Service2(new Pure.DI.Benchmarks.Model.Service3(_scopedM04D27di40_Service4, _scopedM04D27di40_Service4), new Pure.DI.Benchmarks.Model.Service3(_scopedM04D27di40_Service4, _scopedM04D27di40_Service4), new Pure.DI.Benchmarks.Model.Service3(_scopedM04D27di40_Service4, _scopedM04D27di40_Service4), new Pure.DI.Benchmarks.Model.Service3(_scopedM04D27di40_Service4, _scopedM04D27di40_Service4), new Pure.DI.Benchmarks.Model.Service3(_scopedM04D27di40_Service4, _scopedM04D27di40_Service4))); - } - return new Pure.DI.Benchmarks.Model.CompositionRoot(_scopedM04D27di37_Service1, new Pure.DI.Benchmarks.Model.Service2(new Pure.DI.Benchmarks.Model.Service3(_scopedM04D27di40_Service4, _scopedM04D27di40_Service4), new Pure.DI.Benchmarks.Model.Service3(_scopedM04D27di40_Service4, _scopedM04D27di40_Service4), new Pure.DI.Benchmarks.Model.Service3(_scopedM04D27di40_Service4, _scopedM04D27di40_Service4), new Pure.DI.Benchmarks.Model.Service3(_scopedM04D27di40_Service4, _scopedM04D27di40_Service4), new Pure.DI.Benchmarks.Model.Service3(_scopedM04D27di40_Service4, _scopedM04D27di40_Service4)), new Pure.DI.Benchmarks.Model.Service2(new Pure.DI.Benchmarks.Model.Service3(_scopedM04D27di40_Service4, _scopedM04D27di40_Service4), new Pure.DI.Benchmarks.Model.Service3(_scopedM04D27di40_Service4, _scopedM04D27di40_Service4), new Pure.DI.Benchmarks.Model.Service3(_scopedM04D27di40_Service4, _scopedM04D27di40_Service4), new Pure.DI.Benchmarks.Model.Service3(_scopedM04D27di40_Service4, _scopedM04D27di40_Service4), new Pure.DI.Benchmarks.Model.Service3(_scopedM04D27di40_Service4, _scopedM04D27di40_Service4)), new Pure.DI.Benchmarks.Model.Service2(new Pure.DI.Benchmarks.Model.Service3(_scopedM04D27di40_Service4, _scopedM04D27di40_Service4), new Pure.DI.Benchmarks.Model.Service3(_scopedM04D27di40_Service4, _scopedM04D27di40_Service4), new Pure.DI.Benchmarks.Model.Service3(_scopedM04D27di40_Service4, _scopedM04D27di40_Service4), new Pure.DI.Benchmarks.Model.Service3(_scopedM04D27di40_Service4, _scopedM04D27di40_Service4), new Pure.DI.Benchmarks.Model.Service3(_scopedM04D27di40_Service4, _scopedM04D27di40_Service4)), new Pure.DI.Benchmarks.Model.Service3(_scopedM04D27di40_Service4, _scopedM04D27di40_Service4), _scopedM04D27di40_Service4, _scopedM04D27di40_Service4); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Singleton() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.Benchmarks.Model.CompositionRoot), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Singleton composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Singleton composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.Benchmarks.Model.CompositionRoot Resolve(Singleton composition) - { - return composition.TestPureDIByCR(); - } - - public Pure.DI.Benchmarks.Model.CompositionRoot ResolveByTag(Singleton composition, object tag) - { - switch (tag) - { - case null: - return composition.TestPureDIByCR(); - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.Benchmarks.Model.CompositionRoot."); - } - } - } + _rootM04D27di = this; } + +internal Singleton(Singleton baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public partial Pure.DI.Benchmarks.Model.CompositionRoot TestPureDIByCR() +{ + if (_scopedM04D27di40_Service4 == null) + { + _scopedM04D27di40_Service4 = new Pure.DI.Benchmarks.Model.Service4(); + } + if (_scopedM04D27di37_Service1 == null) + { + _scopedM04D27di37_Service1 = new Pure.DI.Benchmarks.Model.Service1(new Pure.DI.Benchmarks.Model.Service2(new Pure.DI.Benchmarks.Model.Service3(_scopedM04D27di40_Service4, _scopedM04D27di40_Service4), new Pure.DI.Benchmarks.Model.Service3(_scopedM04D27di40_Service4, _scopedM04D27di40_Service4), new Pure.DI.Benchmarks.Model.Service3(_scopedM04D27di40_Service4, _scopedM04D27di40_Service4), new Pure.DI.Benchmarks.Model.Service3(_scopedM04D27di40_Service4, _scopedM04D27di40_Service4), new Pure.DI.Benchmarks.Model.Service3(_scopedM04D27di40_Service4, _scopedM04D27di40_Service4))); + } + return new Pure.DI.Benchmarks.Model.CompositionRoot(_scopedM04D27di37_Service1, new Pure.DI.Benchmarks.Model.Service2(new Pure.DI.Benchmarks.Model.Service3(_scopedM04D27di40_Service4, _scopedM04D27di40_Service4), new Pure.DI.Benchmarks.Model.Service3(_scopedM04D27di40_Service4, _scopedM04D27di40_Service4), new Pure.DI.Benchmarks.Model.Service3(_scopedM04D27di40_Service4, _scopedM04D27di40_Service4), new Pure.DI.Benchmarks.Model.Service3(_scopedM04D27di40_Service4, _scopedM04D27di40_Service4), new Pure.DI.Benchmarks.Model.Service3(_scopedM04D27di40_Service4, _scopedM04D27di40_Service4)), new Pure.DI.Benchmarks.Model.Service2(new Pure.DI.Benchmarks.Model.Service3(_scopedM04D27di40_Service4, _scopedM04D27di40_Service4), new Pure.DI.Benchmarks.Model.Service3(_scopedM04D27di40_Service4, _scopedM04D27di40_Service4), new Pure.DI.Benchmarks.Model.Service3(_scopedM04D27di40_Service4, _scopedM04D27di40_Service4), new Pure.DI.Benchmarks.Model.Service3(_scopedM04D27di40_Service4, _scopedM04D27di40_Service4), new Pure.DI.Benchmarks.Model.Service3(_scopedM04D27di40_Service4, _scopedM04D27di40_Service4)), new Pure.DI.Benchmarks.Model.Service2(new Pure.DI.Benchmarks.Model.Service3(_scopedM04D27di40_Service4, _scopedM04D27di40_Service4), new Pure.DI.Benchmarks.Model.Service3(_scopedM04D27di40_Service4, _scopedM04D27di40_Service4), new Pure.DI.Benchmarks.Model.Service3(_scopedM04D27di40_Service4, _scopedM04D27di40_Service4), new Pure.DI.Benchmarks.Model.Service3(_scopedM04D27di40_Service4, _scopedM04D27di40_Service4), new Pure.DI.Benchmarks.Model.Service3(_scopedM04D27di40_Service4, _scopedM04D27di40_Service4)), new Pure.DI.Benchmarks.Model.Service3(_scopedM04D27di40_Service4, _scopedM04D27di40_Service4), _scopedM04D27di40_Service4, _scopedM04D27di40_Service4); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Singleton() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.Benchmarks.Model.CompositionRoot), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Singleton composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Singleton composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.Benchmarks.Model.CompositionRoot Resolve(Singleton composition) + { + return composition.TestPureDIByCR(); + } + + public Pure.DI.Benchmarks.Model.CompositionRoot ResolveByTag(Singleton composition, object tag) + { + switch (tag) + { + case null: + return composition.TestPureDIByCR(); + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.Benchmarks.Model.CompositionRoot."); + } + } +} + } ```
diff --git a/readme/TransientDetails.md b/readme/TransientDetails.md index 727f8d8d9..86181f16e 100644 --- a/readme/TransientDetails.md +++ b/readme/TransientDetails.md @@ -5,60 +5,60 @@ Creating an object graph of 22 transient objects. ### Class diagram ```mermaid classDiagram - class Transient { - +CompositionRoot TestPureDIByCR() - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - class CompositionRoot { - +CompositionRoot(IService1 service1, IService2 service21, IService2 service22, IService2 service23, IService3 service3, IService4 service41, IService4 service42) - } - Service1 --|> IService1 : - class Service1 { - +Service1(IService2 service2) - } - Service2 --|> IService2 : - class Service2 { - +Service2(IService3 service31, IService3 service32, IService3 service33, IService3 service34, IService3 service35) - } - Service3 --|> IService3 : - class Service3 { - +Service3(IService4 service41, IService4 service42) - } - Service4 --|> IService4 : - class Service4 { - +Service4() - } - class IService1 { - <> - } - class IService2 { - <> - } - class IService3 { - <> - } - class IService4 { - <> - } - CompositionRoot *-- Service1 : IService1 - CompositionRoot *-- Service2 : IService2 - CompositionRoot *-- Service2 : IService2 - CompositionRoot *-- Service2 : IService2 - CompositionRoot *-- Service3 : IService3 - CompositionRoot *-- Service4 : IService4 - CompositionRoot *-- Service4 : IService4 - Service1 *-- Service2 : IService2 - Service2 *-- Service3 : IService3 - Service2 *-- Service3 : IService3 - Service2 *-- Service3 : IService3 - Service2 *-- Service3 : IService3 - Service2 *-- Service3 : IService3 - Service3 *-- Service4 : IService4 - Service3 *-- Service4 : IService4 - Transient ..> CompositionRoot : CompositionRoot TestPureDIByCR() + class Transient { + +CompositionRoot TestPureDIByCR() + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + class CompositionRoot { + +CompositionRoot(IService1 service1, IService2 service21, IService2 service22, IService2 service23, IService3 service3, IService4 service41, IService4 service42) + } + Service1 --|> IService1 : + class Service1 { + +Service1(IService2 service2) + } + Service2 --|> IService2 : + class Service2 { + +Service2(IService3 service31, IService3 service32, IService3 service33, IService3 service34, IService3 service35) + } + Service3 --|> IService3 : + class Service3 { + +Service3(IService4 service41, IService4 service42) + } + Service4 --|> IService4 : + class Service4 { + +Service4() + } + class IService1 { + <> + } + class IService2 { + <> + } + class IService3 { + <> + } + class IService4 { + <> + } + CompositionRoot *-- Service1 : IService1 + CompositionRoot *-- Service2 : IService2 + CompositionRoot *-- Service2 : IService2 + CompositionRoot *-- Service2 : IService2 + CompositionRoot *-- Service3 : IService3 + CompositionRoot *-- Service4 : IService4 + CompositionRoot *-- Service4 : IService4 + Service1 *-- Service2 : IService2 + Service2 *-- Service3 : IService3 + Service2 *-- Service3 : IService3 + Service2 *-- Service3 : IService3 + Service2 *-- Service3 : IService3 + Service2 *-- Service3 : IService3 + Service3 *-- Service4 : IService4 + Service3 *-- Service4 : IService4 + Transient ..> CompositionRoot : CompositionRoot TestPureDIByCR() ``` ### Generated code @@ -67,196 +67,196 @@ classDiagram Pure.DI-generated partial class Transient
```c# -partial class Transient +artial class Transient + { +private readonly Transient _rootM04D27di; + +public Transient() { - private readonly Transient _rootM04D27di; - - public Transient() - { - _rootM04D27di = this; - } - - internal Transient(Transient baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public partial Pure.DI.Benchmarks.Model.CompositionRoot TestPureDIByCR() - { - return new Pure.DI.Benchmarks.Model.CompositionRoot(new Pure.DI.Benchmarks.Model.Service1(new Pure.DI.Benchmarks.Model.Service2(new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()))), new Pure.DI.Benchmarks.Model.Service2(new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4())), new Pure.DI.Benchmarks.Model.Service2(new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4())), new Pure.DI.Benchmarks.Model.Service2(new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4())), new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Transient() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.Benchmarks.Model.CompositionRoot), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Transient composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Transient composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.Benchmarks.Model.CompositionRoot Resolve(Transient composition) - { - return composition.TestPureDIByCR(); - } - - public Pure.DI.Benchmarks.Model.CompositionRoot ResolveByTag(Transient composition, object tag) - { - switch (tag) - { - case null: - return composition.TestPureDIByCR(); - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.Benchmarks.Model.CompositionRoot."); - } - } - } + _rootM04D27di = this; } + +internal Transient(Transient baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public partial Pure.DI.Benchmarks.Model.CompositionRoot TestPureDIByCR() +{ + return new Pure.DI.Benchmarks.Model.CompositionRoot(new Pure.DI.Benchmarks.Model.Service1(new Pure.DI.Benchmarks.Model.Service2(new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()))), new Pure.DI.Benchmarks.Model.Service2(new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4())), new Pure.DI.Benchmarks.Model.Service2(new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4())), new Pure.DI.Benchmarks.Model.Service2(new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4())), new Pure.DI.Benchmarks.Model.Service3(new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()), new Pure.DI.Benchmarks.Model.Service4(), new Pure.DI.Benchmarks.Model.Service4()); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Transient() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.Benchmarks.Model.CompositionRoot), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Transient composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Transient composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.Benchmarks.Model.CompositionRoot Resolve(Transient composition) + { + return composition.TestPureDIByCR(); + } + + public Pure.DI.Benchmarks.Model.CompositionRoot ResolveByTag(Transient composition, object tag) + { + switch (tag) + { + case null: + return composition.TestPureDIByCR(); + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.Benchmarks.Model.CompositionRoot."); + } + } +} + } ```
diff --git a/readme/WebAPI.md b/readme/WebAPI.md index 2fde07d3e..8de186216 100644 --- a/readme/WebAPI.md +++ b/readme/WebAPI.md @@ -51,7 +51,7 @@ The [project file](/samples/WebAPI/WebAPI.csproj) looks like this: - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/readme/WebApp.md b/readme/WebApp.md index c336bc42b..76e69136b 100644 --- a/readme/WebApp.md +++ b/readme/WebApp.md @@ -51,7 +51,7 @@ The [project file](/samples/WebApp/WebApp.csproj) looks like this: - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/readme/WinFormsApp.md b/readme/WinFormsApp.md index dd88ff3e0..158eef74c 100644 --- a/readme/WinFormsApp.md +++ b/readme/WinFormsApp.md @@ -55,7 +55,7 @@ The [project file](/samples/WinFormsApp/WinFormsApp.csproj) looks like this: - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/readme/WinFormsAppNetCore.md b/readme/WinFormsAppNetCore.md index 5ca84a2ce..6ccd23465 100644 --- a/readme/WinFormsAppNetCore.md +++ b/readme/WinFormsAppNetCore.md @@ -62,7 +62,7 @@ The [project file](/samples/WinFormsAppNetCore/WinFormsAppNetCore.csproj) looks - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/readme/Wpf.md b/readme/Wpf.md index ef76a2277..2ba640e25 100644 --- a/readme/Wpf.md +++ b/readme/Wpf.md @@ -68,7 +68,7 @@ The [project file](/samples/WpfAppNetCore/WpfAppNetCore.csproj) looks like this: - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/readme/a-few-partial-classes.md b/readme/a-few-partial-classes.md index a0b58fafa..e5161fa14 100644 --- a/readme/a-few-partial-classes.md +++ b/readme/a-few-partial-classes.md @@ -46,29 +46,29 @@ var service = composition.Root; ```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 : - class Dependency { - +Dependency() - } - Service --|> IService : - class Service { - +Service(IDependency dependency) - } - class IDependency { - <> - } - class IService { - <> - } - Service *-- Dependency : IDependency - Composition ..> Service : IService Root + class Composition { + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + Dependency --|> IDependency : + class Dependency { + +Dependency() + } + Service --|> IService : + class Service { + +Service(IDependency dependency) + } + class IDependency { + <> + } + class IService { + <> + } + Service *-- Dependency : IDependency + Composition ..> Service : IService Root ``` @@ -77,168 +77,168 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; + +public Composition() +{ + _rootM04D27di = this; +} + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; +} + +public Pure.DI.UsageTests.Advanced.SeveralPartialClassesScenario.IService Root +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + return new Pure.DI.UsageTests.Advanced.SeveralPartialClassesScenario.Service(new Pure.DI.UsageTests.Advanced.SeveralPartialClassesScenario.Dependency()); + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Advanced.SeveralPartialClassesScenario.IService), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver { - private readonly Composition _rootM04D27di; - - public Composition() - { - _rootM04D27di = this; - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - } - - public Pure.DI.UsageTests.Advanced.SeveralPartialClassesScenario.IService Root - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - return new Pure.DI.UsageTests.Advanced.SeveralPartialClassesScenario.Service(new Pure.DI.UsageTests.Advanced.SeveralPartialClassesScenario.Dependency()); - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Advanced.SeveralPartialClassesScenario.IService), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Advanced.SeveralPartialClassesScenario.IService Resolve(Composition composition) - { - return composition.Root; - } - - public Pure.DI.UsageTests.Advanced.SeveralPartialClassesScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.Root; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Advanced.SeveralPartialClassesScenario.IService."); - } - } - } + public Pure.DI.UsageTests.Advanced.SeveralPartialClassesScenario.IService Resolve(Composition composition) + { + return composition.Root; + } + + public Pure.DI.UsageTests.Advanced.SeveralPartialClassesScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.Root; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Advanced.SeveralPartialClassesScenario.IService."); + } + } } + } ```
diff --git a/readme/accumulators.md b/readme/accumulators.md index 78142ec7b..c1ebb2be3 100644 --- a/readme/accumulators.md +++ b/readme/accumulators.md @@ -45,41 +45,41 @@ accumulator[2].ShouldBeOfType(); ```mermaid classDiagram - class Composition { - +ValueTupleᐸIServiceˏMyAccumulatorᐳ Root - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - class MyAccumulator - class ValueTupleᐸIServiceˏMyAccumulatorᐳ { - +ValueTuple(IService item1, MyAccumulator item2) - } - AbcDependency --|> IDependency : - class AbcDependency { - +AbcDependency() - } - XyzDependency --|> IDependency : typeof(Pure.DI.UsageTests.Advanced.AccumulatorScenario.XyzDependency) - class XyzDependency { - +XyzDependency() - } - Service --|> IService : - class Service { - +Service(IDependency dependency1, IDependency dependency2, IDependency dependency3) - } - class IDependency { - <> - } - class IService { - <> - } - ValueTupleᐸIServiceˏMyAccumulatorᐳ *-- Service : IService - ValueTupleᐸIServiceˏMyAccumulatorᐳ *-- MyAccumulator : MyAccumulator - Service *-- AbcDependency : typeof(Pure.DI.UsageTests.Advanced.AccumulatorScenario.AbcDependency) IDependency - Service o-- "Singleton" XyzDependency : typeof(Pure.DI.UsageTests.Advanced.AccumulatorScenario.XyzDependency) IDependency - Service o-- "PerBlock" AbcDependency : IDependency - Composition ..> ValueTupleᐸIServiceˏMyAccumulatorᐳ : ValueTupleᐸIServiceˏMyAccumulatorᐳ Root + class Composition { + +ValueTupleᐸIServiceˏMyAccumulatorᐳ Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + class MyAccumulator + class ValueTupleᐸIServiceˏMyAccumulatorᐳ { + +ValueTuple(IService item1, MyAccumulator item2) + } + AbcDependency --|> IDependency : + class AbcDependency { + +AbcDependency() + } + XyzDependency --|> IDependency : typeof(Pure.DI.UsageTests.Advanced.AccumulatorScenario.XyzDependency) + class XyzDependency { + +XyzDependency() + } + Service --|> IService : + class Service { + +Service(IDependency dependency1, IDependency dependency2, IDependency dependency3) + } + class IDependency { + <> + } + class IService { + <> + } + ValueTupleᐸIServiceˏMyAccumulatorᐳ *-- Service : IService + ValueTupleᐸIServiceˏMyAccumulatorᐳ *-- MyAccumulator : MyAccumulator + Service *-- AbcDependency : typeof(Pure.DI.UsageTests.Advanced.AccumulatorScenario.AbcDependency) IDependency + Service o-- "Singleton" XyzDependency : typeof(Pure.DI.UsageTests.Advanced.AccumulatorScenario.XyzDependency) IDependency + Service o-- "PerBlock" AbcDependency : IDependency + Composition ..> ValueTupleᐸIServiceˏMyAccumulatorᐳ : ValueTupleᐸIServiceˏMyAccumulatorᐳ Root ``` @@ -88,220 +88,220 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; +private readonly object _lockM04D27di; +private Pure.DI.UsageTests.Advanced.AccumulatorScenario.XyzDependency _singletonM04D27di38_XyzDependency; + +public Composition() { - private readonly Composition _rootM04D27di; - private readonly object _lockM04D27di; - private Pure.DI.UsageTests.Advanced.AccumulatorScenario.XyzDependency _singletonM04D27di38_XyzDependency; - - public Composition() - { - _rootM04D27di = this; - _lockM04D27di = new object(); - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - _lockM04D27di = _rootM04D27di._lockM04D27di; - } - - public (Pure.DI.UsageTests.Advanced.AccumulatorScenario.IService service, Pure.DI.UsageTests.Advanced.AccumulatorScenario.MyAccumulator accumulator) Root - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - var accumulatorM04D27di42 = new Pure.DI.UsageTests.Advanced.AccumulatorScenario.MyAccumulator(); - Pure.DI.UsageTests.Advanced.AccumulatorScenario.AbcDependency perBlockM04D27di4_AbcDependency = new Pure.DI.UsageTests.Advanced.AccumulatorScenario.AbcDependency(); - if (_rootM04D27di._singletonM04D27di38_XyzDependency == null) - { - lock (_lockM04D27di) - { - if (_rootM04D27di._singletonM04D27di38_XyzDependency == null) - { - Pure.DI.UsageTests.Advanced.AccumulatorScenario.XyzDependency _singletonM04D27di38_XyzDependencyTemp; - _singletonM04D27di38_XyzDependencyTemp = new Pure.DI.UsageTests.Advanced.AccumulatorScenario.XyzDependency(); - accumulatorM04D27di42.Add(_singletonM04D27di38_XyzDependencyTemp); - global::System.Threading.Thread.MemoryBarrier(); - _singletonM04D27di38_XyzDependency = _singletonM04D27di38_XyzDependencyTemp; - _rootM04D27di._singletonM04D27di38_XyzDependency = _singletonM04D27di38_XyzDependency; - } - } - } - Pure.DI.UsageTests.Advanced.AccumulatorScenario.AbcDependency transientM04D27di3_AbcDependency = new Pure.DI.UsageTests.Advanced.AccumulatorScenario.AbcDependency(); - lock (_lockM04D27di) - { - accumulatorM04D27di42.Add(transientM04D27di3_AbcDependency); - } - Pure.DI.UsageTests.Advanced.AccumulatorScenario.Service transientM04D27di1_Service = new Pure.DI.UsageTests.Advanced.AccumulatorScenario.Service(transientM04D27di3_AbcDependency, _rootM04D27di._singletonM04D27di38_XyzDependency, perBlockM04D27di4_AbcDependency); - lock (_lockM04D27di) - { - accumulatorM04D27di42.Add(transientM04D27di1_Service); - } - return (transientM04D27di1_Service, accumulatorM04D27di42); - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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(Pure.DI.UsageTests.Advanced.AccumulatorScenario.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(Pure.DI.UsageTests.Advanced.AccumulatorScenario.AbcDependency) IDependency\n" + - " Service o-- \"Singleton\" XyzDependency : typeof(Pure.DI.UsageTests.Advanced.AccumulatorScenario.XyzDependency) IDependency\n" + - " Service o-- \"PerBlock\" AbcDependency : IDependency\n" + - " Composition ..> ValueTupleᐸIServiceˏMyAccumulatorᐳ : ValueTupleᐸIServiceˏMyAccumulatorᐳ Root"; - } - - private readonly static int _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di<(Pure.DI.UsageTests.Advanced.AccumulatorScenario.IService service, Pure.DI.UsageTests.Advanced.AccumulatorScenario.MyAccumulator accumulator)>.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof((Pure.DI.UsageTests.Advanced.AccumulatorScenario.IService service, Pure.DI.UsageTests.Advanced.AccumulatorScenario.MyAccumulator accumulator)), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver, global::Pure.DI.IResolver - { - public (Pure.DI.UsageTests.Advanced.AccumulatorScenario.IService service, Pure.DI.UsageTests.Advanced.AccumulatorScenario.MyAccumulator accumulator) Resolve(Composition composition) - { - return composition.Root; - } - - public (Pure.DI.UsageTests.Advanced.AccumulatorScenario.IService service, Pure.DI.UsageTests.Advanced.AccumulatorScenario.MyAccumulator accumulator) ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.Root; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type (Pure.DI.UsageTests.Advanced.AccumulatorScenario.IService service, Pure.DI.UsageTests.Advanced.AccumulatorScenario.MyAccumulator accumulator)."); - } - } - object global::Pure.DI.IResolver.Resolve(Composition composition) - { - return Resolve(composition); - } - - object global::Pure.DI.IResolver.ResolveByTag(Composition composition, object tag) - { - return ResolveByTag(composition, tag); - } - } + _rootM04D27di = this; + _lockM04D27di = new object(); } + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; + _lockM04D27di = _rootM04D27di._lockM04D27di; +} + +public (Pure.DI.UsageTests.Advanced.AccumulatorScenario.IService service, Pure.DI.UsageTests.Advanced.AccumulatorScenario.MyAccumulator accumulator) Root +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + var accumulatorM04D27di42 = new Pure.DI.UsageTests.Advanced.AccumulatorScenario.MyAccumulator(); + Pure.DI.UsageTests.Advanced.AccumulatorScenario.AbcDependency perBlockM04D27di4_AbcDependency = new Pure.DI.UsageTests.Advanced.AccumulatorScenario.AbcDependency(); + if (_rootM04D27di._singletonM04D27di38_XyzDependency == null) + { + lock (_lockM04D27di) + { + if (_rootM04D27di._singletonM04D27di38_XyzDependency == null) + { + Pure.DI.UsageTests.Advanced.AccumulatorScenario.XyzDependency _singletonM04D27di38_XyzDependencyTemp; + _singletonM04D27di38_XyzDependencyTemp = new Pure.DI.UsageTests.Advanced.AccumulatorScenario.XyzDependency(); + accumulatorM04D27di42.Add(_singletonM04D27di38_XyzDependencyTemp); + global::System.Threading.Thread.MemoryBarrier(); + _singletonM04D27di38_XyzDependency = _singletonM04D27di38_XyzDependencyTemp; + _rootM04D27di._singletonM04D27di38_XyzDependency = _singletonM04D27di38_XyzDependency; + } + } + } + Pure.DI.UsageTests.Advanced.AccumulatorScenario.AbcDependency transientM04D27di3_AbcDependency = new Pure.DI.UsageTests.Advanced.AccumulatorScenario.AbcDependency(); + lock (_lockM04D27di) + { + accumulatorM04D27di42.Add(transientM04D27di3_AbcDependency); + } + Pure.DI.UsageTests.Advanced.AccumulatorScenario.Service transientM04D27di1_Service = new Pure.DI.UsageTests.Advanced.AccumulatorScenario.Service(transientM04D27di3_AbcDependency, _rootM04D27di._singletonM04D27di38_XyzDependency, perBlockM04D27di4_AbcDependency); + lock (_lockM04D27di) + { + accumulatorM04D27di42.Add(transientM04D27di1_Service); + } + return (transientM04D27di1_Service, accumulatorM04D27di42); + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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(Pure.DI.UsageTests.Advanced.AccumulatorScenario.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(Pure.DI.UsageTests.Advanced.AccumulatorScenario.AbcDependency) IDependency\n" + + " Service o-- \"Singleton\" XyzDependency : typeof(Pure.DI.UsageTests.Advanced.AccumulatorScenario.XyzDependency) IDependency\n" + + " Service o-- \"PerBlock\" AbcDependency : IDependency\n" + + " Composition ..> ValueTupleᐸIServiceˏMyAccumulatorᐳ : ValueTupleᐸIServiceˏMyAccumulatorᐳ Root"; +} + +private readonly static int _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di<(Pure.DI.UsageTests.Advanced.AccumulatorScenario.IService service, Pure.DI.UsageTests.Advanced.AccumulatorScenario.MyAccumulator accumulator)>.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof((Pure.DI.UsageTests.Advanced.AccumulatorScenario.IService service, Pure.DI.UsageTests.Advanced.AccumulatorScenario.MyAccumulator accumulator)), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver, global::Pure.DI.IResolver +{ + public (Pure.DI.UsageTests.Advanced.AccumulatorScenario.IService service, Pure.DI.UsageTests.Advanced.AccumulatorScenario.MyAccumulator accumulator) Resolve(Composition composition) + { + return composition.Root; + } + + public (Pure.DI.UsageTests.Advanced.AccumulatorScenario.IService service, Pure.DI.UsageTests.Advanced.AccumulatorScenario.MyAccumulator accumulator) ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.Root; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type (Pure.DI.UsageTests.Advanced.AccumulatorScenario.IService service, Pure.DI.UsageTests.Advanced.AccumulatorScenario.MyAccumulator accumulator)."); + } + } + object global::Pure.DI.IResolver.Resolve(Composition composition) + { + return Resolve(composition); + } + + object global::Pure.DI.IResolver.ResolveByTag(Composition composition, object tag) + { + return ResolveByTag(composition, tag); + } +} + } ```
diff --git a/readme/advanced-interception.md b/readme/advanced-interception.md index 3a719d039..f708adb66 100644 --- a/readme/advanced-interception.md +++ b/readme/advanced-interception.md @@ -114,29 +114,29 @@ log.ShouldBe( ```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 : - class Dependency { - +Dependency() - } - Service --|> IService : - class Service { - +Service(IDependency dependency) - } - class IDependency { - <> - } - class IService { - <> - } - Service *-- Dependency : IDependency - Composition ..> Service : IService Root + class Composition { + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + Dependency --|> IDependency : + class Dependency { + +Dependency() + } + Service --|> IService : + class Service { + +Service(IDependency dependency) + } + class IDependency { + <> + } + class IService { + <> + } + Service *-- Dependency : IDependency + Composition ..> Service : IService Root ``` @@ -145,170 +145,170 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; + +public Composition() { - private readonly Composition _rootM04D27di; - - public Composition() - { - _rootM04D27di = this; - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - } - - public Pure.DI.UsageTests.Interception.AdvancedInterceptionScenario.IService Root - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - return OnDependencyInjection(new Pure.DI.UsageTests.Interception.AdvancedInterceptionScenario.Service(OnDependencyInjection(new Pure.DI.UsageTests.Interception.AdvancedInterceptionScenario.Dependency(), null, Pure.DI.Lifetime.Transient)), null, Pure.DI.Lifetime.Transient); - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {type}."); - } - - private partial T OnDependencyInjection(in T value, object? tag, global::Pure.DI.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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Interception.AdvancedInterceptionScenario.IService), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Interception.AdvancedInterceptionScenario.IService Resolve(Composition composition) - { - return composition.Root; - } - - public Pure.DI.UsageTests.Interception.AdvancedInterceptionScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.Root; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Interception.AdvancedInterceptionScenario.IService."); - } - } - } + _rootM04D27di = this; +} + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; +} + +public Pure.DI.UsageTests.Interception.AdvancedInterceptionScenario.IService Root +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + return OnDependencyInjection(new Pure.DI.UsageTests.Interception.AdvancedInterceptionScenario.Service(OnDependencyInjection(new Pure.DI.UsageTests.Interception.AdvancedInterceptionScenario.Dependency(), null, Pure.DI.Lifetime.Transient)), null, Pure.DI.Lifetime.Transient); + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {type}."); +} + +private partial T OnDependencyInjection(in T value, object? tag, global::Pure.DI.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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Interception.AdvancedInterceptionScenario.IService), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.Interception.AdvancedInterceptionScenario.IService Resolve(Composition composition) + { + return composition.Root; + } + + public Pure.DI.UsageTests.Interception.AdvancedInterceptionScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.Root; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Interception.AdvancedInterceptionScenario.IService."); + } + } } + } ```
diff --git a/readme/arguments.md b/readme/arguments.md index 93eb0289f..7ed248384 100644 --- a/readme/arguments.md +++ b/readme/arguments.md @@ -59,33 +59,33 @@ service.Dependency.Id.ShouldBe(123); ```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 Int32 - class String - Dependency --|> IDependency : - class Dependency { - +Dependency(Int32 id) - } - Service --|> IService : - class Service { - +Service(String name, IDependency dependency) - } - class IDependency { - <> - } - class IService { - <> - } - Dependency o-- Int32 : Argument "id" - Service o-- String : "name" Argument "serviceName" - Service *-- Dependency : IDependency - Composition ..> Service : IService Root + class Composition { + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + class Int32 + class String + Dependency --|> IDependency : + class Dependency { + +Dependency(Int32 id) + } + Service --|> IService : + class Service { + +Service(String name, IDependency dependency) + } + class IDependency { + <> + } + class IService { + <> + } + Dependency o-- Int32 : Argument "id" + Service o-- String : "name" Argument "serviceName" + Service *-- Dependency : IDependency + Composition ..> Service : IService Root ``` @@ -94,184 +94,184 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; + +private readonly int _argM04D27di_id; +private readonly string _argM04D27di_serviceName; + +public Composition(int id, string serviceName) { - private readonly Composition _rootM04D27di; - - private readonly int _argM04D27di_id; - private readonly string _argM04D27di_serviceName; - - public Composition(int id, string serviceName) - { - _rootM04D27di = this; - if (ReferenceEquals(serviceName, null)) - { - throw new global::System.ArgumentNullException("serviceName"); - } - - _argM04D27di_id = id; - _argM04D27di_serviceName = serviceName; - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - _argM04D27di_id = baseComposition._argM04D27di_id; - _argM04D27di_serviceName = baseComposition._argM04D27di_serviceName; - } - - public Pure.DI.UsageTests.Basics.ArgumentsScenario.IService Root - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - return new Pure.DI.UsageTests.Basics.ArgumentsScenario.Service(_argM04D27di_serviceName, new Pure.DI.UsageTests.Basics.ArgumentsScenario.Dependency(_argM04D27di_id)); - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Basics.ArgumentsScenario.IService), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Basics.ArgumentsScenario.IService Resolve(Composition composition) - { - return composition.Root; - } - - public Pure.DI.UsageTests.Basics.ArgumentsScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.Root; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Basics.ArgumentsScenario.IService."); - } - } - } + _rootM04D27di = this; + if (ReferenceEquals(serviceName, null)) + { + throw new global::System.ArgumentNullException("serviceName"); + } + + _argM04D27di_id = id; + _argM04D27di_serviceName = serviceName; } + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; + _argM04D27di_id = baseComposition._argM04D27di_id; + _argM04D27di_serviceName = baseComposition._argM04D27di_serviceName; +} + +public Pure.DI.UsageTests.Basics.ArgumentsScenario.IService Root +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + return new Pure.DI.UsageTests.Basics.ArgumentsScenario.Service(_argM04D27di_serviceName, new Pure.DI.UsageTests.Basics.ArgumentsScenario.Dependency(_argM04D27di_id)); + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Basics.ArgumentsScenario.IService), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.Basics.ArgumentsScenario.IService Resolve(Composition composition) + { + return composition.Root; + } + + public Pure.DI.UsageTests.Basics.ArgumentsScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.Root; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Basics.ArgumentsScenario.IService."); + } + } +} + } ```
diff --git a/readme/array.md b/readme/array.md index 34d43a986..1a046617f 100644 --- a/readme/array.md +++ b/readme/array.md @@ -67,36 +67,36 @@ And of course this list can easily be supplemented on its own. ```mermaid classDiagram - class Composition { - +IService Root - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - AbcDependency --|> IDependency : - class AbcDependency { - +AbcDependency() - } - XyzDependency --|> IDependency : 2 - class XyzDependency { - +XyzDependency() - } - Service --|> IService : - class Service { - +Service(ArrayᐸIDependencyᐳ dependencies) - } - class ArrayᐸIDependencyᐳ - class IDependency { - <> - } - class IService { - <> - } - Service *-- ArrayᐸIDependencyᐳ : ArrayᐸIDependencyᐳ - Composition ..> Service : IService Root - ArrayᐸIDependencyᐳ *-- AbcDependency : IDependency - ArrayᐸIDependencyᐳ *-- XyzDependency : 2 IDependency + class Composition { + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + AbcDependency --|> IDependency : + class AbcDependency { + +AbcDependency() + } + XyzDependency --|> IDependency : 2 + class XyzDependency { + +XyzDependency() + } + Service --|> IService : + class Service { + +Service(ArrayᐸIDependencyᐳ dependencies) + } + class ArrayᐸIDependencyᐳ + class IDependency { + <> + } + class IService { + <> + } + Service *-- ArrayᐸIDependencyᐳ : ArrayᐸIDependencyᐳ + Composition ..> Service : IService Root + ArrayᐸIDependencyᐳ *-- AbcDependency : IDependency + ArrayᐸIDependencyᐳ *-- XyzDependency : 2 IDependency ``` @@ -105,175 +105,175 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; + +public Composition() { - private readonly Composition _rootM04D27di; - - public Composition() - { - _rootM04D27di = this; - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - } - - public Pure.DI.UsageTests.BCL.ArrayScenario.IService Root - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - return new Pure.DI.UsageTests.BCL.ArrayScenario.Service(new Pure.DI.UsageTests.BCL.ArrayScenario.IDependency[2] { new Pure.DI.UsageTests.BCL.ArrayScenario.AbcDependency(), new Pure.DI.UsageTests.BCL.ArrayScenario.XyzDependency() }); - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.BCL.ArrayScenario.IService), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.BCL.ArrayScenario.IService Resolve(Composition composition) - { - return composition.Root; - } - - public Pure.DI.UsageTests.BCL.ArrayScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.Root; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.BCL.ArrayScenario.IService."); - } - } - } + _rootM04D27di = this; } + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; +} + +public Pure.DI.UsageTests.BCL.ArrayScenario.IService Root +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + return new Pure.DI.UsageTests.BCL.ArrayScenario.Service(new Pure.DI.UsageTests.BCL.ArrayScenario.IDependency[2] { new Pure.DI.UsageTests.BCL.ArrayScenario.AbcDependency(), new Pure.DI.UsageTests.BCL.ArrayScenario.XyzDependency() }); + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.BCL.ArrayScenario.IService), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.BCL.ArrayScenario.IService Resolve(Composition composition) + { + return composition.Root; + } + + public Pure.DI.UsageTests.BCL.ArrayScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.Root; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.BCL.ArrayScenario.IService."); + } + } +} + } ```
diff --git a/readme/async-disposable-scope.md b/readme/async-disposable-scope.md index b3a96f2bc..c2d568b70 100644 --- a/readme/async-disposable-scope.md +++ b/readme/async-disposable-scope.md @@ -84,48 +84,48 @@ dependency2.IsDisposed.ShouldBeTrue(); ```mermaid classDiagram - class Composition { - +Program ProgramRoot - +IService SessionRoot - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - Composition --|> IDisposable - Composition --|> IAsyncDisposable - class Session { - +Session(Composition composition) - } - class Program { - +Program(FuncᐸSessionᐳ sessionFactory) - } - Dependency --|> IDependency : - Dependency --|> IAsyncDisposable : - class Dependency { - +Dependency() - } - Service --|> IService : - class Service { - +Service(IDependency dependency) - } - class Composition - class FuncᐸSessionᐳ - class IDependency { - <> - } - class IAsyncDisposable { - <> - } - class IService { - <> - } - Session *-- Composition : Composition - Program o-- "PerResolve" FuncᐸSessionᐳ : FuncᐸSessionᐳ - Service o-- "Scoped" Dependency : IDependency - Composition ..> Service : IService SessionRoot - Composition ..> Program : Program ProgramRoot - FuncᐸSessionᐳ *-- Session : Session + class Composition { + +Program ProgramRoot + +IService SessionRoot + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + Composition --|> IDisposable + Composition --|> IAsyncDisposable + class Session { + +Session(Composition composition) + } + class Program { + +Program(FuncᐸSessionᐳ sessionFactory) + } + Dependency --|> IDependency : + Dependency --|> IAsyncDisposable : + class Dependency { + +Dependency() + } + Service --|> IService : + class Service { + +Service(IDependency dependency) + } + class Composition + class FuncᐸSessionᐳ + class IDependency { + <> + } + class IAsyncDisposable { + <> + } + class IService { + <> + } + Session *-- Composition : Composition + Program o-- "PerResolve" FuncᐸSessionᐳ : FuncᐸSessionᐳ + Service o-- "Scoped" Dependency : IDependency + Composition ..> Service : IService SessionRoot + Composition ..> Program : Program ProgramRoot + FuncᐸSessionᐳ *-- Session : Session ``` @@ -134,316 +134,316 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition: global::System.IDisposable, global::System.IAsyncDisposable +artial class Composition: global::System.IDisposable, global::System.IAsyncDisposable + { +private readonly Composition _rootM04D27di; +private readonly object _lockM04D27di; +private object[] _disposablesM04D27di; +private int _disposeIndexM04D27di; +private Pure.DI.UsageTests.Lifetimes.AsyncDisposableScopeScenario.Dependency _scopedM04D27di36_Dependency; + +public Composition() { - private readonly Composition _rootM04D27di; - private readonly object _lockM04D27di; - private object[] _disposablesM04D27di; - private int _disposeIndexM04D27di; - private Pure.DI.UsageTests.Lifetimes.AsyncDisposableScopeScenario.Dependency _scopedM04D27di36_Dependency; - - public Composition() - { - _rootM04D27di = this; - _lockM04D27di = new object(); - _disposablesM04D27di = new object[1]; - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - _lockM04D27di = _rootM04D27di._lockM04D27di; - _disposablesM04D27di = new object[1]; - } - - public Pure.DI.UsageTests.Lifetimes.AsyncDisposableScopeScenario.IService SessionRoot - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - if (_scopedM04D27di36_Dependency == null) - { - lock (_lockM04D27di) - { - if (_scopedM04D27di36_Dependency == null) - { - _scopedM04D27di36_Dependency = new Pure.DI.UsageTests.Lifetimes.AsyncDisposableScopeScenario.Dependency(); - _disposablesM04D27di[_disposeIndexM04D27di++] = _scopedM04D27di36_Dependency; - } - } - } - return new Pure.DI.UsageTests.Lifetimes.AsyncDisposableScopeScenario.Service(_scopedM04D27di36_Dependency); - } - } - - public Pure.DI.UsageTests.Lifetimes.AsyncDisposableScopeScenario.Program ProgramRoot - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - var perResolveM04D27di43_Func = default(System.Func); - perResolveM04D27di43_Func = new global::System.Func( - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)768)] - () => - { - Pure.DI.UsageTests.Lifetimes.AsyncDisposableScopeScenario.Composition transientM04D27di2_Composition = this; - var value_M04D27di1 = new Pure.DI.UsageTests.Lifetimes.AsyncDisposableScopeScenario.Session(transientM04D27di2_Composition); - return value_M04D27di1; - }); - return new Pure.DI.UsageTests.Lifetimes.AsyncDisposableScopeScenario.Program(perResolveM04D27di43_Func); - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {type}."); - } - - public void Dispose() - { - int disposeIndex; - object[] disposables; - lock (_lockM04D27di) - { - disposeIndex = _disposeIndexM04D27di; - _disposeIndexM04D27di = 0; - disposables = _disposablesM04D27di; - _disposablesM04D27di = new object[1]; - _scopedM04D27di36_Dependency = null; - } - - while (disposeIndex-- > 0) - { - switch (disposables[disposeIndex]) - { - case global::System.IAsyncDisposable asyncDisposableInstance: - try - { - var valueTask = asyncDisposableInstance.DisposeAsync(); - if (!valueTask.IsCompleted) - { - valueTask.AsTask().Wait(); - } - } - catch (Exception exception) - { - OnDisposeAsyncException(asyncDisposableInstance, exception); - } - break; - } - } - } - - partial void OnDisposeException(T disposableInstance, Exception exception) where T : global::System.IDisposable; - - public async global::System.Threading.Tasks.ValueTask DisposeAsync() - { - int disposeIndex; - object[] disposables; - lock (_lockM04D27di) - { - disposeIndex = _disposeIndexM04D27di; - _disposeIndexM04D27di = 0; - disposables = _disposablesM04D27di; - _disposablesM04D27di = new object[1]; - _scopedM04D27di36_Dependency = null; - } - - while (disposeIndex-- > 0) - { - switch (disposables[disposeIndex]) - { - case global::System.IAsyncDisposable asyncDisposableInstance: - try - { - await asyncDisposableInstance.DisposeAsync(); - } - catch (Exception exception) - { - OnDisposeAsyncException(asyncDisposableInstance, exception); - } - break; - } - } - } - - partial void OnDisposeAsyncException(T asyncDisposableInstance, Exception exception) where T : global::System.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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - var valResolverM04D27di_0001 = new ResolverM04D27di_0001(); - ResolverM04D27di.Value = valResolverM04D27di_0001; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 4, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[2] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Lifetimes.AsyncDisposableScopeScenario.IService), valResolverM04D27di_0000) - ,new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Lifetimes.AsyncDisposableScopeScenario.Program), valResolverM04D27di_0001) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Lifetimes.AsyncDisposableScopeScenario.IService Resolve(Composition composition) - { - return composition.SessionRoot; - } - - public Pure.DI.UsageTests.Lifetimes.AsyncDisposableScopeScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.SessionRoot; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Lifetimes.AsyncDisposableScopeScenario.IService."); - } - } - } - - private sealed class ResolverM04D27di_0001: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Lifetimes.AsyncDisposableScopeScenario.Program Resolve(Composition composition) - { - return composition.ProgramRoot; - } - - public Pure.DI.UsageTests.Lifetimes.AsyncDisposableScopeScenario.Program ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.ProgramRoot; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Lifetimes.AsyncDisposableScopeScenario.Program."); - } - } - } + _rootM04D27di = this; + _lockM04D27di = new object(); + _disposablesM04D27di = new object[1]; +} + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; + _lockM04D27di = _rootM04D27di._lockM04D27di; + _disposablesM04D27di = new object[1]; +} + +public Pure.DI.UsageTests.Lifetimes.AsyncDisposableScopeScenario.IService SessionRoot +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + if (_scopedM04D27di36_Dependency == null) + { + lock (_lockM04D27di) + { + if (_scopedM04D27di36_Dependency == null) + { + _scopedM04D27di36_Dependency = new Pure.DI.UsageTests.Lifetimes.AsyncDisposableScopeScenario.Dependency(); + _disposablesM04D27di[_disposeIndexM04D27di++] = _scopedM04D27di36_Dependency; + } + } + } + return new Pure.DI.UsageTests.Lifetimes.AsyncDisposableScopeScenario.Service(_scopedM04D27di36_Dependency); + } +} + +public Pure.DI.UsageTests.Lifetimes.AsyncDisposableScopeScenario.Program ProgramRoot +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + var perResolveM04D27di43_Func = default(System.Func); + perResolveM04D27di43_Func = new global::System.Func( + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)768)] + () => + { + Pure.DI.UsageTests.Lifetimes.AsyncDisposableScopeScenario.Composition transientM04D27di2_Composition = this; + var value_M04D27di1 = new Pure.DI.UsageTests.Lifetimes.AsyncDisposableScopeScenario.Session(transientM04D27di2_Composition); + return value_M04D27di1; + }); + return new Pure.DI.UsageTests.Lifetimes.AsyncDisposableScopeScenario.Program(perResolveM04D27di43_Func); + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {type}."); +} + +public void Dispose() +{ + int disposeIndex; + object[] disposables; + lock (_lockM04D27di) + { + disposeIndex = _disposeIndexM04D27di; + _disposeIndexM04D27di = 0; + disposables = _disposablesM04D27di; + _disposablesM04D27di = new object[1]; + _scopedM04D27di36_Dependency = null; + } + + while (disposeIndex-- > 0) + { + switch (disposables[disposeIndex]) + { + case global::System.IAsyncDisposable asyncDisposableInstance: + try + { + var valueTask = asyncDisposableInstance.DisposeAsync(); + if (!valueTask.IsCompleted) + { + valueTask.AsTask().Wait(); + } + } + catch (Exception exception) + { + OnDisposeAsyncException(asyncDisposableInstance, exception); + } + break; + } + } +} + +partial void OnDisposeException(T disposableInstance, Exception exception) where T : global::System.IDisposable; + +public async global::System.Threading.Tasks.ValueTask DisposeAsync() +{ + int disposeIndex; + object[] disposables; + lock (_lockM04D27di) + { + disposeIndex = _disposeIndexM04D27di; + _disposeIndexM04D27di = 0; + disposables = _disposablesM04D27di; + _disposablesM04D27di = new object[1]; + _scopedM04D27di36_Dependency = null; + } + + while (disposeIndex-- > 0) + { + switch (disposables[disposeIndex]) + { + case global::System.IAsyncDisposable asyncDisposableInstance: + try + { + await asyncDisposableInstance.DisposeAsync(); + } + catch (Exception exception) + { + OnDisposeAsyncException(asyncDisposableInstance, exception); + } + break; + } + } +} + +partial void OnDisposeAsyncException(T asyncDisposableInstance, Exception exception) where T : global::System.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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + var valResolverM04D27di_0001 = new ResolverM04D27di_0001(); + ResolverM04D27di.Value = valResolverM04D27di_0001; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 4, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[2] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Lifetimes.AsyncDisposableScopeScenario.IService), valResolverM04D27di_0000) + ,new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Lifetimes.AsyncDisposableScopeScenario.Program), valResolverM04D27di_0001) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.Lifetimes.AsyncDisposableScopeScenario.IService Resolve(Composition composition) + { + return composition.SessionRoot; + } + + public Pure.DI.UsageTests.Lifetimes.AsyncDisposableScopeScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.SessionRoot; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Lifetimes.AsyncDisposableScopeScenario.IService."); + } + } +} + +private sealed class ResolverM04D27di_0001: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.Lifetimes.AsyncDisposableScopeScenario.Program Resolve(Composition composition) + { + return composition.ProgramRoot; + } + + public Pure.DI.UsageTests.Lifetimes.AsyncDisposableScopeScenario.Program ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.ProgramRoot; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Lifetimes.AsyncDisposableScopeScenario.Program."); + } + } } + } ```
diff --git a/readme/async-disposable-singleton.md b/readme/async-disposable-singleton.md index 781c7bce3..e87ae9c46 100644 --- a/readme/async-disposable-singleton.md +++ b/readme/async-disposable-singleton.md @@ -50,35 +50,35 @@ dependency.IsDisposed.ShouldBeTrue(); ```mermaid classDiagram - class Composition { - +IService Root - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - Composition --|> IDisposable - Composition --|> IAsyncDisposable - Dependency --|> IDependency : - Dependency --|> IAsyncDisposable : - class Dependency { - +Dependency() - } - Service --|> IService : - class Service { - +Service(IDependency dependency) - } - class IDependency { - <> - } - class IAsyncDisposable { - <> - } - class IService { - <> - } - Service o-- "Singleton" Dependency : IDependency - Composition ..> Service : IService Root + class Composition { + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + Composition --|> IDisposable + Composition --|> IAsyncDisposable + Dependency --|> IDependency : + Dependency --|> IAsyncDisposable : + class Dependency { + +Dependency() + } + Service --|> IService : + class Service { + +Service(IDependency dependency) + } + class IDependency { + <> + } + class IAsyncDisposable { + <> + } + class IService { + <> + } + Service o-- "Singleton" Dependency : IDependency + Composition ..> Service : IService Root ``` @@ -87,263 +87,263 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition: global::System.IDisposable, global::System.IAsyncDisposable +artial class Composition: global::System.IDisposable, global::System.IAsyncDisposable + { +private readonly Composition _rootM04D27di; +private readonly object _lockM04D27di; +private object[] _disposablesM04D27di; +private int _disposeIndexM04D27di; +private Pure.DI.UsageTests.Lifetimes.AsyncDisposableSingletonScenario.Dependency _singletonM04D27di36_Dependency; + +public Composition() { - private readonly Composition _rootM04D27di; - private readonly object _lockM04D27di; - private object[] _disposablesM04D27di; - private int _disposeIndexM04D27di; - private Pure.DI.UsageTests.Lifetimes.AsyncDisposableSingletonScenario.Dependency _singletonM04D27di36_Dependency; - - public Composition() - { - _rootM04D27di = this; - _lockM04D27di = new object(); - _disposablesM04D27di = new object[1]; - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - _lockM04D27di = _rootM04D27di._lockM04D27di; - } - - public Pure.DI.UsageTests.Lifetimes.AsyncDisposableSingletonScenario.IService Root - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - if (_rootM04D27di._singletonM04D27di36_Dependency == null) - { - lock (_lockM04D27di) - { - if (_rootM04D27di._singletonM04D27di36_Dependency == null) - { - _singletonM04D27di36_Dependency = new Pure.DI.UsageTests.Lifetimes.AsyncDisposableSingletonScenario.Dependency(); - _rootM04D27di._singletonM04D27di36_Dependency = _singletonM04D27di36_Dependency; - _rootM04D27di._disposablesM04D27di[_rootM04D27di._disposeIndexM04D27di++] = _singletonM04D27di36_Dependency; - } - } - } - return new Pure.DI.UsageTests.Lifetimes.AsyncDisposableSingletonScenario.Service(_rootM04D27di._singletonM04D27di36_Dependency); - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {type}."); - } - - public void Dispose() - { - int disposeIndex; - object[] disposables; - lock (_lockM04D27di) - { - disposeIndex = _disposeIndexM04D27di; - _disposeIndexM04D27di = 0; - disposables = _disposablesM04D27di; - _disposablesM04D27di = new object[1]; - _singletonM04D27di36_Dependency = null; - } - - while (disposeIndex-- > 0) - { - switch (disposables[disposeIndex]) - { - case global::System.IAsyncDisposable asyncDisposableInstance: - try - { - var valueTask = asyncDisposableInstance.DisposeAsync(); - if (!valueTask.IsCompleted) - { - valueTask.AsTask().Wait(); - } - } - catch (Exception exception) - { - OnDisposeAsyncException(asyncDisposableInstance, exception); - } - break; - } - } - } - - partial void OnDisposeException(T disposableInstance, Exception exception) where T : global::System.IDisposable; - - public async global::System.Threading.Tasks.ValueTask DisposeAsync() - { - int disposeIndex; - object[] disposables; - lock (_lockM04D27di) - { - disposeIndex = _disposeIndexM04D27di; - _disposeIndexM04D27di = 0; - disposables = _disposablesM04D27di; - _disposablesM04D27di = new object[1]; - _singletonM04D27di36_Dependency = null; - } - - while (disposeIndex-- > 0) - { - switch (disposables[disposeIndex]) - { - case global::System.IAsyncDisposable asyncDisposableInstance: - try - { - await asyncDisposableInstance.DisposeAsync(); - } - catch (Exception exception) - { - OnDisposeAsyncException(asyncDisposableInstance, exception); - } - break; - } - } - } - - partial void OnDisposeAsyncException(T asyncDisposableInstance, Exception exception) where T : global::System.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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Lifetimes.AsyncDisposableSingletonScenario.IService), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Lifetimes.AsyncDisposableSingletonScenario.IService Resolve(Composition composition) - { - return composition.Root; - } - - public Pure.DI.UsageTests.Lifetimes.AsyncDisposableSingletonScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.Root; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Lifetimes.AsyncDisposableSingletonScenario.IService."); - } - } - } + _rootM04D27di = this; + _lockM04D27di = new object(); + _disposablesM04D27di = new object[1]; +} + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; + _lockM04D27di = _rootM04D27di._lockM04D27di; +} + +public Pure.DI.UsageTests.Lifetimes.AsyncDisposableSingletonScenario.IService Root +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + if (_rootM04D27di._singletonM04D27di36_Dependency == null) + { + lock (_lockM04D27di) + { + if (_rootM04D27di._singletonM04D27di36_Dependency == null) + { + _singletonM04D27di36_Dependency = new Pure.DI.UsageTests.Lifetimes.AsyncDisposableSingletonScenario.Dependency(); + _rootM04D27di._singletonM04D27di36_Dependency = _singletonM04D27di36_Dependency; + _rootM04D27di._disposablesM04D27di[_rootM04D27di._disposeIndexM04D27di++] = _singletonM04D27di36_Dependency; + } + } + } + return new Pure.DI.UsageTests.Lifetimes.AsyncDisposableSingletonScenario.Service(_rootM04D27di._singletonM04D27di36_Dependency); + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {type}."); +} + +public void Dispose() +{ + int disposeIndex; + object[] disposables; + lock (_lockM04D27di) + { + disposeIndex = _disposeIndexM04D27di; + _disposeIndexM04D27di = 0; + disposables = _disposablesM04D27di; + _disposablesM04D27di = new object[1]; + _singletonM04D27di36_Dependency = null; + } + + while (disposeIndex-- > 0) + { + switch (disposables[disposeIndex]) + { + case global::System.IAsyncDisposable asyncDisposableInstance: + try + { + var valueTask = asyncDisposableInstance.DisposeAsync(); + if (!valueTask.IsCompleted) + { + valueTask.AsTask().Wait(); + } + } + catch (Exception exception) + { + OnDisposeAsyncException(asyncDisposableInstance, exception); + } + break; + } + } +} + +partial void OnDisposeException(T disposableInstance, Exception exception) where T : global::System.IDisposable; + +public async global::System.Threading.Tasks.ValueTask DisposeAsync() +{ + int disposeIndex; + object[] disposables; + lock (_lockM04D27di) + { + disposeIndex = _disposeIndexM04D27di; + _disposeIndexM04D27di = 0; + disposables = _disposablesM04D27di; + _disposablesM04D27di = new object[1]; + _singletonM04D27di36_Dependency = null; + } + + while (disposeIndex-- > 0) + { + switch (disposables[disposeIndex]) + { + case global::System.IAsyncDisposable asyncDisposableInstance: + try + { + await asyncDisposableInstance.DisposeAsync(); + } + catch (Exception exception) + { + OnDisposeAsyncException(asyncDisposableInstance, exception); + } + break; + } + } +} + +partial void OnDisposeAsyncException(T asyncDisposableInstance, Exception exception) where T : global::System.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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Lifetimes.AsyncDisposableSingletonScenario.IService), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.Lifetimes.AsyncDisposableSingletonScenario.IService Resolve(Composition composition) + { + return composition.Root; + } + + public Pure.DI.UsageTests.Lifetimes.AsyncDisposableSingletonScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.Root; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Lifetimes.AsyncDisposableSingletonScenario.IService."); + } + } } + } ```
diff --git a/readme/async-enumerable.md b/readme/async-enumerable.md index 1f91da7f0..9092b396d 100644 --- a/readme/async-enumerable.md +++ b/readme/async-enumerable.md @@ -50,36 +50,36 @@ dependencies[1].ShouldBeOfType(); ```mermaid classDiagram - class Composition { - +IService Root - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - AbcDependency --|> IDependency : - class AbcDependency { - +AbcDependency() - } - XyzDependency --|> IDependency : 2 - class XyzDependency { - +XyzDependency() - } - Service --|> IService : - class Service { - +Service(IAsyncEnumerableᐸIDependencyᐳ dependencies) - } - class IAsyncEnumerableᐸIDependencyᐳ - class IDependency { - <> - } - class IService { - <> - } - Service *-- IAsyncEnumerableᐸIDependencyᐳ : IAsyncEnumerableᐸIDependencyᐳ - Composition ..> Service : IService Root - IAsyncEnumerableᐸIDependencyᐳ *-- AbcDependency : IDependency - IAsyncEnumerableᐸIDependencyᐳ *-- XyzDependency : 2 IDependency + class Composition { + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + AbcDependency --|> IDependency : + class AbcDependency { + +AbcDependency() + } + XyzDependency --|> IDependency : 2 + class XyzDependency { + +XyzDependency() + } + Service --|> IService : + class Service { + +Service(IAsyncEnumerableᐸIDependencyᐳ dependencies) + } + class IAsyncEnumerableᐸIDependencyᐳ + class IDependency { + <> + } + class IService { + <> + } + Service *-- IAsyncEnumerableᐸIDependencyᐳ : IAsyncEnumerableᐸIDependencyᐳ + Composition ..> Service : IService Root + IAsyncEnumerableᐸIDependencyᐳ *-- AbcDependency : IDependency + IAsyncEnumerableᐸIDependencyᐳ *-- XyzDependency : 2 IDependency ``` @@ -88,182 +88,182 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; + +public Composition() { - private readonly Composition _rootM04D27di; - - public Composition() - { - _rootM04D27di = this; - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - } - - public Pure.DI.UsageTests.BCL.AsyncEnumerableScenario.IService Root - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x200)] - async System.Collections.Generic.IAsyncEnumerable LocaltransientM04D27di1_IAsyncEnumerable() - { - yield return new Pure.DI.UsageTests.BCL.AsyncEnumerableScenario.AbcDependency(); - yield return new Pure.DI.UsageTests.BCL.AsyncEnumerableScenario.XyzDependency(); - } - System.Collections.Generic.IAsyncEnumerable transientM04D27di1_IAsyncEnumerable = LocaltransientM04D27di1_IAsyncEnumerable(); - return new Pure.DI.UsageTests.BCL.AsyncEnumerableScenario.Service(transientM04D27di1_IAsyncEnumerable); - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.BCL.AsyncEnumerableScenario.IService), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.BCL.AsyncEnumerableScenario.IService Resolve(Composition composition) - { - return composition.Root; - } - - public Pure.DI.UsageTests.BCL.AsyncEnumerableScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.Root; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.BCL.AsyncEnumerableScenario.IService."); - } - } - } + _rootM04D27di = this; +} + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; +} + +public Pure.DI.UsageTests.BCL.AsyncEnumerableScenario.IService Root +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x200)] + async System.Collections.Generic.IAsyncEnumerable LocaltransientM04D27di1_IAsyncEnumerable() + { + yield return new Pure.DI.UsageTests.BCL.AsyncEnumerableScenario.AbcDependency(); + yield return new Pure.DI.UsageTests.BCL.AsyncEnumerableScenario.XyzDependency(); + } + System.Collections.Generic.IAsyncEnumerable transientM04D27di1_IAsyncEnumerable = LocaltransientM04D27di1_IAsyncEnumerable(); + return new Pure.DI.UsageTests.BCL.AsyncEnumerableScenario.Service(transientM04D27di1_IAsyncEnumerable); + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.BCL.AsyncEnumerableScenario.IService), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.BCL.AsyncEnumerableScenario.IService Resolve(Composition composition) + { + return composition.Root; + } + + public Pure.DI.UsageTests.BCL.AsyncEnumerableScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.Root; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.BCL.AsyncEnumerableScenario.IService."); + } + } } + } ```
diff --git a/readme/auto-bindings.md b/readme/auto-bindings.md index 51a763af4..5eca69af3 100644 --- a/readme/auto-bindings.md +++ b/readme/auto-bindings.md @@ -30,17 +30,17 @@ It is better to inject abstract dependencies, for example, in the form of interf ```mermaid classDiagram - class Composition { - +Service MyService - } - class Dependency { - +Dependency() - } - class Service { - +Service(Dependency dependency) - } - Service *-- Dependency : Dependency - Composition ..> Service : Service MyService + class Composition { + +Service MyService + } + class Dependency { + +Dependency() + } + class Service { + +Service(Dependency dependency) + } + Service *-- Dependency : Dependency + Composition ..> Service : Service MyService ``` @@ -49,47 +49,47 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; + +public Composition() { - private readonly Composition _rootM04D27di; - - public Composition() - { - _rootM04D27di = this; - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - } - - public Pure.DI.UsageTests.Basics.AutoBindingsScenario.Service MyService - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - return new Pure.DI.UsageTests.Basics.AutoBindingsScenario.Service(new Pure.DI.UsageTests.Basics.AutoBindingsScenario.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"; - } - + _rootM04D27di = this; } + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; +} + +public Pure.DI.UsageTests.Basics.AutoBindingsScenario.Service MyService +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + return new Pure.DI.UsageTests.Basics.AutoBindingsScenario.Service(new Pure.DI.UsageTests.Basics.AutoBindingsScenario.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 2e6d22003..2c1d5c004 100644 --- a/readme/auto-scoped.md +++ b/readme/auto-scoped.md @@ -66,36 +66,36 @@ service1.Dependency.ShouldNotBe(service2.Dependency); ```mermaid classDiagram - class Composition { - +Program ProgramRoot - +Service SessionRoot - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - class Program { - +Program(FuncᐸIServiceᐳ serviceFactory) - } - class Service { - +Service(IDependency dependency) - } - class IService - Dependency --|> IDependency : - class Dependency { - +Dependency() - } - class FuncᐸIServiceᐳ - class Composition - class IDependency { - <> - } - Program o-- "PerResolve" FuncᐸIServiceᐳ : FuncᐸIServiceᐳ - Service o-- "Scoped" Dependency : IDependency - IService *-- Composition : Composition - Composition ..> Service : Service SessionRoot - Composition ..> Program : Program ProgramRoot - FuncᐸIServiceᐳ *-- IService : IService + class Composition { + +Program ProgramRoot + +Service SessionRoot + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + class Program { + +Program(FuncᐸIServiceᐳ serviceFactory) + } + class Service { + +Service(IDependency dependency) + } + class IService + Dependency --|> IDependency : + class Dependency { + +Dependency() + } + class FuncᐸIServiceᐳ + class Composition + class IDependency { + <> + } + Program o-- "PerResolve" FuncᐸIServiceᐳ : FuncᐸIServiceᐳ + Service o-- "Scoped" Dependency : IDependency + IService *-- Composition : Composition + Composition ..> Service : Service SessionRoot + Composition ..> Program : Program ProgramRoot + FuncᐸIServiceᐳ *-- IService : IService ``` @@ -104,236 +104,236 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; +private readonly object _lockM04D27di; +private Pure.DI.UsageTests.Lifetimes.AutoScopedScenario.Dependency _scopedM04D27di36_Dependency; + +public Composition() +{ + _rootM04D27di = this; + _lockM04D27di = new object(); +} + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; + _lockM04D27di = _rootM04D27di._lockM04D27di; +} + +private Pure.DI.UsageTests.Lifetimes.AutoScopedScenario.Service SessionRoot +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + if (_scopedM04D27di36_Dependency == null) + { + lock (_lockM04D27di) + { + if (_scopedM04D27di36_Dependency == null) + { + _scopedM04D27di36_Dependency = new Pure.DI.UsageTests.Lifetimes.AutoScopedScenario.Dependency(); + } + } + } + return new Pure.DI.UsageTests.Lifetimes.AutoScopedScenario.Service(_scopedM04D27di36_Dependency); + } +} + +public Pure.DI.UsageTests.Lifetimes.AutoScopedScenario.Program ProgramRoot +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + var perResolveM04D27di43_Func = default(System.Func); + perResolveM04D27di43_Func = new global::System.Func( + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)768)] + () => + { + Pure.DI.UsageTests.Lifetimes.AutoScopedScenario.Composition transientM04D27di2_Composition = this; + Pure.DI.UsageTests.Lifetimes.AutoScopedScenario.IService transientM04D27di1_IService; + { + var baseComposition_M04D27di2 = transientM04D27di2_Composition; + // Creates a session + var session_M04D27di3 = new Composition(baseComposition_M04D27di2); + transientM04D27di1_IService = session_M04D27di3.SessionRoot; + } + var value_M04D27di1 = transientM04D27di1_IService; + return value_M04D27di1; + }); + return new Pure.DI.UsageTests.Lifetimes.AutoScopedScenario.Program(perResolveM04D27di43_Func); + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + var valResolverM04D27di_0001 = new ResolverM04D27di_0001(); + ResolverM04D27di.Value = valResolverM04D27di_0001; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 4, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[2] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Lifetimes.AutoScopedScenario.Service), valResolverM04D27di_0000) + ,new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Lifetimes.AutoScopedScenario.Program), valResolverM04D27di_0001) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.Lifetimes.AutoScopedScenario.Service Resolve(Composition composition) + { + return composition.SessionRoot; + } + + public Pure.DI.UsageTests.Lifetimes.AutoScopedScenario.Service ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.SessionRoot; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Lifetimes.AutoScopedScenario.Service."); + } + } +} + +private sealed class ResolverM04D27di_0001: global::Pure.DI.IResolver { - private readonly Composition _rootM04D27di; - private readonly object _lockM04D27di; - private Pure.DI.UsageTests.Lifetimes.AutoScopedScenario.Dependency _scopedM04D27di36_Dependency; - - public Composition() - { - _rootM04D27di = this; - _lockM04D27di = new object(); - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - _lockM04D27di = _rootM04D27di._lockM04D27di; - } - - private Pure.DI.UsageTests.Lifetimes.AutoScopedScenario.Service SessionRoot - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - if (_scopedM04D27di36_Dependency == null) - { - lock (_lockM04D27di) - { - if (_scopedM04D27di36_Dependency == null) - { - _scopedM04D27di36_Dependency = new Pure.DI.UsageTests.Lifetimes.AutoScopedScenario.Dependency(); - } - } - } - return new Pure.DI.UsageTests.Lifetimes.AutoScopedScenario.Service(_scopedM04D27di36_Dependency); - } - } - - public Pure.DI.UsageTests.Lifetimes.AutoScopedScenario.Program ProgramRoot - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - var perResolveM04D27di43_Func = default(System.Func); - perResolveM04D27di43_Func = new global::System.Func( - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)768)] - () => - { - Pure.DI.UsageTests.Lifetimes.AutoScopedScenario.Composition transientM04D27di2_Composition = this; - Pure.DI.UsageTests.Lifetimes.AutoScopedScenario.IService transientM04D27di1_IService; - { - var baseComposition_M04D27di2 = transientM04D27di2_Composition; - // Creates a session - var session_M04D27di3 = new Composition(baseComposition_M04D27di2); - transientM04D27di1_IService = session_M04D27di3.SessionRoot; - } - var value_M04D27di1 = transientM04D27di1_IService; - return value_M04D27di1; - }); - return new Pure.DI.UsageTests.Lifetimes.AutoScopedScenario.Program(perResolveM04D27di43_Func); - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - var valResolverM04D27di_0001 = new ResolverM04D27di_0001(); - ResolverM04D27di.Value = valResolverM04D27di_0001; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 4, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[2] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Lifetimes.AutoScopedScenario.Service), valResolverM04D27di_0000) - ,new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Lifetimes.AutoScopedScenario.Program), valResolverM04D27di_0001) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Lifetimes.AutoScopedScenario.Service Resolve(Composition composition) - { - return composition.SessionRoot; - } - - public Pure.DI.UsageTests.Lifetimes.AutoScopedScenario.Service ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.SessionRoot; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Lifetimes.AutoScopedScenario.Service."); - } - } - } - - private sealed class ResolverM04D27di_0001: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Lifetimes.AutoScopedScenario.Program Resolve(Composition composition) - { - return composition.ProgramRoot; - } - - public Pure.DI.UsageTests.Lifetimes.AutoScopedScenario.Program ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.ProgramRoot; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Lifetimes.AutoScopedScenario.Program."); - } - } - } + public Pure.DI.UsageTests.Lifetimes.AutoScopedScenario.Program Resolve(Composition composition) + { + return composition.ProgramRoot; + } + + public Pure.DI.UsageTests.Lifetimes.AutoScopedScenario.Program ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.ProgramRoot; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Lifetimes.AutoScopedScenario.Program."); + } + } } + } ```
diff --git a/readme/check-for-a-root.md b/readme/check-for-a-root.md index c6ef6d477..d48d5fd99 100644 --- a/readme/check-for-a-root.md +++ b/readme/check-for-a-root.md @@ -63,32 +63,32 @@ Composition.HasRoot(typeof(IComparable)).ShouldBeFalse(); ```mermaid classDiagram - class Composition { - +IService Root - -IDependency _ - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - Dependency --|> IDependency : "MyDep" - class Dependency { - +Dependency() - } - Service --|> IService : - class Service { - +Service() - +IDependency Dependency - } - class IDependency { - <> - } - class IService { - <> - } - Service *-- Dependency : "MyDep" IDependency - Composition ..> Dependency : IDependency _ - Composition ..> Service : IService Root + class Composition { + +IService Root + -IDependency _ + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + Dependency --|> IDependency : "MyDep" + class Dependency { + +Dependency() + } + Service --|> IService : + class Service { + +Service() + +IDependency Dependency + } + class IDependency { + <> + } + class IService { + <> + } + Service *-- Dependency : "MyDep" IDependency + Composition ..> Dependency : IDependency _ + Composition ..> Service : IService Root ``` @@ -97,209 +97,209 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; + +public Composition() +{ + _rootM04D27di = this; +} + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; +} + +public Pure.DI.UsageTests.Hints.CheckForRootScenario.IService Root +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + return new Pure.DI.UsageTests.Hints.CheckForRootScenario.Service() + { + Dependency = new Pure.DI.UsageTests.Hints.CheckForRootScenario.Dependency() + }; + } +} + +private Pure.DI.UsageTests.Hints.CheckForRootScenario.IDependency RootM04D27di0001 +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + return new Pure.DI.UsageTests.Hints.CheckForRootScenario.Dependency(); + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +private static partial void OnNewRoot(global::Pure.DI.IResolver resolver, string name, object? tag, global::Pure.DI.Lifetime lifetime); + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + OnNewRoot(valResolverM04D27di_0000, "Root", null, Pure.DI.Lifetime.Transient); + ResolverM04D27di.Value = valResolverM04D27di_0000; + var valResolverM04D27di_0001 = new ResolverM04D27di_0001(); + OnNewRoot(valResolverM04D27di_0001, "RootM04D27di0001", "MyDep", Pure.DI.Lifetime.Transient); + ResolverM04D27di.Value = valResolverM04D27di_0001; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 4, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[2] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Hints.CheckForRootScenario.IService), valResolverM04D27di_0000) + ,new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Hints.CheckForRootScenario.IDependency), valResolverM04D27di_0001) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.Hints.CheckForRootScenario.IService Resolve(Composition composition) + { + return composition.Root; + } + + public Pure.DI.UsageTests.Hints.CheckForRootScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.Root; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Hints.CheckForRootScenario.IService."); + } + } +} + +private sealed class ResolverM04D27di_0001: global::Pure.DI.IResolver { - private readonly Composition _rootM04D27di; - - public Composition() - { - _rootM04D27di = this; - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - } - - public Pure.DI.UsageTests.Hints.CheckForRootScenario.IService Root - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - return new Pure.DI.UsageTests.Hints.CheckForRootScenario.Service() - { - Dependency = new Pure.DI.UsageTests.Hints.CheckForRootScenario.Dependency() - }; - } - } - - private Pure.DI.UsageTests.Hints.CheckForRootScenario.IDependency RootM04D27di0001 - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - return new Pure.DI.UsageTests.Hints.CheckForRootScenario.Dependency(); - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - private static partial void OnNewRoot(global::Pure.DI.IResolver resolver, string name, object? tag, global::Pure.DI.Lifetime lifetime); - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - OnNewRoot(valResolverM04D27di_0000, "Root", null, Pure.DI.Lifetime.Transient); - ResolverM04D27di.Value = valResolverM04D27di_0000; - var valResolverM04D27di_0001 = new ResolverM04D27di_0001(); - OnNewRoot(valResolverM04D27di_0001, "RootM04D27di0001", "MyDep", Pure.DI.Lifetime.Transient); - ResolverM04D27di.Value = valResolverM04D27di_0001; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 4, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[2] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Hints.CheckForRootScenario.IService), valResolverM04D27di_0000) - ,new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Hints.CheckForRootScenario.IDependency), valResolverM04D27di_0001) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Hints.CheckForRootScenario.IService Resolve(Composition composition) - { - return composition.Root; - } - - public Pure.DI.UsageTests.Hints.CheckForRootScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.Root; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Hints.CheckForRootScenario.IService."); - } - } - } - - private sealed class ResolverM04D27di_0001: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Hints.CheckForRootScenario.IDependency Resolve(Composition composition) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type Pure.DI.UsageTests.Hints.CheckForRootScenario.IDependency."); - } - - public Pure.DI.UsageTests.Hints.CheckForRootScenario.IDependency ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case "MyDep": - return composition.RootM04D27di0001; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Hints.CheckForRootScenario.IDependency."); - } - } - } + public Pure.DI.UsageTests.Hints.CheckForRootScenario.IDependency Resolve(Composition composition) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type Pure.DI.UsageTests.Hints.CheckForRootScenario.IDependency."); + } + + public Pure.DI.UsageTests.Hints.CheckForRootScenario.IDependency ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case "MyDep": + return composition.RootM04D27di0001; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Hints.CheckForRootScenario.IDependency."); + } + } } + } ```
diff --git a/readme/complex-generics.md b/readme/complex-generics.md index fa08f48e8..73d89c74a 100644 --- a/readme/complex-generics.md +++ b/readme/complex-generics.md @@ -65,41 +65,41 @@ It can also be useful in a very simple scenario where, for example, the sequence ```mermaid classDiagram - class Composition { - +ProgramᐸStringᐳ Root - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - class ProgramᐸStringᐳ { - +Program(IServiceᐸStringˏInt32ˏListᐸStringᐳˏDictionaryᐸStringˏInt32ᐳᐳ service) - } - ServiceᐸStringˏInt32ˏListᐸStringᐳˏDictionaryᐸStringˏInt32ᐳᐳ --|> IServiceᐸStringˏInt32ˏListᐸStringᐳˏDictionaryᐸStringˏInt32ᐳᐳ : - class ServiceᐸStringˏInt32ˏListᐸStringᐳˏDictionaryᐸStringˏInt32ᐳᐳ { - +Service(IDependencyᐸStringᐳ dependency1, IDependencyᐸInt32ᐳ dependency2) - } - DependencyᐸStringᐳ --|> IDependencyᐸStringᐳ : - class DependencyᐸStringᐳ { - +Dependency() - } - DependencyStructᐸInt32ᐳ --|> IDependencyᐸInt32ᐳ : "value type" - class DependencyStructᐸInt32ᐳ { - +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 - ServiceᐸStringˏInt32ˏListᐸStringᐳˏDictionaryᐸStringˏInt32ᐳᐳ *-- DependencyᐸStringᐳ : IDependencyᐸStringᐳ - ServiceᐸStringˏInt32ˏListᐸStringᐳˏDictionaryᐸStringˏInt32ᐳᐳ *-- DependencyStructᐸInt32ᐳ : "value type" IDependencyᐸInt32ᐳ + class Composition { + +ProgramᐸStringᐳ Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + class ProgramᐸStringᐳ { + +Program(IServiceᐸStringˏInt32ˏListᐸStringᐳˏDictionaryᐸStringˏInt32ᐳᐳ service) + } + ServiceᐸStringˏInt32ˏListᐸStringᐳˏDictionaryᐸStringˏInt32ᐳᐳ --|> IServiceᐸStringˏInt32ˏListᐸStringᐳˏDictionaryᐸStringˏInt32ᐳᐳ : + class ServiceᐸStringˏInt32ˏListᐸStringᐳˏDictionaryᐸStringˏInt32ᐳᐳ { + +Service(IDependencyᐸStringᐳ dependency1, IDependencyᐸInt32ᐳ dependency2) + } + DependencyᐸStringᐳ --|> IDependencyᐸStringᐳ : + class DependencyᐸStringᐳ { + +Dependency() + } + DependencyStructᐸInt32ᐳ --|> IDependencyᐸInt32ᐳ : "value type" + class DependencyStructᐸInt32ᐳ { + +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 + ServiceᐸStringˏInt32ˏListᐸStringᐳˏDictionaryᐸStringˏInt32ᐳᐳ *-- DependencyᐸStringᐳ : IDependencyᐸStringᐳ + ServiceᐸStringˏInt32ˏListᐸStringᐳˏDictionaryᐸStringˏInt32ᐳᐳ *-- DependencyStructᐸInt32ᐳ : "value type" IDependencyᐸInt32ᐳ ``` @@ -108,180 +108,180 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; + +public Composition() { - private readonly Composition _rootM04D27di; - - public Composition() - { - _rootM04D27di = this; - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - } - - public Pure.DI.UsageTests.Generics.ComplexGenericsScenario.Program Root - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - return new Pure.DI.UsageTests.Generics.ComplexGenericsScenario.Program(new Pure.DI.UsageTests.Generics.ComplexGenericsScenario.Service, System.Collections.Generic.Dictionary>(new Pure.DI.UsageTests.Generics.ComplexGenericsScenario.Dependency(), new Pure.DI.UsageTests.Generics.ComplexGenericsScenario.DependencyStruct())); - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di>.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Generics.ComplexGenericsScenario.Program), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver> - { - public Pure.DI.UsageTests.Generics.ComplexGenericsScenario.Program Resolve(Composition composition) - { - return composition.Root; - } - - public Pure.DI.UsageTests.Generics.ComplexGenericsScenario.Program ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.Root; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Generics.ComplexGenericsScenario.Program."); - } - } - } + _rootM04D27di = this; } + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; +} + +public Pure.DI.UsageTests.Generics.ComplexGenericsScenario.Program Root +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + return new Pure.DI.UsageTests.Generics.ComplexGenericsScenario.Program(new Pure.DI.UsageTests.Generics.ComplexGenericsScenario.Service, System.Collections.Generic.Dictionary>(new Pure.DI.UsageTests.Generics.ComplexGenericsScenario.Dependency(), new Pure.DI.UsageTests.Generics.ComplexGenericsScenario.DependencyStruct())); + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di>.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Generics.ComplexGenericsScenario.Program), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver> +{ + public Pure.DI.UsageTests.Generics.ComplexGenericsScenario.Program Resolve(Composition composition) + { + return composition.Root; + } + + public Pure.DI.UsageTests.Generics.ComplexGenericsScenario.Program ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.Root; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Generics.ComplexGenericsScenario.Program."); + } + } +} + } ```
diff --git a/readme/composition-root-kinds.md b/readme/composition-root-kinds.md index a9540e047..3573b32cb 100644 --- a/readme/composition-root-kinds.md +++ b/readme/composition-root-kinds.md @@ -49,37 +49,37 @@ var dependency = Composition.Dependency; ```mermaid classDiagram - class Composition { - +IDependency Dependency - +IService GetOtherService() - +IService GetRoot() - + 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 ..> OtherService : IService GetOtherService() - Composition ..> Service : IService GetRoot() - Composition ..> Dependency : IDependency Dependency + class Composition { + +IDependency Dependency + +IService GetOtherService() + +IService GetRoot() + + 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 ..> OtherService : IService GetOtherService() + Composition ..> Service : IService GetRoot() + Composition ..> Dependency : IDependency Dependency ``` @@ -88,212 +88,212 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; + +public Composition() +{ + _rootM04D27di = this; +} + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +private partial Pure.DI.UsageTests.Advanced.CompositionRootKindsScenario.IService GetRoot() +{ + return new Pure.DI.UsageTests.Advanced.CompositionRootKindsScenario.Service(new Pure.DI.UsageTests.Advanced.CompositionRootKindsScenario.Dependency()); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public Pure.DI.UsageTests.Advanced.CompositionRootKindsScenario.IService GetOtherService() +{ + return new Pure.DI.UsageTests.Advanced.CompositionRootKindsScenario.OtherService(); +} + +internal static Pure.DI.UsageTests.Advanced.CompositionRootKindsScenario.IDependency Dependency +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + return new Pure.DI.UsageTests.Advanced.CompositionRootKindsScenario.Dependency(); + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + var valResolverM04D27di_0001 = new ResolverM04D27di_0001(); + ResolverM04D27di.Value = valResolverM04D27di_0001; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 4, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[2] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Advanced.CompositionRootKindsScenario.IService), valResolverM04D27di_0000) + ,new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Advanced.CompositionRootKindsScenario.IDependency), valResolverM04D27di_0001) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.Advanced.CompositionRootKindsScenario.IService Resolve(Composition composition) + { + return composition.GetRoot(); + } + + public Pure.DI.UsageTests.Advanced.CompositionRootKindsScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case "Other": + return composition.GetOtherService(); + case null: + return composition.GetRoot(); + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Advanced.CompositionRootKindsScenario.IService."); + } + } +} + +private sealed class ResolverM04D27di_0001: global::Pure.DI.IResolver { - private readonly Composition _rootM04D27di; - - public Composition() - { - _rootM04D27di = this; - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - private partial Pure.DI.UsageTests.Advanced.CompositionRootKindsScenario.IService GetRoot() - { - return new Pure.DI.UsageTests.Advanced.CompositionRootKindsScenario.Service(new Pure.DI.UsageTests.Advanced.CompositionRootKindsScenario.Dependency()); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public Pure.DI.UsageTests.Advanced.CompositionRootKindsScenario.IService GetOtherService() - { - return new Pure.DI.UsageTests.Advanced.CompositionRootKindsScenario.OtherService(); - } - - internal static Pure.DI.UsageTests.Advanced.CompositionRootKindsScenario.IDependency Dependency - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - return new Pure.DI.UsageTests.Advanced.CompositionRootKindsScenario.Dependency(); - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - var valResolverM04D27di_0001 = new ResolverM04D27di_0001(); - ResolverM04D27di.Value = valResolverM04D27di_0001; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 4, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[2] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Advanced.CompositionRootKindsScenario.IService), valResolverM04D27di_0000) - ,new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Advanced.CompositionRootKindsScenario.IDependency), valResolverM04D27di_0001) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Advanced.CompositionRootKindsScenario.IService Resolve(Composition composition) - { - return composition.GetRoot(); - } - - public Pure.DI.UsageTests.Advanced.CompositionRootKindsScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case "Other": - return composition.GetOtherService(); - case null: - return composition.GetRoot(); - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Advanced.CompositionRootKindsScenario.IService."); - } - } - } - - private sealed class ResolverM04D27di_0001: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Advanced.CompositionRootKindsScenario.IDependency Resolve(Composition composition) - { - return Composition.Dependency; - } - - public Pure.DI.UsageTests.Advanced.CompositionRootKindsScenario.IDependency ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return Composition.Dependency; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Advanced.CompositionRootKindsScenario.IDependency."); - } - } - } + public Pure.DI.UsageTests.Advanced.CompositionRootKindsScenario.IDependency Resolve(Composition composition) + { + return Composition.Dependency; + } + + public Pure.DI.UsageTests.Advanced.CompositionRootKindsScenario.IDependency ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return Composition.Dependency; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Advanced.CompositionRootKindsScenario.IDependency."); + } + } } + } ```
diff --git a/readme/composition-roots-simplified.md b/readme/composition-roots-simplified.md index 10fdd7050..fcca8dedf 100644 --- a/readme/composition-roots-simplified.md +++ b/readme/composition-roots-simplified.md @@ -44,35 +44,35 @@ var someOtherService = composition.Resolve("Other"); ```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 _ + 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 _ ``` @@ -81,185 +81,185 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; + +public Composition() { - private readonly Composition _rootM04D27di; - - public Composition() - { - _rootM04D27di = this; - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - } - - public Pure.DI.UsageTests.Basics.CompositionRootsSimplifiedScenario.IService MyRoot - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - return new Pure.DI.UsageTests.Basics.CompositionRootsSimplifiedScenario.Service(new Pure.DI.UsageTests.Basics.CompositionRootsSimplifiedScenario.Dependency()); - } - } - - private Pure.DI.UsageTests.Basics.CompositionRootsSimplifiedScenario.IService RootM04D27di0002 - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - return new Pure.DI.UsageTests.Basics.CompositionRootsSimplifiedScenario.OtherService(); - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Basics.CompositionRootsSimplifiedScenario.IService), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Basics.CompositionRootsSimplifiedScenario.IService Resolve(Composition composition) - { - return composition.MyRoot; - } - - public Pure.DI.UsageTests.Basics.CompositionRootsSimplifiedScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case "Other": - return composition.RootM04D27di0002; - case null: - return composition.MyRoot; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Basics.CompositionRootsSimplifiedScenario.IService."); - } - } - } + _rootM04D27di = this; } + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; +} + +public Pure.DI.UsageTests.Basics.CompositionRootsSimplifiedScenario.IService MyRoot +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + return new Pure.DI.UsageTests.Basics.CompositionRootsSimplifiedScenario.Service(new Pure.DI.UsageTests.Basics.CompositionRootsSimplifiedScenario.Dependency()); + } +} + +private Pure.DI.UsageTests.Basics.CompositionRootsSimplifiedScenario.IService RootM04D27di0002 +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + return new Pure.DI.UsageTests.Basics.CompositionRootsSimplifiedScenario.OtherService(); + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Basics.CompositionRootsSimplifiedScenario.IService), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.Basics.CompositionRootsSimplifiedScenario.IService Resolve(Composition composition) + { + return composition.MyRoot; + } + + public Pure.DI.UsageTests.Basics.CompositionRootsSimplifiedScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case "Other": + return composition.RootM04D27di0002; + case null: + return composition.MyRoot; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Basics.CompositionRootsSimplifiedScenario.IService."); + } + } +} + } ```
diff --git a/readme/composition-roots.md b/readme/composition-roots.md index cedb52325..6210f126e 100644 --- a/readme/composition-roots.md +++ b/readme/composition-roots.md @@ -68,37 +68,37 @@ This can be done if these methods are not needed, in case only certain compositi ```mermaid classDiagram - class Composition { - +IService MyRoot - +IService SomeOtherService - -IDependency _ - + 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 ..> OtherService : IService SomeOtherService - Composition ..> Service : IService MyRoot - Composition ..> Dependency : IDependency _ + class Composition { + +IService MyRoot + +IService SomeOtherService + -IDependency _ + + 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 ..> OtherService : IService SomeOtherService + Composition ..> Service : IService MyRoot + Composition ..> Dependency : IDependency _ ``` @@ -107,218 +107,218 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; + +public Composition() { - private readonly Composition _rootM04D27di; - - public Composition() - { - _rootM04D27di = this; - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - } - - public Pure.DI.UsageTests.Basics.CompositionRootsScenario.IService MyRoot - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - return new Pure.DI.UsageTests.Basics.CompositionRootsScenario.Service(new Pure.DI.UsageTests.Basics.CompositionRootsScenario.Dependency()); - } - } - - public Pure.DI.UsageTests.Basics.CompositionRootsScenario.IService SomeOtherService - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - return new Pure.DI.UsageTests.Basics.CompositionRootsScenario.OtherService(); - } - } - - private Pure.DI.UsageTests.Basics.CompositionRootsScenario.IDependency RootM04D27di0003 - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - return new Pure.DI.UsageTests.Basics.CompositionRootsScenario.Dependency(); - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - var valResolverM04D27di_0001 = new ResolverM04D27di_0001(); - ResolverM04D27di.Value = valResolverM04D27di_0001; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 4, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[2] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Basics.CompositionRootsScenario.IService), valResolverM04D27di_0000) - ,new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Basics.CompositionRootsScenario.IDependency), valResolverM04D27di_0001) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Basics.CompositionRootsScenario.IService Resolve(Composition composition) - { - return composition.MyRoot; - } - - public Pure.DI.UsageTests.Basics.CompositionRootsScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case "Other": - return composition.SomeOtherService; - case null: - return composition.MyRoot; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Basics.CompositionRootsScenario.IService."); - } - } - } - - private sealed class ResolverM04D27di_0001: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Basics.CompositionRootsScenario.IDependency Resolve(Composition composition) - { - return composition.RootM04D27di0003; - } - - public Pure.DI.UsageTests.Basics.CompositionRootsScenario.IDependency ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.RootM04D27di0003; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Basics.CompositionRootsScenario.IDependency."); - } - } - } + _rootM04D27di = this; +} + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; +} + +public Pure.DI.UsageTests.Basics.CompositionRootsScenario.IService MyRoot +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + return new Pure.DI.UsageTests.Basics.CompositionRootsScenario.Service(new Pure.DI.UsageTests.Basics.CompositionRootsScenario.Dependency()); + } +} + +public Pure.DI.UsageTests.Basics.CompositionRootsScenario.IService SomeOtherService +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + return new Pure.DI.UsageTests.Basics.CompositionRootsScenario.OtherService(); + } +} + +private Pure.DI.UsageTests.Basics.CompositionRootsScenario.IDependency RootM04D27di0003 +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + return new Pure.DI.UsageTests.Basics.CompositionRootsScenario.Dependency(); + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + var valResolverM04D27di_0001 = new ResolverM04D27di_0001(); + ResolverM04D27di.Value = valResolverM04D27di_0001; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 4, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[2] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Basics.CompositionRootsScenario.IService), valResolverM04D27di_0000) + ,new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Basics.CompositionRootsScenario.IDependency), valResolverM04D27di_0001) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.Basics.CompositionRootsScenario.IService Resolve(Composition composition) + { + return composition.MyRoot; + } + + public Pure.DI.UsageTests.Basics.CompositionRootsScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case "Other": + return composition.SomeOtherService; + case null: + return composition.MyRoot; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Basics.CompositionRootsScenario.IService."); + } + } +} + +private sealed class ResolverM04D27di_0001: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.Basics.CompositionRootsScenario.IDependency Resolve(Composition composition) + { + return composition.RootM04D27di0003; + } + + public Pure.DI.UsageTests.Basics.CompositionRootsScenario.IDependency ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.RootM04D27di0003; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Basics.CompositionRootsScenario.IDependency."); + } + } } + } ```
diff --git a/readme/constructor-ordinal-attribute.md b/readme/constructor-ordinal-attribute.md index 74867c36d..4b6be8dbc 100644 --- a/readme/constructor-ordinal-attribute.md +++ b/readme/constructor-ordinal-attribute.md @@ -47,23 +47,23 @@ The attribute `Ordinal` is part of the API, but you can use your own attribute a ```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 String - Service --|> IService : - class Service { - ~Service(String name) - } - class IService { - <> - } - Service o-- String : Argument "serviceName" - Composition ..> Service : IService Root + class Composition { + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + class String + Service --|> IService : + class Service { + ~Service(String name) + } + class IService { + <> + } + Service o-- String : Argument "serviceName" + Composition ..> Service : IService Root ``` @@ -72,171 +72,171 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; + +private readonly string _argM04D27di_serviceName; + +public Composition(string serviceName) { - private readonly Composition _rootM04D27di; - - private readonly string _argM04D27di_serviceName; - - public Composition(string serviceName) - { - _rootM04D27di = this; - if (ReferenceEquals(serviceName, null)) - { - throw new global::System.ArgumentNullException("serviceName"); - } - - _argM04D27di_serviceName = serviceName; - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - _argM04D27di_serviceName = baseComposition._argM04D27di_serviceName; - } - - public Pure.DI.UsageTests.Attributes.ConstructorOrdinalAttributeScenario.IService Root - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - return new Pure.DI.UsageTests.Attributes.ConstructorOrdinalAttributeScenario.Service(_argM04D27di_serviceName); - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Attributes.ConstructorOrdinalAttributeScenario.IService), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Attributes.ConstructorOrdinalAttributeScenario.IService Resolve(Composition composition) - { - return composition.Root; - } - - public Pure.DI.UsageTests.Attributes.ConstructorOrdinalAttributeScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.Root; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Attributes.ConstructorOrdinalAttributeScenario.IService."); - } - } - } + _rootM04D27di = this; + if (ReferenceEquals(serviceName, null)) + { + throw new global::System.ArgumentNullException("serviceName"); + } + + _argM04D27di_serviceName = serviceName; } + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; + _argM04D27di_serviceName = baseComposition._argM04D27di_serviceName; +} + +public Pure.DI.UsageTests.Attributes.ConstructorOrdinalAttributeScenario.IService Root +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + return new Pure.DI.UsageTests.Attributes.ConstructorOrdinalAttributeScenario.Service(_argM04D27di_serviceName); + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Attributes.ConstructorOrdinalAttributeScenario.IService), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.Attributes.ConstructorOrdinalAttributeScenario.IService Resolve(Composition composition) + { + return composition.Root; + } + + public Pure.DI.UsageTests.Attributes.ConstructorOrdinalAttributeScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.Root; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Attributes.ConstructorOrdinalAttributeScenario.IService."); + } + } +} + } ```
diff --git a/readme/custom-attributes.md b/readme/custom-attributes.md index 8924f3b37..018acd6b2 100644 --- a/readme/custom-attributes.md +++ b/readme/custom-attributes.md @@ -60,26 +60,26 @@ person.ToString().ShouldBe("123 Nik"); ```mermaid classDiagram - class PersonComposition { - +IPerson Person - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - class String - class Int32 - Person --|> IPerson : - class Person { - +Person(String name) - ~Object Id - } - class IPerson { - <> - } - Person *-- String : "NikName" String - Person o-- Int32 : Argument "personId" - PersonComposition ..> Person : IPerson Person + class PersonComposition { + +IPerson Person + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + class String + class Int32 + Person --|> IPerson : + class Person { + +Person(String name) + ~Object Id + } + class IPerson { + <> + } + Person *-- String : "NikName" String + Person o-- Int32 : Argument "personId" + PersonComposition ..> Person : IPerson Person ``` @@ -88,172 +88,172 @@ classDiagram Pure.DI-generated partial class PersonComposition
```c# -partial class PersonComposition +artial class PersonComposition + { +private readonly PersonComposition _rootM04D27di; + +private readonly int _argM04D27di_personId; + +public PersonComposition(int personId) { - private readonly PersonComposition _rootM04D27di; - - private readonly int _argM04D27di_personId; - - public PersonComposition(int personId) - { - _rootM04D27di = this; - _argM04D27di_personId = personId; - } - - internal PersonComposition(PersonComposition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - _argM04D27di_personId = baseComposition._argM04D27di_personId; - } - - public Pure.DI.UsageTests.Attributes.CustomAttributesScenario.IPerson Person - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - string transientM04D27di1_String = "Nik"; - Pure.DI.UsageTests.Attributes.CustomAttributesScenario.Person transientM04D27di0_Person = new Pure.DI.UsageTests.Attributes.CustomAttributesScenario.Person(transientM04D27di1_String); - transientM04D27di0_Person.Id = _argM04D27di_personId; - return transientM04D27di0_Person; - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static PersonComposition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Attributes.CustomAttributesScenario.IPerson), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(PersonComposition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(PersonComposition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Attributes.CustomAttributesScenario.IPerson Resolve(PersonComposition composition) - { - return composition.Person; - } - - public Pure.DI.UsageTests.Attributes.CustomAttributesScenario.IPerson ResolveByTag(PersonComposition composition, object tag) - { - switch (tag) - { - case null: - return composition.Person; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Attributes.CustomAttributesScenario.IPerson."); - } - } - } + _rootM04D27di = this; + _argM04D27di_personId = personId; } + +internal PersonComposition(PersonComposition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; + _argM04D27di_personId = baseComposition._argM04D27di_personId; +} + +public Pure.DI.UsageTests.Attributes.CustomAttributesScenario.IPerson Person +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + string transientM04D27di1_String = "Nik"; + Pure.DI.UsageTests.Attributes.CustomAttributesScenario.Person transientM04D27di0_Person = new Pure.DI.UsageTests.Attributes.CustomAttributesScenario.Person(transientM04D27di1_String); + transientM04D27di0_Person.Id = _argM04D27di_personId; + return transientM04D27di0_Person; + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static PersonComposition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Attributes.CustomAttributesScenario.IPerson), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(PersonComposition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(PersonComposition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.Attributes.CustomAttributesScenario.IPerson Resolve(PersonComposition composition) + { + return composition.Person; + } + + public Pure.DI.UsageTests.Attributes.CustomAttributesScenario.IPerson ResolveByTag(PersonComposition composition, object tag) + { + switch (tag) + { + case null: + return composition.Person; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Attributes.CustomAttributesScenario.IPerson."); + } + } +} + } ```
diff --git a/readme/decorator.md b/readme/decorator.md index bf2123d3f..037c772c0 100644 --- a/readme/decorator.md +++ b/readme/decorator.md @@ -34,26 +34,26 @@ Here an instance of the _Service_ type, labeled _"base"_, is embedded in the dec ```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 : "base" - class Service { - +Service() - } - GreetingService --|> IService : - class GreetingService { - +GreetingService(IService baseService) - } - class IService { - <> - } - GreetingService *-- Service : "base" IService - Composition ..> GreetingService : IService Root + class Composition { + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + Service --|> IService : "base" + class Service { + +Service() + } + GreetingService --|> IService : + class GreetingService { + +GreetingService(IService baseService) + } + class IService { + <> + } + GreetingService *-- Service : "base" IService + Composition ..> GreetingService : IService Root ``` @@ -62,165 +62,165 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; + +public Composition() { - private readonly Composition _rootM04D27di; - - public Composition() - { - _rootM04D27di = this; - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - } - - public Pure.DI.UsageTests.Interception.DecoratorScenario.IService Root - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - return new Pure.DI.UsageTests.Interception.DecoratorScenario.GreetingService(new Pure.DI.UsageTests.Interception.DecoratorScenario.Service()); - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Interception.DecoratorScenario.IService), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Interception.DecoratorScenario.IService Resolve(Composition composition) - { - return composition.Root; - } - - public Pure.DI.UsageTests.Interception.DecoratorScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.Root; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Interception.DecoratorScenario.IService."); - } - } - } + _rootM04D27di = this; } + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; +} + +public Pure.DI.UsageTests.Interception.DecoratorScenario.IService Root +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + return new Pure.DI.UsageTests.Interception.DecoratorScenario.GreetingService(new Pure.DI.UsageTests.Interception.DecoratorScenario.Service()); + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Interception.DecoratorScenario.IService), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.Interception.DecoratorScenario.IService Resolve(Composition composition) + { + return composition.Root; + } + + public Pure.DI.UsageTests.Interception.DecoratorScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.Root; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Interception.DecoratorScenario.IService."); + } + } +} + } ```
diff --git a/readme/default-lifetime.md b/readme/default-lifetime.md index 233f05383..99edbd2ed 100644 --- a/readme/default-lifetime.md +++ b/readme/default-lifetime.md @@ -43,30 +43,30 @@ service1.Dependency1.ShouldBe(service1.Dependency2); ```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 : - class Dependency { - +Dependency() - } - Service --|> IService : - class Service { - +Service(IDependency dependency1, IDependency dependency2) - } - class IDependency { - <> - } - class IService { - <> - } - Service o-- "Singleton" Dependency : IDependency - Service o-- "Singleton" Dependency : IDependency - Composition ..> Service : IService Root + class Composition { + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + Dependency --|> IDependency : + class Dependency { + +Dependency() + } + Service --|> IService : + class Service { + +Service(IDependency dependency1, IDependency dependency2) + } + class IDependency { + <> + } + class IService { + <> + } + Service o-- "Singleton" Dependency : IDependency + Service o-- "Singleton" Dependency : IDependency + Composition ..> Service : IService Root ``` @@ -75,190 +75,190 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; +private readonly object _lockM04D27di; +private Pure.DI.UsageTests.Lifetimes.DefaultLifetimeScenario.Service _singletonM04D27di37_Service; +private Pure.DI.UsageTests.Lifetimes.DefaultLifetimeScenario.Dependency _singletonM04D27di36_Dependency; + +public Composition() { - private readonly Composition _rootM04D27di; - private readonly object _lockM04D27di; - private Pure.DI.UsageTests.Lifetimes.DefaultLifetimeScenario.Service _singletonM04D27di37_Service; - private Pure.DI.UsageTests.Lifetimes.DefaultLifetimeScenario.Dependency _singletonM04D27di36_Dependency; - - public Composition() - { - _rootM04D27di = this; - _lockM04D27di = new object(); - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - _lockM04D27di = _rootM04D27di._lockM04D27di; - } - - public Pure.DI.UsageTests.Lifetimes.DefaultLifetimeScenario.IService Root - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - if (_rootM04D27di._singletonM04D27di37_Service == null) - { - lock (_lockM04D27di) - { - if (_rootM04D27di._singletonM04D27di37_Service == null) - { - if (_rootM04D27di._singletonM04D27di36_Dependency == null) - { - _singletonM04D27di36_Dependency = new Pure.DI.UsageTests.Lifetimes.DefaultLifetimeScenario.Dependency(); - _rootM04D27di._singletonM04D27di36_Dependency = _singletonM04D27di36_Dependency; - } - _singletonM04D27di37_Service = new Pure.DI.UsageTests.Lifetimes.DefaultLifetimeScenario.Service(_singletonM04D27di36_Dependency, _rootM04D27di._singletonM04D27di36_Dependency); - _rootM04D27di._singletonM04D27di37_Service = _singletonM04D27di37_Service; - } - } - } - return _rootM04D27di._singletonM04D27di37_Service; - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Lifetimes.DefaultLifetimeScenario.IService), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Lifetimes.DefaultLifetimeScenario.IService Resolve(Composition composition) - { - return composition.Root; - } - - public Pure.DI.UsageTests.Lifetimes.DefaultLifetimeScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.Root; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Lifetimes.DefaultLifetimeScenario.IService."); - } - } - } + _rootM04D27di = this; + _lockM04D27di = new object(); } + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; + _lockM04D27di = _rootM04D27di._lockM04D27di; +} + +public Pure.DI.UsageTests.Lifetimes.DefaultLifetimeScenario.IService Root +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + if (_rootM04D27di._singletonM04D27di37_Service == null) + { + lock (_lockM04D27di) + { + if (_rootM04D27di._singletonM04D27di37_Service == null) + { + if (_rootM04D27di._singletonM04D27di36_Dependency == null) + { + _singletonM04D27di36_Dependency = new Pure.DI.UsageTests.Lifetimes.DefaultLifetimeScenario.Dependency(); + _rootM04D27di._singletonM04D27di36_Dependency = _singletonM04D27di36_Dependency; + } + _singletonM04D27di37_Service = new Pure.DI.UsageTests.Lifetimes.DefaultLifetimeScenario.Service(_singletonM04D27di36_Dependency, _rootM04D27di._singletonM04D27di36_Dependency); + _rootM04D27di._singletonM04D27di37_Service = _singletonM04D27di37_Service; + } + } + } + return _rootM04D27di._singletonM04D27di37_Service; + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Lifetimes.DefaultLifetimeScenario.IService), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.Lifetimes.DefaultLifetimeScenario.IService Resolve(Composition composition) + { + return composition.Root; + } + + public Pure.DI.UsageTests.Lifetimes.DefaultLifetimeScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.Root; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Lifetimes.DefaultLifetimeScenario.IService."); + } + } +} + } ```
diff --git a/readme/default-values.md b/readme/default-values.md index 1b409bf6f..bfaa5cf59 100644 --- a/readme/default-values.md +++ b/readme/default-values.md @@ -39,30 +39,30 @@ service.Name.ShouldBe("My Service"); ```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 : - class Dependency { - +Dependency() - } - Service --|> IService : - class Service { - +Service(String name) - +IDependency Dependency - } - class IDependency { - <> - } - class IService { - <> - } - Service *-- Dependency : IDependency - Composition ..> Service : IService Root + class Composition { + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + Dependency --|> IDependency : + class Dependency { + +Dependency() + } + Service --|> IService : + class Service { + +Service(String name) + +IDependency Dependency + } + class IDependency { + <> + } + class IService { + <> + } + Service *-- Dependency : IDependency + Composition ..> Service : IService Root ``` @@ -71,172 +71,172 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; + +public Composition() { - private readonly Composition _rootM04D27di; - - public Composition() - { - _rootM04D27di = this; - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - } - - public Pure.DI.UsageTests.Basics.DefaultValuesScenario.IService Root - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - return new Pure.DI.UsageTests.Basics.DefaultValuesScenario.Service() - { - Dependency = new Pure.DI.UsageTests.Basics.DefaultValuesScenario.Dependency() - }; - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Basics.DefaultValuesScenario.IService), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Basics.DefaultValuesScenario.IService Resolve(Composition composition) - { - return composition.Root; - } - - public Pure.DI.UsageTests.Basics.DefaultValuesScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.Root; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Basics.DefaultValuesScenario.IService."); - } - } - } + _rootM04D27di = this; } + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; +} + +public Pure.DI.UsageTests.Basics.DefaultValuesScenario.IService Root +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + return new Pure.DI.UsageTests.Basics.DefaultValuesScenario.Service() + { + Dependency = new Pure.DI.UsageTests.Basics.DefaultValuesScenario.Dependency() + }; + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Basics.DefaultValuesScenario.IService), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.Basics.DefaultValuesScenario.IService Resolve(Composition composition) + { + return composition.Root; + } + + public Pure.DI.UsageTests.Basics.DefaultValuesScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.Root; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Basics.DefaultValuesScenario.IService."); + } + } +} + } ```
diff --git a/readme/dependent-compositions.md b/readme/dependent-compositions.md index be0a07288..29228173e 100644 --- a/readme/dependent-compositions.md +++ b/readme/dependent-compositions.md @@ -51,35 +51,35 @@ service = otherComposition.Program.Service; ```mermaid classDiagram - class OtherComposition { - +Program Program - +IService Root - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - class Program { - +Program(IService service) - } - Service --|> IService : - class Service { - +Service(IDependency dependency) - } - Dependency --|> IDependency : - class Dependency { - +Dependency() - } - class IService { - <> - } - class IDependency { - <> - } - Program *-- Service : IService - Service *-- Dependency : IDependency - OtherComposition ..> Service : IService Root - OtherComposition ..> Program : Program Program + class OtherComposition { + +Program Program + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + class Program { + +Program(IService service) + } + Service --|> IService : + class Service { + +Service(IDependency dependency) + } + Dependency --|> IDependency : + class Dependency { + +Dependency() + } + class IService { + <> + } + class IDependency { + <> + } + Program *-- Service : IService + Service *-- Dependency : IDependency + OtherComposition ..> Service : IService Root + OtherComposition ..> Program : Program Program ``` @@ -88,168 +88,168 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; + +public Composition() { - private readonly Composition _rootM04D27di; - - public Composition() - { - _rootM04D27di = this; - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - } - - public Pure.DI.UsageTests.Advanced.DependentCompositionsScenario.IService Root - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - return new Pure.DI.UsageTests.Advanced.DependentCompositionsScenario.Service(new Pure.DI.UsageTests.Advanced.DependentCompositionsScenario.Dependency()); - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Advanced.DependentCompositionsScenario.IService), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Advanced.DependentCompositionsScenario.IService Resolve(Composition composition) - { - return composition.Root; - } - - public Pure.DI.UsageTests.Advanced.DependentCompositionsScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.Root; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Advanced.DependentCompositionsScenario.IService."); - } - } - } + _rootM04D27di = this; } + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; +} + +public Pure.DI.UsageTests.Advanced.DependentCompositionsScenario.IService Root +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + return new Pure.DI.UsageTests.Advanced.DependentCompositionsScenario.Service(new Pure.DI.UsageTests.Advanced.DependentCompositionsScenario.Dependency()); + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Advanced.DependentCompositionsScenario.IService), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.Advanced.DependentCompositionsScenario.IService Resolve(Composition composition) + { + return composition.Root; + } + + public Pure.DI.UsageTests.Advanced.DependentCompositionsScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.Root; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Advanced.DependentCompositionsScenario.IService."); + } + } +} + } ```
@@ -258,205 +258,205 @@ partial class Composition Pure.DI-generated partial class OtherComposition
```c# -partial class OtherComposition +artial class OtherComposition + { +private readonly OtherComposition _rootM04D27di; + +public OtherComposition() +{ + _rootM04D27di = this; +} + +internal OtherComposition(OtherComposition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; +} + +public Pure.DI.UsageTests.Advanced.DependentCompositionsScenario.IService Root +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + return new Pure.DI.UsageTests.Advanced.DependentCompositionsScenario.Service(new Pure.DI.UsageTests.Advanced.DependentCompositionsScenario.Dependency()); + } +} + +public Pure.DI.UsageTests.Advanced.DependentCompositionsScenario.Program Program +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + return new Pure.DI.UsageTests.Advanced.DependentCompositionsScenario.Program(new Pure.DI.UsageTests.Advanced.DependentCompositionsScenario.Service(new Pure.DI.UsageTests.Advanced.DependentCompositionsScenario.Dependency())); + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static OtherComposition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + var valResolverM04D27di_0001 = new ResolverM04D27di_0001(); + ResolverM04D27di.Value = valResolverM04D27di_0001; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 4, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[2] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Advanced.DependentCompositionsScenario.IService), valResolverM04D27di_0000) + ,new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Advanced.DependentCompositionsScenario.Program), valResolverM04D27di_0001) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(OtherComposition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(OtherComposition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.Advanced.DependentCompositionsScenario.IService Resolve(OtherComposition composition) + { + return composition.Root; + } + + public Pure.DI.UsageTests.Advanced.DependentCompositionsScenario.IService ResolveByTag(OtherComposition composition, object tag) + { + switch (tag) + { + case null: + return composition.Root; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Advanced.DependentCompositionsScenario.IService."); + } + } +} + +private sealed class ResolverM04D27di_0001: global::Pure.DI.IResolver { - private readonly OtherComposition _rootM04D27di; - - public OtherComposition() - { - _rootM04D27di = this; - } - - internal OtherComposition(OtherComposition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - } - - public Pure.DI.UsageTests.Advanced.DependentCompositionsScenario.IService Root - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - return new Pure.DI.UsageTests.Advanced.DependentCompositionsScenario.Service(new Pure.DI.UsageTests.Advanced.DependentCompositionsScenario.Dependency()); - } - } - - public Pure.DI.UsageTests.Advanced.DependentCompositionsScenario.Program Program - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - return new Pure.DI.UsageTests.Advanced.DependentCompositionsScenario.Program(new Pure.DI.UsageTests.Advanced.DependentCompositionsScenario.Service(new Pure.DI.UsageTests.Advanced.DependentCompositionsScenario.Dependency())); - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static OtherComposition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - var valResolverM04D27di_0001 = new ResolverM04D27di_0001(); - ResolverM04D27di.Value = valResolverM04D27di_0001; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 4, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[2] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Advanced.DependentCompositionsScenario.IService), valResolverM04D27di_0000) - ,new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Advanced.DependentCompositionsScenario.Program), valResolverM04D27di_0001) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(OtherComposition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(OtherComposition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Advanced.DependentCompositionsScenario.IService Resolve(OtherComposition composition) - { - return composition.Root; - } - - public Pure.DI.UsageTests.Advanced.DependentCompositionsScenario.IService ResolveByTag(OtherComposition composition, object tag) - { - switch (tag) - { - case null: - return composition.Root; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Advanced.DependentCompositionsScenario.IService."); - } - } - } - - private sealed class ResolverM04D27di_0001: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Advanced.DependentCompositionsScenario.Program Resolve(OtherComposition composition) - { - return composition.Program; - } - - public Pure.DI.UsageTests.Advanced.DependentCompositionsScenario.Program ResolveByTag(OtherComposition composition, object tag) - { - switch (tag) - { - case null: - return composition.Program; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Advanced.DependentCompositionsScenario.Program."); - } - } - } + public Pure.DI.UsageTests.Advanced.DependentCompositionsScenario.Program Resolve(OtherComposition composition) + { + return composition.Program; + } + + public Pure.DI.UsageTests.Advanced.DependentCompositionsScenario.Program ResolveByTag(OtherComposition composition, object tag) + { + switch (tag) + { + case null: + return composition.Program; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Advanced.DependentCompositionsScenario.Program."); + } + } } + } ```
diff --git a/readme/disposable-singleton.md b/readme/disposable-singleton.md index 8fd02924b..e065493e7 100644 --- a/readme/disposable-singleton.md +++ b/readme/disposable-singleton.md @@ -48,30 +48,30 @@ A composition class becomes disposable if it creates at least one disposable sin ```mermaid classDiagram - class Composition { - +IService Root - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - Composition --|> IDisposable - Dependency --|> IDependency : - class Dependency { - +Dependency() - } - Service --|> IService : - class Service { - +Service(IDependency dependency) - } - class IDependency { - <> - } - class IService { - <> - } - Service o-- "Singleton" Dependency : IDependency - Composition ..> Service : IService Root + class Composition { + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + Composition --|> IDisposable + Dependency --|> IDependency : + class Dependency { + +Dependency() + } + Service --|> IService : + class Service { + +Service(IDependency dependency) + } + class IDependency { + <> + } + class IService { + <> + } + Service o-- "Singleton" Dependency : IDependency + Composition ..> Service : IService Root ``` @@ -80,221 +80,221 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition: global::System.IDisposable +artial class Composition: global::System.IDisposable + { +private readonly Composition _rootM04D27di; +private readonly object _lockM04D27di; +private object[] _disposablesM04D27di; +private int _disposeIndexM04D27di; +private Pure.DI.UsageTests.Lifetimes.DisposableSingletonScenario.Dependency _singletonM04D27di36_Dependency; + +public Composition() { - private readonly Composition _rootM04D27di; - private readonly object _lockM04D27di; - private object[] _disposablesM04D27di; - private int _disposeIndexM04D27di; - private Pure.DI.UsageTests.Lifetimes.DisposableSingletonScenario.Dependency _singletonM04D27di36_Dependency; - - public Composition() - { - _rootM04D27di = this; - _lockM04D27di = new object(); - _disposablesM04D27di = new object[1]; - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - _lockM04D27di = _rootM04D27di._lockM04D27di; - } - - public Pure.DI.UsageTests.Lifetimes.DisposableSingletonScenario.IService Root - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - if (_rootM04D27di._singletonM04D27di36_Dependency == null) - { - lock (_lockM04D27di) - { - if (_rootM04D27di._singletonM04D27di36_Dependency == null) - { - _singletonM04D27di36_Dependency = new Pure.DI.UsageTests.Lifetimes.DisposableSingletonScenario.Dependency(); - _rootM04D27di._singletonM04D27di36_Dependency = _singletonM04D27di36_Dependency; - _rootM04D27di._disposablesM04D27di[_rootM04D27di._disposeIndexM04D27di++] = _singletonM04D27di36_Dependency; - } - } - } - return new Pure.DI.UsageTests.Lifetimes.DisposableSingletonScenario.Service(_rootM04D27di._singletonM04D27di36_Dependency); - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {type}."); - } - - public void Dispose() - { - int disposeIndex; - object[] disposables; - lock (_lockM04D27di) - { - disposeIndex = _disposeIndexM04D27di; - _disposeIndexM04D27di = 0; - disposables = _disposablesM04D27di; - _disposablesM04D27di = new object[1]; - _singletonM04D27di36_Dependency = null; - } - - while (disposeIndex-- > 0) - { - switch (disposables[disposeIndex]) - { - case global::System.IDisposable disposableInstance: - try - { - disposableInstance.Dispose(); - } - catch (Exception exception) - { - OnDisposeException(disposableInstance, exception); - } - break; - } - } - } - - partial void OnDisposeException(T disposableInstance, Exception exception) where T : global::System.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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Lifetimes.DisposableSingletonScenario.IService), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Lifetimes.DisposableSingletonScenario.IService Resolve(Composition composition) - { - return composition.Root; - } - - public Pure.DI.UsageTests.Lifetimes.DisposableSingletonScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.Root; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Lifetimes.DisposableSingletonScenario.IService."); - } - } - } + _rootM04D27di = this; + _lockM04D27di = new object(); + _disposablesM04D27di = new object[1]; } + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; + _lockM04D27di = _rootM04D27di._lockM04D27di; +} + +public Pure.DI.UsageTests.Lifetimes.DisposableSingletonScenario.IService Root +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + if (_rootM04D27di._singletonM04D27di36_Dependency == null) + { + lock (_lockM04D27di) + { + if (_rootM04D27di._singletonM04D27di36_Dependency == null) + { + _singletonM04D27di36_Dependency = new Pure.DI.UsageTests.Lifetimes.DisposableSingletonScenario.Dependency(); + _rootM04D27di._singletonM04D27di36_Dependency = _singletonM04D27di36_Dependency; + _rootM04D27di._disposablesM04D27di[_rootM04D27di._disposeIndexM04D27di++] = _singletonM04D27di36_Dependency; + } + } + } + return new Pure.DI.UsageTests.Lifetimes.DisposableSingletonScenario.Service(_rootM04D27di._singletonM04D27di36_Dependency); + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {type}."); +} + +public void Dispose() +{ + int disposeIndex; + object[] disposables; + lock (_lockM04D27di) + { + disposeIndex = _disposeIndexM04D27di; + _disposeIndexM04D27di = 0; + disposables = _disposablesM04D27di; + _disposablesM04D27di = new object[1]; + _singletonM04D27di36_Dependency = null; + } + + while (disposeIndex-- > 0) + { + switch (disposables[disposeIndex]) + { + case global::System.IDisposable disposableInstance: + try + { + disposableInstance.Dispose(); + } + catch (Exception exception) + { + OnDisposeException(disposableInstance, exception); + } + break; + } + } +} + +partial void OnDisposeException(T disposableInstance, Exception exception) where T : global::System.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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Lifetimes.DisposableSingletonScenario.IService), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.Lifetimes.DisposableSingletonScenario.IService Resolve(Composition composition) + { + return composition.Root; + } + + public Pure.DI.UsageTests.Lifetimes.DisposableSingletonScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.Root; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Lifetimes.DisposableSingletonScenario.IService."); + } + } +} + } ```
diff --git a/readme/enumerable-generics.md b/readme/enumerable-generics.md index 3fcb99701..8fc5e0ec5 100644 --- a/readme/enumerable-generics.md +++ b/readme/enumerable-generics.md @@ -47,60 +47,60 @@ stringService.Dependencies[1].ShouldBeOfType>(); ```mermaid classDiagram - class Composition { - +IServiceᐸInt32ᐳ IntRoot - +IServiceᐸStringᐳ StringRoot - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - ServiceᐸInt32ᐳ --|> IServiceᐸInt32ᐳ : - class ServiceᐸInt32ᐳ { - +Service(IEnumerableᐸIDependencyᐸInt32ᐳᐳ dependencies) - } - ServiceᐸStringᐳ --|> IServiceᐸStringᐳ : - class ServiceᐸStringᐳ { - +Service(IEnumerableᐸIDependencyᐸStringᐳᐳ dependencies) - } - class IEnumerableᐸIDependencyᐸInt32ᐳᐳ - class IEnumerableᐸIDependencyᐸStringᐳᐳ - AbcDependencyᐸInt32ᐳ --|> IDependencyᐸInt32ᐳ : - class AbcDependencyᐸInt32ᐳ { - +AbcDependency() - } - XyzDependencyᐸInt32ᐳ --|> IDependencyᐸInt32ᐳ : "Xyz" - class XyzDependencyᐸInt32ᐳ { - +XyzDependency() - } - AbcDependencyᐸStringᐳ --|> IDependencyᐸStringᐳ : - class AbcDependencyᐸStringᐳ { - +AbcDependency() - } - XyzDependencyᐸStringᐳ --|> IDependencyᐸStringᐳ : "Xyz" - class XyzDependencyᐸStringᐳ { - +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 - ServiceᐸInt32ᐳ o-- "PerBlock" IEnumerableᐸIDependencyᐸInt32ᐳᐳ : IEnumerableᐸIDependencyᐸInt32ᐳᐳ - ServiceᐸStringᐳ o-- "PerBlock" IEnumerableᐸIDependencyᐸStringᐳᐳ : IEnumerableᐸIDependencyᐸStringᐳᐳ - IEnumerableᐸIDependencyᐸInt32ᐳᐳ *-- AbcDependencyᐸInt32ᐳ : IDependencyᐸInt32ᐳ - IEnumerableᐸIDependencyᐸInt32ᐳᐳ *-- XyzDependencyᐸInt32ᐳ : "Xyz" IDependencyᐸInt32ᐳ - IEnumerableᐸIDependencyᐸStringᐳᐳ *-- AbcDependencyᐸStringᐳ : IDependencyᐸStringᐳ - IEnumerableᐸIDependencyᐸStringᐳᐳ *-- XyzDependencyᐸStringᐳ : "Xyz" IDependencyᐸStringᐳ + class Composition { + +IServiceᐸInt32ᐳ IntRoot + +IServiceᐸStringᐳ StringRoot + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + ServiceᐸInt32ᐳ --|> IServiceᐸInt32ᐳ : + class ServiceᐸInt32ᐳ { + +Service(IEnumerableᐸIDependencyᐸInt32ᐳᐳ dependencies) + } + ServiceᐸStringᐳ --|> IServiceᐸStringᐳ : + class ServiceᐸStringᐳ { + +Service(IEnumerableᐸIDependencyᐸStringᐳᐳ dependencies) + } + class IEnumerableᐸIDependencyᐸInt32ᐳᐳ + class IEnumerableᐸIDependencyᐸStringᐳᐳ + AbcDependencyᐸInt32ᐳ --|> IDependencyᐸInt32ᐳ : + class AbcDependencyᐸInt32ᐳ { + +AbcDependency() + } + XyzDependencyᐸInt32ᐳ --|> IDependencyᐸInt32ᐳ : "Xyz" + class XyzDependencyᐸInt32ᐳ { + +XyzDependency() + } + AbcDependencyᐸStringᐳ --|> IDependencyᐸStringᐳ : + class AbcDependencyᐸStringᐳ { + +AbcDependency() + } + XyzDependencyᐸStringᐳ --|> IDependencyᐸStringᐳ : "Xyz" + class XyzDependencyᐸStringᐳ { + +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 + ServiceᐸInt32ᐳ o-- "PerBlock" IEnumerableᐸIDependencyᐸInt32ᐳᐳ : IEnumerableᐸIDependencyᐸInt32ᐳᐳ + ServiceᐸStringᐳ o-- "PerBlock" IEnumerableᐸIDependencyᐸStringᐳᐳ : IEnumerableᐸIDependencyᐸStringᐳᐳ + IEnumerableᐸIDependencyᐸInt32ᐳᐳ *-- AbcDependencyᐸInt32ᐳ : IDependencyᐸInt32ᐳ + IEnumerableᐸIDependencyᐸInt32ᐳᐳ *-- XyzDependencyᐸInt32ᐳ : "Xyz" IDependencyᐸInt32ᐳ + IEnumerableᐸIDependencyᐸStringᐳᐳ *-- AbcDependencyᐸStringᐳ : IDependencyᐸStringᐳ + IEnumerableᐸIDependencyᐸStringᐳᐳ *-- XyzDependencyᐸStringᐳ : "Xyz" IDependencyᐸStringᐳ ``` @@ -109,244 +109,244 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; + +public Composition() { - private readonly Composition _rootM04D27di; - - public Composition() - { - _rootM04D27di = this; - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - } - - public Pure.DI.UsageTests.BCL.EnumerableGenericsScenario.IService IntRoot - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x200)] - System.Collections.Generic.IEnumerable> LocalperBlockM04D27di1_IEnumerable() - { - yield return new Pure.DI.UsageTests.BCL.EnumerableGenericsScenario.AbcDependency(); - yield return new Pure.DI.UsageTests.BCL.EnumerableGenericsScenario.XyzDependency(); - } - System.Collections.Generic.IEnumerable> perBlockM04D27di1_IEnumerable = LocalperBlockM04D27di1_IEnumerable(); - return new Pure.DI.UsageTests.BCL.EnumerableGenericsScenario.Service(perBlockM04D27di1_IEnumerable); - } - } - - public Pure.DI.UsageTests.BCL.EnumerableGenericsScenario.IService StringRoot - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x200)] - System.Collections.Generic.IEnumerable> LocalperBlockM04D27di1_IEnumerable() - { - yield return new Pure.DI.UsageTests.BCL.EnumerableGenericsScenario.AbcDependency(); - yield return new Pure.DI.UsageTests.BCL.EnumerableGenericsScenario.XyzDependency(); - } - System.Collections.Generic.IEnumerable> perBlockM04D27di1_IEnumerable = LocalperBlockM04D27di1_IEnumerable(); - return new Pure.DI.UsageTests.BCL.EnumerableGenericsScenario.Service(perBlockM04D27di1_IEnumerable); - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di>.Value = valResolverM04D27di_0000; - var valResolverM04D27di_0001 = new ResolverM04D27di_0001(); - ResolverM04D27di>.Value = valResolverM04D27di_0001; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 4, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[2] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.BCL.EnumerableGenericsScenario.IService), valResolverM04D27di_0000) - ,new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.BCL.EnumerableGenericsScenario.IService), valResolverM04D27di_0001) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver> - { - public Pure.DI.UsageTests.BCL.EnumerableGenericsScenario.IService Resolve(Composition composition) - { - return composition.IntRoot; - } - - public Pure.DI.UsageTests.BCL.EnumerableGenericsScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.IntRoot; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.BCL.EnumerableGenericsScenario.IService."); - } - } - } - - private sealed class ResolverM04D27di_0001: global::Pure.DI.IResolver> - { - public Pure.DI.UsageTests.BCL.EnumerableGenericsScenario.IService Resolve(Composition composition) - { - return composition.StringRoot; - } - - public Pure.DI.UsageTests.BCL.EnumerableGenericsScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.StringRoot; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.BCL.EnumerableGenericsScenario.IService."); - } - } - } + _rootM04D27di = this; } + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; +} + +public Pure.DI.UsageTests.BCL.EnumerableGenericsScenario.IService IntRoot +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x200)] + System.Collections.Generic.IEnumerable> LocalperBlockM04D27di1_IEnumerable() + { + yield return new Pure.DI.UsageTests.BCL.EnumerableGenericsScenario.AbcDependency(); + yield return new Pure.DI.UsageTests.BCL.EnumerableGenericsScenario.XyzDependency(); + } + System.Collections.Generic.IEnumerable> perBlockM04D27di1_IEnumerable = LocalperBlockM04D27di1_IEnumerable(); + return new Pure.DI.UsageTests.BCL.EnumerableGenericsScenario.Service(perBlockM04D27di1_IEnumerable); + } +} + +public Pure.DI.UsageTests.BCL.EnumerableGenericsScenario.IService StringRoot +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x200)] + System.Collections.Generic.IEnumerable> LocalperBlockM04D27di1_IEnumerable() + { + yield return new Pure.DI.UsageTests.BCL.EnumerableGenericsScenario.AbcDependency(); + yield return new Pure.DI.UsageTests.BCL.EnumerableGenericsScenario.XyzDependency(); + } + System.Collections.Generic.IEnumerable> perBlockM04D27di1_IEnumerable = LocalperBlockM04D27di1_IEnumerable(); + return new Pure.DI.UsageTests.BCL.EnumerableGenericsScenario.Service(perBlockM04D27di1_IEnumerable); + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di>.Value = valResolverM04D27di_0000; + var valResolverM04D27di_0001 = new ResolverM04D27di_0001(); + ResolverM04D27di>.Value = valResolverM04D27di_0001; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 4, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[2] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.BCL.EnumerableGenericsScenario.IService), valResolverM04D27di_0000) + ,new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.BCL.EnumerableGenericsScenario.IService), valResolverM04D27di_0001) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver> +{ + public Pure.DI.UsageTests.BCL.EnumerableGenericsScenario.IService Resolve(Composition composition) + { + return composition.IntRoot; + } + + public Pure.DI.UsageTests.BCL.EnumerableGenericsScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.IntRoot; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.BCL.EnumerableGenericsScenario.IService."); + } + } +} + +private sealed class ResolverM04D27di_0001: global::Pure.DI.IResolver> +{ + public Pure.DI.UsageTests.BCL.EnumerableGenericsScenario.IService Resolve(Composition composition) + { + return composition.StringRoot; + } + + public Pure.DI.UsageTests.BCL.EnumerableGenericsScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.StringRoot; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.BCL.EnumerableGenericsScenario.IService."); + } + } +} + } ```
diff --git a/readme/enumerable.md b/readme/enumerable.md index 15b058bf4..345a01c43 100644 --- a/readme/enumerable.md +++ b/readme/enumerable.md @@ -42,36 +42,36 @@ service.Dependencies[1].ShouldBeOfType(); ```mermaid classDiagram - class Composition { - +IService Root - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - AbcDependency --|> IDependency : - class AbcDependency { - +AbcDependency() - } - XyzDependency --|> IDependency : 2 - class XyzDependency { - +XyzDependency() - } - Service --|> IService : - class Service { - +Service(IEnumerableᐸIDependencyᐳ dependencies) - } - class IEnumerableᐸIDependencyᐳ - class IDependency { - <> - } - class IService { - <> - } - Service o-- "PerBlock" IEnumerableᐸIDependencyᐳ : IEnumerableᐸIDependencyᐳ - Composition ..> Service : IService Root - IEnumerableᐸIDependencyᐳ *-- AbcDependency : IDependency - IEnumerableᐸIDependencyᐳ *-- XyzDependency : 2 IDependency + class Composition { + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + AbcDependency --|> IDependency : + class AbcDependency { + +AbcDependency() + } + XyzDependency --|> IDependency : 2 + class XyzDependency { + +XyzDependency() + } + Service --|> IService : + class Service { + +Service(IEnumerableᐸIDependencyᐳ dependencies) + } + class IEnumerableᐸIDependencyᐳ + class IDependency { + <> + } + class IService { + <> + } + Service o-- "PerBlock" IEnumerableᐸIDependencyᐳ : IEnumerableᐸIDependencyᐳ + Composition ..> Service : IService Root + IEnumerableᐸIDependencyᐳ *-- AbcDependency : IDependency + IEnumerableᐸIDependencyᐳ *-- XyzDependency : 2 IDependency ``` @@ -80,182 +80,182 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; + +public Composition() { - private readonly Composition _rootM04D27di; - - public Composition() - { - _rootM04D27di = this; - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - } - - public Pure.DI.UsageTests.BCL.EnumerableScenario.IService Root - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x200)] - System.Collections.Generic.IEnumerable LocalperBlockM04D27di1_IEnumerable() - { - yield return new Pure.DI.UsageTests.BCL.EnumerableScenario.AbcDependency(); - yield return new Pure.DI.UsageTests.BCL.EnumerableScenario.XyzDependency(); - } - System.Collections.Generic.IEnumerable perBlockM04D27di1_IEnumerable = LocalperBlockM04D27di1_IEnumerable(); - return new Pure.DI.UsageTests.BCL.EnumerableScenario.Service(perBlockM04D27di1_IEnumerable); - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.BCL.EnumerableScenario.IService), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.BCL.EnumerableScenario.IService Resolve(Composition composition) - { - return composition.Root; - } - - public Pure.DI.UsageTests.BCL.EnumerableScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.Root; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.BCL.EnumerableScenario.IService."); - } - } - } + _rootM04D27di = this; } + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; +} + +public Pure.DI.UsageTests.BCL.EnumerableScenario.IService Root +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x200)] + System.Collections.Generic.IEnumerable LocalperBlockM04D27di1_IEnumerable() + { + yield return new Pure.DI.UsageTests.BCL.EnumerableScenario.AbcDependency(); + yield return new Pure.DI.UsageTests.BCL.EnumerableScenario.XyzDependency(); + } + System.Collections.Generic.IEnumerable perBlockM04D27di1_IEnumerable = LocalperBlockM04D27di1_IEnumerable(); + return new Pure.DI.UsageTests.BCL.EnumerableScenario.Service(perBlockM04D27di1_IEnumerable); + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.BCL.EnumerableScenario.IService), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.BCL.EnumerableScenario.IService Resolve(Composition composition) + { + return composition.Root; + } + + public Pure.DI.UsageTests.BCL.EnumerableScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.Root; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.BCL.EnumerableScenario.IService."); + } + } +} + } ```
diff --git a/readme/factory.md b/readme/factory.md index f9fe432ad..227a46334 100644 --- a/readme/factory.md +++ b/readme/factory.md @@ -54,27 +54,27 @@ service.Dependency.IsInitialized.ShouldBeTrue(); ```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 Dependency { - +Dependency(DateTimeOffset time) - } - class DateTimeOffset - Service --|> IService : - class Service { - +Service(IDependency dependency) - } - class IService { - <> - } - Dependency *-- DateTimeOffset : DateTimeOffset - Service *-- Dependency : IDependency - Composition ..> Service : IService Root + class Composition { + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + class Dependency { + +Dependency(DateTimeOffset time) + } + class DateTimeOffset + Service --|> IService : + class Service { + +Service(IDependency dependency) + } + class IService { + <> + } + Dependency *-- DateTimeOffset : DateTimeOffset + Service *-- Dependency : IDependency + Composition ..> Service : IService Root ``` @@ -83,173 +83,173 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; + +public Composition() { - private readonly Composition _rootM04D27di; - - public Composition() - { - _rootM04D27di = this; - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - } - - public Pure.DI.UsageTests.Basics.FactoryScenario.IService Root - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - System.DateTimeOffset transientM04D27di3_DateTimeOffset = DateTimeOffset.Now; - Pure.DI.UsageTests.Basics.FactoryScenario.Dependency transientM04D27di1_Dependency; - { - var dependency_M04D27di1 = new Pure.DI.UsageTests.Basics.FactoryScenario.Dependency(transientM04D27di3_DateTimeOffset); - dependency_M04D27di1.Initialize(); - transientM04D27di1_Dependency = dependency_M04D27di1; - } - return new Pure.DI.UsageTests.Basics.FactoryScenario.Service(transientM04D27di1_Dependency); - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Basics.FactoryScenario.IService), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Basics.FactoryScenario.IService Resolve(Composition composition) - { - return composition.Root; - } - - public Pure.DI.UsageTests.Basics.FactoryScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.Root; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Basics.FactoryScenario.IService."); - } - } - } + _rootM04D27di = this; +} + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; +} + +public Pure.DI.UsageTests.Basics.FactoryScenario.IService Root +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + System.DateTimeOffset transientM04D27di3_DateTimeOffset = DateTimeOffset.Now; + Pure.DI.UsageTests.Basics.FactoryScenario.Dependency transientM04D27di1_Dependency; + { + var dependency_M04D27di1 = new Pure.DI.UsageTests.Basics.FactoryScenario.Dependency(transientM04D27di3_DateTimeOffset); + dependency_M04D27di1.Initialize(); + transientM04D27di1_Dependency = dependency_M04D27di1; + } + return new Pure.DI.UsageTests.Basics.FactoryScenario.Service(transientM04D27di1_Dependency); + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Basics.FactoryScenario.IService), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.Basics.FactoryScenario.IService Resolve(Composition composition) + { + return composition.Root; + } + + public Pure.DI.UsageTests.Basics.FactoryScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.Root; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Basics.FactoryScenario.IService."); + } + } } + } ```
diff --git a/readme/field-injection.md b/readme/field-injection.md index 108a98f4b..8200c354f 100644 --- a/readme/field-injection.md +++ b/readme/field-injection.md @@ -39,30 +39,30 @@ service.Dependency.ShouldBeOfType(); ```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 : - class Dependency { - +Dependency() - } - Service --|> IService : - class Service { - +Service() - ~IDependency DependencyVal - } - class IDependency { - <> - } - class IService { - <> - } - Service *-- Dependency : IDependency - Composition ..> Service : IService Root + class Composition { + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + Dependency --|> IDependency : + class Dependency { + +Dependency() + } + Service --|> IService : + class Service { + +Service() + ~IDependency DependencyVal + } + class IDependency { + <> + } + class IService { + <> + } + Service *-- Dependency : IDependency + Composition ..> Service : IService Root ``` @@ -71,171 +71,171 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; + +public Composition() { - private readonly Composition _rootM04D27di; - - public Composition() - { - _rootM04D27di = this; - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - } - - public Pure.DI.UsageTests.Basics.FieldInjectionScenario.IService Root - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - Pure.DI.UsageTests.Basics.FieldInjectionScenario.Service transientM04D27di0_Service = new Pure.DI.UsageTests.Basics.FieldInjectionScenario.Service(); - transientM04D27di0_Service.DependencyVal = new Pure.DI.UsageTests.Basics.FieldInjectionScenario.Dependency(); - return transientM04D27di0_Service; - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Basics.FieldInjectionScenario.IService), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Basics.FieldInjectionScenario.IService Resolve(Composition composition) - { - return composition.Root; - } - - public Pure.DI.UsageTests.Basics.FieldInjectionScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.Root; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Basics.FieldInjectionScenario.IService."); - } - } - } + _rootM04D27di = this; } + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; +} + +public Pure.DI.UsageTests.Basics.FieldInjectionScenario.IService Root +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + Pure.DI.UsageTests.Basics.FieldInjectionScenario.Service transientM04D27di0_Service = new Pure.DI.UsageTests.Basics.FieldInjectionScenario.Service(); + transientM04D27di0_Service.DependencyVal = new Pure.DI.UsageTests.Basics.FieldInjectionScenario.Dependency(); + return transientM04D27di0_Service; + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Basics.FieldInjectionScenario.IService), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.Basics.FieldInjectionScenario.IService Resolve(Composition composition) + { + return composition.Root; + } + + public Pure.DI.UsageTests.Basics.FieldInjectionScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.Root; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Basics.FieldInjectionScenario.IService."); + } + } +} + } ```
diff --git a/readme/func-with-arguments.md b/readme/func-with-arguments.md index 94e29f4e1..0b93c1891 100644 --- a/readme/func-with-arguments.md +++ b/readme/func-with-arguments.md @@ -70,37 +70,37 @@ service.Dependencies[3].Id.ShouldBe(3); ```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 Dependency { - +Dependency(IClock clock, Int32 id) - } - class Int32 - class FuncᐸInt32ˏIDependencyᐳ - Clock --|> IClock : - class Clock { - +Clock() - } - Service --|> IService : - class Service { - +Service(FuncᐸInt32ˏIDependencyᐳ dependencyFactory) - } - class IClock { - <> - } - class IService { - <> - } - Dependency o-- "Singleton" Clock : IClock - Dependency *-- Int32 : Int32 - FuncᐸInt32ˏIDependencyᐳ *-- Dependency : Dependency - Service *-- FuncᐸInt32ˏIDependencyᐳ : FuncᐸInt32ˏIDependencyᐳ - Composition ..> Service : IService Root + class Composition { + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + class Dependency { + +Dependency(IClock clock, Int32 id) + } + class Int32 + class FuncᐸInt32ˏIDependencyᐳ + Clock --|> IClock : + class Clock { + +Clock() + } + Service --|> IService : + class Service { + +Service(FuncᐸInt32ˏIDependencyᐳ dependencyFactory) + } + class IClock { + <> + } + class IService { + <> + } + Dependency o-- "Singleton" Clock : IClock + Dependency *-- Int32 : Int32 + FuncᐸInt32ˏIDependencyᐳ *-- Dependency : Dependency + Service *-- FuncᐸInt32ˏIDependencyᐳ : FuncᐸInt32ˏIDependencyᐳ + Composition ..> Service : IService Root ``` @@ -109,197 +109,197 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; +private readonly object _lockM04D27di; +private Pure.DI.UsageTests.BCL.FuncWithArgumentsScenario.Clock _singletonM04D27di36_Clock; + +public Composition() { - private readonly Composition _rootM04D27di; - private readonly object _lockM04D27di; - private Pure.DI.UsageTests.BCL.FuncWithArgumentsScenario.Clock _singletonM04D27di36_Clock; - - public Composition() - { - _rootM04D27di = this; - _lockM04D27di = new object(); - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - _lockM04D27di = _rootM04D27di._lockM04D27di; - } - - public Pure.DI.UsageTests.BCL.FuncWithArgumentsScenario.IService Root - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - System.Func transientM04D27di1_Func = dependencyId => - { - int transientM04D27di3_Int32 = dependencyId; - if (_rootM04D27di._singletonM04D27di36_Clock == null) - { - lock (_lockM04D27di) - { - if (_rootM04D27di._singletonM04D27di36_Clock == null) - { - _singletonM04D27di36_Clock = new Pure.DI.UsageTests.BCL.FuncWithArgumentsScenario.Clock(); - _rootM04D27di._singletonM04D27di36_Clock = _singletonM04D27di36_Clock; - } - } - } - var dependency_M04D27di1 = new Pure.DI.UsageTests.BCL.FuncWithArgumentsScenario.Dependency(_rootM04D27di._singletonM04D27di36_Clock, transientM04D27di3_Int32); - return dependency_M04D27di1; - }; - return new Pure.DI.UsageTests.BCL.FuncWithArgumentsScenario.Service(transientM04D27di1_Func); - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.BCL.FuncWithArgumentsScenario.IService), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.BCL.FuncWithArgumentsScenario.IService Resolve(Composition composition) - { - return composition.Root; - } - - public Pure.DI.UsageTests.BCL.FuncWithArgumentsScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.Root; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.BCL.FuncWithArgumentsScenario.IService."); - } - } - } + _rootM04D27di = this; + _lockM04D27di = new object(); } + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; + _lockM04D27di = _rootM04D27di._lockM04D27di; +} + +public Pure.DI.UsageTests.BCL.FuncWithArgumentsScenario.IService Root +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + System.Func transientM04D27di1_Func = dependencyId => + { + int transientM04D27di3_Int32 = dependencyId; + if (_rootM04D27di._singletonM04D27di36_Clock == null) + { + lock (_lockM04D27di) + { + if (_rootM04D27di._singletonM04D27di36_Clock == null) + { + _singletonM04D27di36_Clock = new Pure.DI.UsageTests.BCL.FuncWithArgumentsScenario.Clock(); + _rootM04D27di._singletonM04D27di36_Clock = _singletonM04D27di36_Clock; + } + } + } + var dependency_M04D27di1 = new Pure.DI.UsageTests.BCL.FuncWithArgumentsScenario.Dependency(_rootM04D27di._singletonM04D27di36_Clock, transientM04D27di3_Int32); + return dependency_M04D27di1; + }; + return new Pure.DI.UsageTests.BCL.FuncWithArgumentsScenario.Service(transientM04D27di1_Func); + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.BCL.FuncWithArgumentsScenario.IService), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.BCL.FuncWithArgumentsScenario.IService Resolve(Composition composition) + { + return composition.Root; + } + + public Pure.DI.UsageTests.BCL.FuncWithArgumentsScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.Root; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.BCL.FuncWithArgumentsScenario.IService."); + } + } +} + } ```
diff --git a/readme/func-with-tag.md b/readme/func-with-tag.md index e1d513469..d9d2f1031 100644 --- a/readme/func-with-tag.md +++ b/readme/func-with-tag.md @@ -40,31 +40,31 @@ service.Dependencies.Length.ShouldBe(10); ```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 : "my tag" - class Dependency { - +Dependency() - } - Service --|> IService : - class Service { - +Service(FuncᐸIDependencyᐳ dependencyFactory) - } - class FuncᐸIDependencyᐳ - class IDependency { - <> - } - class IService { - <> - } - Service o-- "PerResolve" FuncᐸIDependencyᐳ : "my tag" FuncᐸIDependencyᐳ - Composition ..> Service : IService Root - FuncᐸIDependencyᐳ *-- Dependency : "my tag" IDependency + class Composition { + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + Dependency --|> IDependency : "my tag" + class Dependency { + +Dependency() + } + Service --|> IService : + class Service { + +Service(FuncᐸIDependencyᐳ dependencyFactory) + } + class FuncᐸIDependencyᐳ + class IDependency { + <> + } + class IService { + <> + } + Service o-- "PerResolve" FuncᐸIDependencyᐳ : "my tag" FuncᐸIDependencyᐳ + Composition ..> Service : IService Root + FuncᐸIDependencyᐳ *-- Dependency : "my tag" IDependency ``` @@ -73,181 +73,181 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; +private readonly object _lockM04D27di; + +public Composition() { - private readonly Composition _rootM04D27di; - private readonly object _lockM04D27di; - - public Composition() - { - _rootM04D27di = this; - _lockM04D27di = new object(); - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - _lockM04D27di = _rootM04D27di._lockM04D27di; - } - - public Pure.DI.UsageTests.BCL.FuncWithTagScenario.IService Root - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - var perResolveM04D27di39_Func = default(System.Func); - perResolveM04D27di39_Func = new global::System.Func( - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)768)] - () => - { - var value_M04D27di1 = new Pure.DI.UsageTests.BCL.FuncWithTagScenario.Dependency(); - return value_M04D27di1; - }); - return new Pure.DI.UsageTests.BCL.FuncWithTagScenario.Service(perResolveM04D27di39_Func); - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.BCL.FuncWithTagScenario.IService), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.BCL.FuncWithTagScenario.IService Resolve(Composition composition) - { - return composition.Root; - } - - public Pure.DI.UsageTests.BCL.FuncWithTagScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.Root; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.BCL.FuncWithTagScenario.IService."); - } - } - } + _rootM04D27di = this; + _lockM04D27di = new object(); } + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; + _lockM04D27di = _rootM04D27di._lockM04D27di; +} + +public Pure.DI.UsageTests.BCL.FuncWithTagScenario.IService Root +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + var perResolveM04D27di39_Func = default(System.Func); + perResolveM04D27di39_Func = new global::System.Func( + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)768)] + () => + { + var value_M04D27di1 = new Pure.DI.UsageTests.BCL.FuncWithTagScenario.Dependency(); + return value_M04D27di1; + }); + return new Pure.DI.UsageTests.BCL.FuncWithTagScenario.Service(perResolveM04D27di39_Func); + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.BCL.FuncWithTagScenario.IService), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.BCL.FuncWithTagScenario.IService Resolve(Composition composition) + { + return composition.Root; + } + + public Pure.DI.UsageTests.BCL.FuncWithTagScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.Root; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.BCL.FuncWithTagScenario.IService."); + } + } +} + } ```
diff --git a/readme/func.md b/readme/func.md index fde3241de..0eefacb3f 100644 --- a/readme/func.md +++ b/readme/func.md @@ -43,31 +43,31 @@ Be careful, replication takes into account the lifetime of the object. ```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 : - class Dependency { - +Dependency() - } - Service --|> IService : - class Service { - +Service(FuncᐸIDependencyᐳ dependencyFactory) - } - class FuncᐸIDependencyᐳ - class IDependency { - <> - } - class IService { - <> - } - Service o-- "PerResolve" FuncᐸIDependencyᐳ : FuncᐸIDependencyᐳ - Composition ..> Service : IService Root - FuncᐸIDependencyᐳ *-- Dependency : IDependency + class Composition { + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + Dependency --|> IDependency : + class Dependency { + +Dependency() + } + Service --|> IService : + class Service { + +Service(FuncᐸIDependencyᐳ dependencyFactory) + } + class FuncᐸIDependencyᐳ + class IDependency { + <> + } + class IService { + <> + } + Service o-- "PerResolve" FuncᐸIDependencyᐳ : FuncᐸIDependencyᐳ + Composition ..> Service : IService Root + FuncᐸIDependencyᐳ *-- Dependency : IDependency ``` @@ -76,181 +76,181 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; +private readonly object _lockM04D27di; + +public Composition() { - private readonly Composition _rootM04D27di; - private readonly object _lockM04D27di; - - public Composition() - { - _rootM04D27di = this; - _lockM04D27di = new object(); - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - _lockM04D27di = _rootM04D27di._lockM04D27di; - } - - public Pure.DI.UsageTests.BCL.FuncScenario.IService Root - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - var perResolveM04D27di39_Func = default(System.Func); - perResolveM04D27di39_Func = new global::System.Func( - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)768)] - () => - { - var value_M04D27di1 = new Pure.DI.UsageTests.BCL.FuncScenario.Dependency(); - return value_M04D27di1; - }); - return new Pure.DI.UsageTests.BCL.FuncScenario.Service(perResolveM04D27di39_Func); - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.BCL.FuncScenario.IService), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.BCL.FuncScenario.IService Resolve(Composition composition) - { - return composition.Root; - } - - public Pure.DI.UsageTests.BCL.FuncScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.Root; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.BCL.FuncScenario.IService."); - } - } - } + _rootM04D27di = this; + _lockM04D27di = new object(); } + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; + _lockM04D27di = _rootM04D27di._lockM04D27di; +} + +public Pure.DI.UsageTests.BCL.FuncScenario.IService Root +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + var perResolveM04D27di39_Func = default(System.Func); + perResolveM04D27di39_Func = new global::System.Func( + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)768)] + () => + { + var value_M04D27di1 = new Pure.DI.UsageTests.BCL.FuncScenario.Dependency(); + return value_M04D27di1; + }); + return new Pure.DI.UsageTests.BCL.FuncScenario.Service(perResolveM04D27di39_Func); + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.BCL.FuncScenario.IService), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.BCL.FuncScenario.IService Resolve(Composition composition) + { + return composition.Root; + } + + public Pure.DI.UsageTests.BCL.FuncScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.Root; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.BCL.FuncScenario.IService."); + } + } +} + } ```
diff --git a/readme/generic-composition-roots-with-constraints.md b/readme/generic-composition-roots-with-constraints.md index 86d384a40..4ee08cf06 100644 --- a/readme/generic-composition-roots-with-constraints.md +++ b/readme/generic-composition-roots-with-constraints.md @@ -58,33 +58,33 @@ var someOtherService = composition.GetOtherService(); ```mermaid classDiagram - class Composition { - +IServiceᐸTˏT4ᐳ GetMyRootᐸTˏT4ᐳ() - +IServiceᐸTˏBooleanᐳ GetOtherServiceᐸTᐳ() - } - ServiceᐸTˏT4ᐳ --|> IServiceᐸTˏT4ᐳ : - class ServiceᐸTˏT4ᐳ { - +Service(IDependencyᐸTᐳ dependency) - } - OtherServiceᐸTᐳ --|> IServiceᐸTˏBooleanᐳ : "Other" - class OtherServiceᐸTᐳ - DependencyᐸTᐳ --|> IDependencyᐸTᐳ : - class DependencyᐸTᐳ { - +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ᐳ() - ServiceᐸTˏT4ᐳ *-- DependencyᐸTᐳ : IDependencyᐸTᐳ - OtherServiceᐸTᐳ *-- DependencyᐸTᐳ : IDependencyᐸTᐳ + class Composition { + +IServiceᐸTˏT4ᐳ GetMyRootᐸTˏT4ᐳ() + +IServiceᐸTˏBooleanᐳ GetOtherServiceᐸTᐳ() + } + ServiceᐸTˏT4ᐳ --|> IServiceᐸTˏT4ᐳ : + class ServiceᐸTˏT4ᐳ { + +Service(IDependencyᐸTᐳ dependency) + } + OtherServiceᐸTᐳ --|> IServiceᐸTˏBooleanᐳ : "Other" + class OtherServiceᐸTᐳ + DependencyᐸTᐳ --|> IDependencyᐸTᐳ : + class DependencyᐸTᐳ { + +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ᐳ() + ServiceᐸTˏT4ᐳ *-- DependencyᐸTᐳ : IDependencyᐸTᐳ + OtherServiceᐸTᐳ *-- DependencyᐸTᐳ : IDependencyᐸTᐳ ``` @@ -93,74 +93,74 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; + +public Composition() { - private readonly Composition _rootM04D27di; - - public Composition() - { - _rootM04D27di = this; - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public Pure.DI.UsageTests.Generics.GenericCompositionRootsWithConstraintsScenario.IService GetMyRoot() - where T: System.IDisposable - where T4: struct - { - return new Pure.DI.UsageTests.Generics.GenericCompositionRootsWithConstraintsScenario.Service(new Pure.DI.UsageTests.Generics.GenericCompositionRootsWithConstraintsScenario.Dependency()); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public Pure.DI.UsageTests.Generics.GenericCompositionRootsWithConstraintsScenario.IService GetOtherService() - where T: System.IDisposable - { - Pure.DI.UsageTests.Generics.GenericCompositionRootsWithConstraintsScenario.OtherService transientM04D27di0_OtherService; - { - var dependency_M04D27di1 = new Pure.DI.UsageTests.Generics.GenericCompositionRootsWithConstraintsScenario.Dependency(); - transientM04D27di0_OtherService = new OtherService(dependency_M04D27di1); - } - return transientM04D27di0_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ᐳ"; - } - + _rootM04D27di = this; +} + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public Pure.DI.UsageTests.Generics.GenericCompositionRootsWithConstraintsScenario.IService GetMyRoot() + where T: System.IDisposable + where T4: struct +{ + return new Pure.DI.UsageTests.Generics.GenericCompositionRootsWithConstraintsScenario.Service(new Pure.DI.UsageTests.Generics.GenericCompositionRootsWithConstraintsScenario.Dependency()); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public Pure.DI.UsageTests.Generics.GenericCompositionRootsWithConstraintsScenario.IService GetOtherService() + where T: System.IDisposable +{ + Pure.DI.UsageTests.Generics.GenericCompositionRootsWithConstraintsScenario.OtherService transientM04D27di0_OtherService; + { + var dependency_M04D27di1 = new Pure.DI.UsageTests.Generics.GenericCompositionRootsWithConstraintsScenario.Dependency(); + transientM04D27di0_OtherService = new OtherService(dependency_M04D27di1); + } + return transientM04D27di0_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 60db1b316..e4dc8bfa1 100644 --- a/readme/generic-composition-roots.md +++ b/readme/generic-composition-roots.md @@ -55,30 +55,30 @@ When a generic composition root is used, `Resolve` methods cannot be used to res ```mermaid classDiagram - class Composition { - +IServiceᐸT54ᐳ GetMyRootᐸT54ᐳ() - +IServiceᐸT54ᐳ GetOtherServiceᐸT54ᐳ() - } - ServiceᐸT54ᐳ --|> IServiceᐸT54ᐳ : - class ServiceᐸT54ᐳ { - +Service(IDependencyᐸT54ᐳ dependency) - } - OtherServiceᐸT54ᐳ --|> IServiceᐸT54ᐳ : "Other" - class OtherServiceᐸT54ᐳ - DependencyᐸT54ᐳ --|> IDependencyᐸT54ᐳ : - class DependencyᐸT54ᐳ { - +Dependency() - } - class IServiceᐸT54ᐳ { - <> - } - class IDependencyᐸT54ᐳ { - <> - } - Composition ..> ServiceᐸT54ᐳ : IServiceᐸT54ᐳ GetMyRootᐸT54ᐳ() - Composition ..> OtherServiceᐸT54ᐳ : IServiceᐸT54ᐳ GetOtherServiceᐸT54ᐳ() - ServiceᐸT54ᐳ *-- DependencyᐸT54ᐳ : IDependencyᐸT54ᐳ - OtherServiceᐸT54ᐳ *-- DependencyᐸT54ᐳ : IDependencyᐸT54ᐳ + class Composition { + +IServiceᐸT54ᐳ GetMyRootᐸT54ᐳ() + +IServiceᐸT54ᐳ GetOtherServiceᐸT54ᐳ() + } + ServiceᐸT54ᐳ --|> IServiceᐸT54ᐳ : + class ServiceᐸT54ᐳ { + +Service(IDependencyᐸT54ᐳ dependency) + } + OtherServiceᐸT54ᐳ --|> IServiceᐸT54ᐳ : "Other" + class OtherServiceᐸT54ᐳ + DependencyᐸT54ᐳ --|> IDependencyᐸT54ᐳ : + class DependencyᐸT54ᐳ { + +Dependency() + } + class IServiceᐸT54ᐳ { + <> + } + class IDependencyᐸT54ᐳ { + <> + } + Composition ..> ServiceᐸT54ᐳ : IServiceᐸT54ᐳ GetMyRootᐸT54ᐳ() + Composition ..> OtherServiceᐸT54ᐳ : IServiceᐸT54ᐳ GetOtherServiceᐸT54ᐳ() + ServiceᐸT54ᐳ *-- DependencyᐸT54ᐳ : IDependencyᐸT54ᐳ + OtherServiceᐸT54ᐳ *-- DependencyᐸT54ᐳ : IDependencyᐸT54ᐳ ``` @@ -87,68 +87,68 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; + +public Composition() { - private readonly Composition _rootM04D27di; - - public Composition() - { - _rootM04D27di = this; - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public Pure.DI.UsageTests.Generics.GenericsCompositionRootsScenario.IService GetMyRoot() - { - return new Pure.DI.UsageTests.Generics.GenericsCompositionRootsScenario.Service(new Pure.DI.UsageTests.Generics.GenericsCompositionRootsScenario.Dependency()); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public Pure.DI.UsageTests.Generics.GenericsCompositionRootsScenario.IService GetOtherService() - { - Pure.DI.UsageTests.Generics.GenericsCompositionRootsScenario.OtherService transientM04D27di0_OtherService; - { - var dependency_M04D27di1 = new Pure.DI.UsageTests.Generics.GenericsCompositionRootsScenario.Dependency(); - transientM04D27di0_OtherService = new OtherService(dependency_M04D27di1); - } - return transientM04D27di0_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ᐳ"; - } - + _rootM04D27di = this; +} + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public Pure.DI.UsageTests.Generics.GenericsCompositionRootsScenario.IService GetMyRoot() +{ + return new Pure.DI.UsageTests.Generics.GenericsCompositionRootsScenario.Service(new Pure.DI.UsageTests.Generics.GenericsCompositionRootsScenario.Dependency()); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public Pure.DI.UsageTests.Generics.GenericsCompositionRootsScenario.IService GetOtherService() +{ + Pure.DI.UsageTests.Generics.GenericsCompositionRootsScenario.OtherService transientM04D27di0_OtherService; + { + var dependency_M04D27di1 = new Pure.DI.UsageTests.Generics.GenericsCompositionRootsScenario.Dependency(); + transientM04D27di0_OtherService = new OtherService(dependency_M04D27di1); + } + return transientM04D27di0_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 9d8de11b2..181511689 100644 --- a/readme/generics.md +++ b/readme/generics.md @@ -55,37 +55,37 @@ public IService Root ```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 { - +Service(IDependencyᐸInt32ᐳ intDependency, IDependencyᐸStringᐳ stringDependency) - } - DependencyᐸInt32ᐳ --|> IDependencyᐸInt32ᐳ : - class DependencyᐸInt32ᐳ { - +Dependency() - } - DependencyᐸStringᐳ --|> IDependencyᐸStringᐳ : - class DependencyᐸStringᐳ { - +Dependency() - } - class IService { - <> - } - class IDependencyᐸInt32ᐳ { - <> - } - class IDependencyᐸStringᐳ { - <> - } - Service *-- DependencyᐸInt32ᐳ : IDependencyᐸInt32ᐳ - Service *-- DependencyᐸStringᐳ : IDependencyᐸStringᐳ - Composition ..> Service : IService Root + 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 { + +Service(IDependencyᐸInt32ᐳ intDependency, IDependencyᐸStringᐳ stringDependency) + } + DependencyᐸInt32ᐳ --|> IDependencyᐸInt32ᐳ : + class DependencyᐸInt32ᐳ { + +Dependency() + } + DependencyᐸStringᐳ --|> IDependencyᐸStringᐳ : + class DependencyᐸStringᐳ { + +Dependency() + } + class IService { + <> + } + class IDependencyᐸInt32ᐳ { + <> + } + class IDependencyᐸStringᐳ { + <> + } + Service *-- DependencyᐸInt32ᐳ : IDependencyᐸInt32ᐳ + Service *-- DependencyᐸStringᐳ : IDependencyᐸStringᐳ + Composition ..> Service : IService Root ``` @@ -94,176 +94,176 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; + +public Composition() { - private readonly Composition _rootM04D27di; - - public Composition() - { - _rootM04D27di = this; - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - } - - public Pure.DI.UsageTests.Generics.GenericsScenario.IService Root - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - return new Pure.DI.UsageTests.Generics.GenericsScenario.Service(new Pure.DI.UsageTests.Generics.GenericsScenario.Dependency(), new Pure.DI.UsageTests.Generics.GenericsScenario.Dependency()); - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Generics.GenericsScenario.IService), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Generics.GenericsScenario.IService Resolve(Composition composition) - { - return composition.Root; - } - - public Pure.DI.UsageTests.Generics.GenericsScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.Root; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Generics.GenericsScenario.IService."); - } - } - } + _rootM04D27di = this; +} + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; +} + +public Pure.DI.UsageTests.Generics.GenericsScenario.IService Root +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + return new Pure.DI.UsageTests.Generics.GenericsScenario.Service(new Pure.DI.UsageTests.Generics.GenericsScenario.Dependency(), new Pure.DI.UsageTests.Generics.GenericsScenario.Dependency()); + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Generics.GenericsScenario.IService), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.Generics.GenericsScenario.IService Resolve(Composition composition) + { + return composition.Root; + } + + public Pure.DI.UsageTests.Generics.GenericsScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.Root; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Generics.GenericsScenario.IService."); + } + } } + } ```
diff --git a/readme/injection.md b/readme/injection.md index 7039802a1..a3309441a 100644 --- a/readme/injection.md +++ b/readme/injection.md @@ -42,27 +42,27 @@ In addition to the dependency type, you can specify the dependency tag in the fi ```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 + 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 ``` @@ -71,171 +71,171 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; + +public Composition() { - private readonly Composition _rootM04D27di; - - public Composition() - { - _rootM04D27di = this; - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - } - - public Pure.DI.UsageTests.Basics.InjectionScenario.IService Root - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - Pure.DI.UsageTests.Basics.InjectionScenario.Service transientM04D27di0_Service; - { - var dependency_M04D27di1 = new Pure.DI.UsageTests.Basics.InjectionScenario.Dependency(); - transientM04D27di0_Service = new Service(dependency_M04D27di1); - } - return transientM04D27di0_Service; - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Basics.InjectionScenario.IService), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Basics.InjectionScenario.IService Resolve(Composition composition) - { - return composition.Root; - } - - public Pure.DI.UsageTests.Basics.InjectionScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.Root; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Basics.InjectionScenario.IService."); - } - } - } + _rootM04D27di = this; } + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; +} + +public Pure.DI.UsageTests.Basics.InjectionScenario.IService Root +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + Pure.DI.UsageTests.Basics.InjectionScenario.Service transientM04D27di0_Service; + { + var dependency_M04D27di1 = new Pure.DI.UsageTests.Basics.InjectionScenario.Dependency(); + transientM04D27di0_Service = new Service(dependency_M04D27di1); + } + return transientM04D27di0_Service; + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Basics.InjectionScenario.IService), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.Basics.InjectionScenario.IService Resolve(Composition composition) + { + return composition.Root; + } + + public Pure.DI.UsageTests.Basics.InjectionScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.Root; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Basics.InjectionScenario.IService."); + } + } +} + } ```
diff --git a/readme/injections-of-abstractions.md b/readme/injections-of-abstractions.md index 8960bbbda..6a696deda 100644 --- a/readme/injections-of-abstractions.md +++ b/readme/injections-of-abstractions.md @@ -46,29 +46,29 @@ root.Run(); ```mermaid classDiagram - class Composition { - +Program Root - } - class Program { - +Program(IService service) - } - Dependency --|> IDependency : - class Dependency { - +Dependency() - } - Service --|> IService : - class Service { - +Service(IDependency dependency) - } - class IDependency { - <> - } - class IService { - <> - } - Program *-- Service : IService - Service *-- Dependency : IDependency - Composition ..> Program : Program Root + class Composition { + +Program Root + } + class Program { + +Program(IService service) + } + Dependency --|> IDependency : + class Dependency { + +Dependency() + } + Service --|> IService : + class Service { + +Service(IDependency dependency) + } + class IDependency { + <> + } + class IService { + <> + } + Program *-- Service : IService + Service *-- Dependency : IDependency + Composition ..> Program : Program Root ``` @@ -77,59 +77,59 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; + +public Composition() { - private readonly Composition _rootM04D27di; - - public Composition() - { - _rootM04D27di = this; - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - } - - public Pure.DI.UsageTests.Basics.InjectionsOfAbstractionsScenario.Program Root - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - return new Pure.DI.UsageTests.Basics.InjectionsOfAbstractionsScenario.Program(new Pure.DI.UsageTests.Basics.InjectionsOfAbstractionsScenario.Service(new Pure.DI.UsageTests.Basics.InjectionsOfAbstractionsScenario.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"; - } - + _rootM04D27di = this; } + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; +} + +public Pure.DI.UsageTests.Basics.InjectionsOfAbstractionsScenario.Program Root +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + return new Pure.DI.UsageTests.Basics.InjectionsOfAbstractionsScenario.Program(new Pure.DI.UsageTests.Basics.InjectionsOfAbstractionsScenario.Service(new Pure.DI.UsageTests.Basics.InjectionsOfAbstractionsScenario.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 index 974ffde7a..5832e54ae 100644 --- a/readme/instance-initialization.md +++ b/readme/instance-initialization.md @@ -58,27 +58,27 @@ service.IsInitialized.ShouldBeTrue(); ```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 + 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 ``` @@ -87,181 +87,181 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; + +private readonly string _argM04D27di_serviceName; + +public Composition(string serviceName) { - private readonly Composition _rootM04D27di; - - private readonly string _argM04D27di_serviceName; - - public Composition(string serviceName) - { - _rootM04D27di = this; - if (ReferenceEquals(serviceName, null)) - { - throw new global::System.ArgumentNullException("serviceName"); - } - - _argM04D27di_serviceName = serviceName; - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - _argM04D27di_serviceName = baseComposition._argM04D27di_serviceName; - } - - public Pure.DI.UsageTests.Advanced.InstanceInitializationScenario.IService Root - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - Pure.DI.UsageTests.Advanced.InstanceInitializationScenario.Service transientM04D27di0_Service; - { - var service_M04D27di1 = new Pure.DI.UsageTests.Advanced.InstanceInitializationScenario.Service(_argM04D27di_serviceName, new Pure.DI.UsageTests.Advanced.InstanceInitializationScenario.Dependency()); - service_M04D27di1.Initialize(); - transientM04D27di0_Service = service_M04D27di1; - } - return transientM04D27di0_Service; - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Advanced.InstanceInitializationScenario.IService), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Advanced.InstanceInitializationScenario.IService Resolve(Composition composition) - { - return composition.Root; - } - - public Pure.DI.UsageTests.Advanced.InstanceInitializationScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.Root; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Advanced.InstanceInitializationScenario.IService."); - } - } - } + _rootM04D27di = this; + if (ReferenceEquals(serviceName, null)) + { + throw new global::System.ArgumentNullException("serviceName"); + } + + _argM04D27di_serviceName = serviceName; } + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; + _argM04D27di_serviceName = baseComposition._argM04D27di_serviceName; +} + +public Pure.DI.UsageTests.Advanced.InstanceInitializationScenario.IService Root +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + Pure.DI.UsageTests.Advanced.InstanceInitializationScenario.Service transientM04D27di0_Service; + { + var service_M04D27di1 = new Pure.DI.UsageTests.Advanced.InstanceInitializationScenario.Service(_argM04D27di_serviceName, new Pure.DI.UsageTests.Advanced.InstanceInitializationScenario.Dependency()); + service_M04D27di1.Initialize(); + transientM04D27di0_Service = service_M04D27di1; + } + return transientM04D27di0_Service; + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Advanced.InstanceInitializationScenario.IService), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.Advanced.InstanceInitializationScenario.IService Resolve(Composition composition) + { + return composition.Root; + } + + public Pure.DI.UsageTests.Advanced.InstanceInitializationScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.Root; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Advanced.InstanceInitializationScenario.IService."); + } + } +} + } ```
diff --git a/readme/interception.md b/readme/interception.md index 98581991f..d6ce0b456 100644 --- a/readme/interception.md +++ b/readme/interception.md @@ -58,21 +58,21 @@ service.GetMessage().ShouldBe("Hello World !!!"); ```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 { - +Service() - } - class IService { - <> - } - Composition ..> Service : IService Root + 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 { + +Service() + } + class IService { + <> + } + Composition ..> Service : IService Root ``` @@ -81,162 +81,162 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; + +public Composition() { - private readonly Composition _rootM04D27di; - - public Composition() - { - _rootM04D27di = this; - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - } - - public Pure.DI.UsageTests.Interception.InterceptionScenario.IService Root - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - return OnDependencyInjection(new Pure.DI.UsageTests.Interception.InterceptionScenario.Service(), null, Pure.DI.Lifetime.Transient); - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {type}."); - } - - private partial T OnDependencyInjection(in T value, object? tag, global::Pure.DI.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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Interception.InterceptionScenario.IService), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Interception.InterceptionScenario.IService Resolve(Composition composition) - { - return composition.Root; - } - - public Pure.DI.UsageTests.Interception.InterceptionScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.Root; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Interception.InterceptionScenario.IService."); - } - } - } + _rootM04D27di = this; +} + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; +} + +public Pure.DI.UsageTests.Interception.InterceptionScenario.IService Root +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + return OnDependencyInjection(new Pure.DI.UsageTests.Interception.InterceptionScenario.Service(), null, Pure.DI.Lifetime.Transient); + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {type}."); +} + +private partial T OnDependencyInjection(in T value, object? tag, global::Pure.DI.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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Interception.InterceptionScenario.IService), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.Interception.InterceptionScenario.IService Resolve(Composition composition) + { + return composition.Root; + } + + public Pure.DI.UsageTests.Interception.InterceptionScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.Root; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Interception.InterceptionScenario.IService."); + } + } } + } ```
diff --git a/readme/keyed-service-provider.md b/readme/keyed-service-provider.md index 8720f445d..7db5baef3 100644 --- a/readme/keyed-service-provider.md +++ b/readme/keyed-service-provider.md @@ -49,31 +49,31 @@ service.Dependency.ShouldBe(dependency); ```mermaid classDiagram - class Composition { - -IDependency _ - -IService _ - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object GetService(Type type) - + object GetRequiredKeyedService(Type type, object? tag) - } - Dependency --|> IDependency : "Dependency Key" - class Dependency { - +Dependency() - } - Service --|> IService : "Service Key" - class Service { - +Service(IDependency dependency) - } - class IDependency { - <> - } - class IService { - <> - } - Service o-- "Singleton" Dependency : "Dependency Key" IDependency - Composition ..> Dependency : IDependency _ - Composition ..> Service : IService _ + class Composition { + -IDependency _ + -IService _ + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object GetService(Type type) + + object GetRequiredKeyedService(Type type, object? tag) + } + Dependency --|> IDependency : "Dependency Key" + class Dependency { + +Dependency() + } + Service --|> IService : "Service Key" + class Service { + +Service(IDependency dependency) + } + class IDependency { + <> + } + class IService { + <> + } + Service o-- "Singleton" Dependency : "Dependency Key" IDependency + Composition ..> Dependency : IDependency _ + Composition ..> Service : IService _ ``` @@ -82,227 +82,227 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; +private readonly object _lockM04D27di; +private Pure.DI.UsageTests.BCL.KeyedServiceProviderScenario.Dependency _singletonM04D27di36_Dependency; + +public Composition() { - private readonly Composition _rootM04D27di; - private readonly object _lockM04D27di; - private Pure.DI.UsageTests.BCL.KeyedServiceProviderScenario.Dependency _singletonM04D27di36_Dependency; - - public Composition() - { - _rootM04D27di = this; - _lockM04D27di = new object(); - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - _lockM04D27di = _rootM04D27di._lockM04D27di; - } - - private Pure.DI.UsageTests.BCL.KeyedServiceProviderScenario.IDependency RootM04D27di0001 - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - if (_rootM04D27di._singletonM04D27di36_Dependency == null) - { - lock (_lockM04D27di) - { - if (_rootM04D27di._singletonM04D27di36_Dependency == null) - { - _singletonM04D27di36_Dependency = new Pure.DI.UsageTests.BCL.KeyedServiceProviderScenario.Dependency(); - _rootM04D27di._singletonM04D27di36_Dependency = _singletonM04D27di36_Dependency; - } - } - } - return _rootM04D27di._singletonM04D27di36_Dependency; - } - } - - private Pure.DI.UsageTests.BCL.KeyedServiceProviderScenario.IService RootM04D27di0002 - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - if (_rootM04D27di._singletonM04D27di36_Dependency == null) - { - lock (_lockM04D27di) - { - if (_rootM04D27di._singletonM04D27di36_Dependency == null) - { - _singletonM04D27di36_Dependency = new Pure.DI.UsageTests.BCL.KeyedServiceProviderScenario.Dependency(); - _rootM04D27di._singletonM04D27di36_Dependency = _singletonM04D27di36_Dependency; - } - } - } - return new Pure.DI.UsageTests.BCL.KeyedServiceProviderScenario.Service(_rootM04D27di._singletonM04D27di36_Dependency); - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object GetService(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object GetRequiredKeyedService(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - var valResolverM04D27di_0001 = new ResolverM04D27di_0001(); - ResolverM04D27di.Value = valResolverM04D27di_0001; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 4, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[2] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.BCL.KeyedServiceProviderScenario.IDependency), valResolverM04D27di_0000) - ,new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.BCL.KeyedServiceProviderScenario.IService), valResolverM04D27di_0001) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.BCL.KeyedServiceProviderScenario.IDependency Resolve(Composition composition) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type Pure.DI.UsageTests.BCL.KeyedServiceProviderScenario.IDependency."); - } - - public Pure.DI.UsageTests.BCL.KeyedServiceProviderScenario.IDependency ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case "Dependency Key": - return composition.RootM04D27di0001; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.BCL.KeyedServiceProviderScenario.IDependency."); - } - } - } - - private sealed class ResolverM04D27di_0001: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.BCL.KeyedServiceProviderScenario.IService Resolve(Composition composition) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type Pure.DI.UsageTests.BCL.KeyedServiceProviderScenario.IService."); - } - - public Pure.DI.UsageTests.BCL.KeyedServiceProviderScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case "Service Key": - return composition.RootM04D27di0002; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.BCL.KeyedServiceProviderScenario.IService."); - } - } - } + _rootM04D27di = this; + _lockM04D27di = new object(); } + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; + _lockM04D27di = _rootM04D27di._lockM04D27di; +} + +private Pure.DI.UsageTests.BCL.KeyedServiceProviderScenario.IDependency RootM04D27di0001 +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + if (_rootM04D27di._singletonM04D27di36_Dependency == null) + { + lock (_lockM04D27di) + { + if (_rootM04D27di._singletonM04D27di36_Dependency == null) + { + _singletonM04D27di36_Dependency = new Pure.DI.UsageTests.BCL.KeyedServiceProviderScenario.Dependency(); + _rootM04D27di._singletonM04D27di36_Dependency = _singletonM04D27di36_Dependency; + } + } + } + return _rootM04D27di._singletonM04D27di36_Dependency; + } +} + +private Pure.DI.UsageTests.BCL.KeyedServiceProviderScenario.IService RootM04D27di0002 +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + if (_rootM04D27di._singletonM04D27di36_Dependency == null) + { + lock (_lockM04D27di) + { + if (_rootM04D27di._singletonM04D27di36_Dependency == null) + { + _singletonM04D27di36_Dependency = new Pure.DI.UsageTests.BCL.KeyedServiceProviderScenario.Dependency(); + _rootM04D27di._singletonM04D27di36_Dependency = _singletonM04D27di36_Dependency; + } + } + } + return new Pure.DI.UsageTests.BCL.KeyedServiceProviderScenario.Service(_rootM04D27di._singletonM04D27di36_Dependency); + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object GetService(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object GetRequiredKeyedService(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + var valResolverM04D27di_0001 = new ResolverM04D27di_0001(); + ResolverM04D27di.Value = valResolverM04D27di_0001; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 4, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[2] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.BCL.KeyedServiceProviderScenario.IDependency), valResolverM04D27di_0000) + ,new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.BCL.KeyedServiceProviderScenario.IService), valResolverM04D27di_0001) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.BCL.KeyedServiceProviderScenario.IDependency Resolve(Composition composition) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type Pure.DI.UsageTests.BCL.KeyedServiceProviderScenario.IDependency."); + } + + public Pure.DI.UsageTests.BCL.KeyedServiceProviderScenario.IDependency ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case "Dependency Key": + return composition.RootM04D27di0001; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.BCL.KeyedServiceProviderScenario.IDependency."); + } + } +} + +private sealed class ResolverM04D27di_0001: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.BCL.KeyedServiceProviderScenario.IService Resolve(Composition composition) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type Pure.DI.UsageTests.BCL.KeyedServiceProviderScenario.IService."); + } + + public Pure.DI.UsageTests.BCL.KeyedServiceProviderScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case "Service Key": + return composition.RootM04D27di0002; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.BCL.KeyedServiceProviderScenario.IService."); + } + } +} + } ```
diff --git a/readme/lazy.md b/readme/lazy.md index 19bff8d58..d172e028c 100644 --- a/readme/lazy.md +++ b/readme/lazy.md @@ -34,33 +34,33 @@ service.Dependency.ShouldBe(service.Dependency); ```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 : - class Dependency { - +Dependency() - } - Service --|> IService : - class Service { - +Service(LazyᐸIDependencyᐳ dependency) - } - class LazyᐸIDependencyᐳ - class FuncᐸIDependencyᐳ - class IDependency { - <> - } - class IService { - <> - } - Service *-- LazyᐸIDependencyᐳ : LazyᐸIDependencyᐳ - Composition ..> Service : IService Root - LazyᐸIDependencyᐳ o-- "PerResolve" FuncᐸIDependencyᐳ : FuncᐸIDependencyᐳ - FuncᐸIDependencyᐳ *-- Dependency : IDependency + class Composition { + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + Dependency --|> IDependency : + class Dependency { + +Dependency() + } + Service --|> IService : + class Service { + +Service(LazyᐸIDependencyᐳ dependency) + } + class LazyᐸIDependencyᐳ + class FuncᐸIDependencyᐳ + class IDependency { + <> + } + class IService { + <> + } + Service *-- LazyᐸIDependencyᐳ : LazyᐸIDependencyᐳ + Composition ..> Service : IService Root + LazyᐸIDependencyᐳ o-- "PerResolve" FuncᐸIDependencyᐳ : FuncᐸIDependencyᐳ + FuncᐸIDependencyᐳ *-- Dependency : IDependency ``` @@ -69,188 +69,188 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; +private readonly object _lockM04D27di; + +public Composition() { - private readonly Composition _rootM04D27di; - private readonly object _lockM04D27di; - - public Composition() - { - _rootM04D27di = this; - _lockM04D27di = new object(); - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - _lockM04D27di = _rootM04D27di._lockM04D27di; - } - - public Pure.DI.UsageTests.BCL.LazyScenario.IService Root - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - var perResolveM04D27di40_Func = default(System.Func); - perResolveM04D27di40_Func = new global::System.Func( - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)768)] - () => - { - var value_M04D27di1 = new Pure.DI.UsageTests.BCL.LazyScenario.Dependency(); - return value_M04D27di1; - }); - System.Lazy transientM04D27di1_Lazy; - { - var factory_M04D27di2 = perResolveM04D27di40_Func; - transientM04D27di1_Lazy = new global::System.Lazy(factory_M04D27di2, true); - } - return new Pure.DI.UsageTests.BCL.LazyScenario.Service(transientM04D27di1_Lazy); - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.BCL.LazyScenario.IService), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.BCL.LazyScenario.IService Resolve(Composition composition) - { - return composition.Root; - } - - public Pure.DI.UsageTests.BCL.LazyScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.Root; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.BCL.LazyScenario.IService."); - } - } - } + _rootM04D27di = this; + _lockM04D27di = new object(); } + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; + _lockM04D27di = _rootM04D27di._lockM04D27di; +} + +public Pure.DI.UsageTests.BCL.LazyScenario.IService Root +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + var perResolveM04D27di40_Func = default(System.Func); + perResolveM04D27di40_Func = new global::System.Func( + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)768)] + () => + { + var value_M04D27di1 = new Pure.DI.UsageTests.BCL.LazyScenario.Dependency(); + return value_M04D27di1; + }); + System.Lazy transientM04D27di1_Lazy; + { + var factory_M04D27di2 = perResolveM04D27di40_Func; + transientM04D27di1_Lazy = new global::System.Lazy(factory_M04D27di2, true); + } + return new Pure.DI.UsageTests.BCL.LazyScenario.Service(transientM04D27di1_Lazy); + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.BCL.LazyScenario.IService), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.BCL.LazyScenario.IService Resolve(Composition composition) + { + return composition.Root; + } + + public Pure.DI.UsageTests.BCL.LazyScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.Root; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.BCL.LazyScenario.IService."); + } + } +} + } ```
diff --git a/readme/manually-started-tasks.md b/readme/manually-started-tasks.md index 81a00b4c3..1c3e73c23 100644 --- a/readme/manually-started-tasks.md +++ b/readme/manually-started-tasks.md @@ -71,36 +71,36 @@ await service.RunAsync(cancellationTokenSource.Token); ```mermaid classDiagram - class Composition { - +IService GetRoot(System.Threading.CancellationToken cancellationToken) - } - class TaskFactory - class CancellationToken - Dependency --|> IDependency : - class Dependency { - +Dependency() - } - Service --|> IService : - class Service { - +Service(TaskᐸIDependencyᐳ dependencyTask) - } - class TaskᐸIDependencyᐳ - class FuncᐸIDependencyᐳ - class IDependency { - <> - } - class IService { - <> - } - TaskFactory o-- CancellationToken : Argument "cancellationToken" - TaskFactory *-- TaskCreationOptions : TaskCreationOptions - TaskFactory *-- TaskContinuationOptions : TaskContinuationOptions - TaskFactory *-- TaskScheduler : TaskScheduler - Service *-- TaskᐸIDependencyᐳ : TaskᐸIDependencyᐳ - Composition ..> Service : IService GetRoot(System.Threading.CancellationToken cancellationToken) - TaskᐸIDependencyᐳ o-- "PerResolve" FuncᐸIDependencyᐳ : FuncᐸIDependencyᐳ - TaskᐸIDependencyᐳ o-- CancellationToken : Argument "cancellationToken" - FuncᐸIDependencyᐳ *-- Dependency : IDependency + class Composition { + +IService GetRoot(System.Threading.CancellationToken cancellationToken) + } + class TaskFactory + class CancellationToken + Dependency --|> IDependency : + class Dependency { + +Dependency() + } + Service --|> IService : + class Service { + +Service(TaskᐸIDependencyᐳ dependencyTask) + } + class TaskᐸIDependencyᐳ + class FuncᐸIDependencyᐳ + class IDependency { + <> + } + class IService { + <> + } + TaskFactory o-- CancellationToken : Argument "cancellationToken" + TaskFactory *-- TaskCreationOptions : TaskCreationOptions + TaskFactory *-- TaskContinuationOptions : TaskContinuationOptions + TaskFactory *-- TaskScheduler : TaskScheduler + Service *-- TaskᐸIDependencyᐳ : TaskᐸIDependencyᐳ + Composition ..> Service : IService GetRoot(System.Threading.CancellationToken cancellationToken) + TaskᐸIDependencyᐳ o-- "PerResolve" FuncᐸIDependencyᐳ : FuncᐸIDependencyᐳ + TaskᐸIDependencyᐳ o-- CancellationToken : Argument "cancellationToken" + FuncᐸIDependencyᐳ *-- Dependency : IDependency ``` @@ -109,80 +109,80 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; +private readonly object _lockM04D27di; + +public Composition() { - private readonly Composition _rootM04D27di; - private readonly object _lockM04D27di; - - public Composition() - { - _rootM04D27di = this; - _lockM04D27di = new object(); - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - _lockM04D27di = _rootM04D27di._lockM04D27di; - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public Pure.DI.UsageTests.BCL.ManualTaskScenario.IService GetRoot(System.Threading.CancellationToken cancellationToken) - { - var perResolveM04D27di42_Func = default(System.Func); - perResolveM04D27di42_Func = new global::System.Func( - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)768)] - () => - { - var value_M04D27di1 = new Pure.DI.UsageTests.BCL.ManualTaskScenario.Dependency(); - return value_M04D27di1; - }); - System.Threading.Tasks.Task transientM04D27di1_Task; - { - var factory_M04D27di2 = perResolveM04D27di42_Func; - var cancellationToken_M04D27di3 = cancellationToken; - transientM04D27di1_Task = new Task(factory_M04D27di2, cancellationToken_M04D27di3); - } - return new Pure.DI.UsageTests.BCL.ManualTaskScenario.Service(transientM04D27di1_Task); - } - - public override string ToString() - { - return - "classDiagram\n" + - " class Composition {\n" + - " +IService GetRoot(System.Threading.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(System.Threading.CancellationToken cancellationToken)\n" + - " TaskᐸIDependencyᐳ o-- \"PerResolve\" FuncᐸIDependencyᐳ : FuncᐸIDependencyᐳ\n" + - " TaskᐸIDependencyᐳ o-- CancellationToken : Argument \"cancellationToken\"\n" + - " FuncᐸIDependencyᐳ *-- Dependency : IDependency"; - } - + _rootM04D27di = this; + _lockM04D27di = new object(); +} + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; + _lockM04D27di = _rootM04D27di._lockM04D27di; +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public Pure.DI.UsageTests.BCL.ManualTaskScenario.IService GetRoot(System.Threading.CancellationToken cancellationToken) +{ + var perResolveM04D27di42_Func = default(System.Func); + perResolveM04D27di42_Func = new global::System.Func( + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)768)] + () => + { + var value_M04D27di1 = new Pure.DI.UsageTests.BCL.ManualTaskScenario.Dependency(); + return value_M04D27di1; + }); + System.Threading.Tasks.Task transientM04D27di1_Task; + { + var factory_M04D27di2 = perResolveM04D27di42_Func; + var cancellationToken_M04D27di3 = cancellationToken; + transientM04D27di1_Task = new Task(factory_M04D27di2, cancellationToken_M04D27di3); + } + return new Pure.DI.UsageTests.BCL.ManualTaskScenario.Service(transientM04D27di1_Task); +} + +public override string ToString() +{ + return + "classDiagram\n" + + " class Composition {\n" + + " +IService GetRoot(System.Threading.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(System.Threading.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 f4d220b5f..f058d82ac 100644 --- a/readme/member-ordinal-attribute.md +++ b/readme/member-ordinal-attribute.md @@ -66,30 +66,30 @@ The attribute `Ordinal` is part of the API, but you can use your own attribute a ```mermaid classDiagram - class PersonComposition { - +IPerson Person - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - class Int32 - class String - class DateTime - Person --|> IPerson : - class Person { - +Person() - +Int32 Id - +String FirstName - +DateTime Birthday - } - class IPerson { - <> - } - Person o-- Int32 : Argument "personId" - Person o-- String : Argument "personName" - Person o-- DateTime : Argument "personBirthday" - PersonComposition ..> Person : IPerson Person + class PersonComposition { + +IPerson Person + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + class Int32 + class String + class DateTime + Person --|> IPerson : + class Person { + +Person() + +Int32 Id + +String FirstName + +DateTime Birthday + } + class IPerson { + <> + } + Person o-- Int32 : Argument "personId" + Person o-- String : Argument "personName" + Person o-- DateTime : Argument "personBirthday" + PersonComposition ..> Person : IPerson Person ``` @@ -98,188 +98,188 @@ classDiagram Pure.DI-generated partial class PersonComposition
```c# -partial class PersonComposition +artial class PersonComposition + { +private readonly PersonComposition _rootM04D27di; + +private readonly int _argM04D27di_personId; +private readonly string _argM04D27di_personName; +private readonly System.DateTime _argM04D27di_personBirthday; + +public PersonComposition(int personId, string personName, System.DateTime personBirthday) { - private readonly PersonComposition _rootM04D27di; - - private readonly int _argM04D27di_personId; - private readonly string _argM04D27di_personName; - private readonly System.DateTime _argM04D27di_personBirthday; - - public PersonComposition(int personId, string personName, System.DateTime personBirthday) - { - _rootM04D27di = this; - if (ReferenceEquals(personName, null)) - { - throw new global::System.ArgumentNullException("personName"); - } - - _argM04D27di_personId = personId; - _argM04D27di_personName = personName; - _argM04D27di_personBirthday = personBirthday; - } - - internal PersonComposition(PersonComposition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - _argM04D27di_personId = baseComposition._argM04D27di_personId; - _argM04D27di_personName = baseComposition._argM04D27di_personName; - _argM04D27di_personBirthday = baseComposition._argM04D27di_personBirthday; - } - - public Pure.DI.UsageTests.Attributes.MemberOrdinalAttributeScenario.IPerson Person - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - Pure.DI.UsageTests.Attributes.MemberOrdinalAttributeScenario.Person transientM04D27di0_Person = new Pure.DI.UsageTests.Attributes.MemberOrdinalAttributeScenario.Person(); - transientM04D27di0_Person.Id = _argM04D27di_personId; - transientM04D27di0_Person.FirstName = _argM04D27di_personName; - transientM04D27di0_Person.Birthday = _argM04D27di_personBirthday; - return transientM04D27di0_Person; - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static PersonComposition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Attributes.MemberOrdinalAttributeScenario.IPerson), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(PersonComposition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(PersonComposition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Attributes.MemberOrdinalAttributeScenario.IPerson Resolve(PersonComposition composition) - { - return composition.Person; - } - - public Pure.DI.UsageTests.Attributes.MemberOrdinalAttributeScenario.IPerson ResolveByTag(PersonComposition composition, object tag) - { - switch (tag) - { - case null: - return composition.Person; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Attributes.MemberOrdinalAttributeScenario.IPerson."); - } - } - } + _rootM04D27di = this; + if (ReferenceEquals(personName, null)) + { + throw new global::System.ArgumentNullException("personName"); + } + + _argM04D27di_personId = personId; + _argM04D27di_personName = personName; + _argM04D27di_personBirthday = personBirthday; +} + +internal PersonComposition(PersonComposition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; + _argM04D27di_personId = baseComposition._argM04D27di_personId; + _argM04D27di_personName = baseComposition._argM04D27di_personName; + _argM04D27di_personBirthday = baseComposition._argM04D27di_personBirthday; +} + +public Pure.DI.UsageTests.Attributes.MemberOrdinalAttributeScenario.IPerson Person +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + Pure.DI.UsageTests.Attributes.MemberOrdinalAttributeScenario.Person transientM04D27di0_Person = new Pure.DI.UsageTests.Attributes.MemberOrdinalAttributeScenario.Person(); + transientM04D27di0_Person.Id = _argM04D27di_personId; + transientM04D27di0_Person.FirstName = _argM04D27di_personName; + transientM04D27di0_Person.Birthday = _argM04D27di_personBirthday; + return transientM04D27di0_Person; + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static PersonComposition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Attributes.MemberOrdinalAttributeScenario.IPerson), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(PersonComposition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(PersonComposition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.Attributes.MemberOrdinalAttributeScenario.IPerson Resolve(PersonComposition composition) + { + return composition.Person; + } + + public Pure.DI.UsageTests.Attributes.MemberOrdinalAttributeScenario.IPerson ResolveByTag(PersonComposition composition, object tag) + { + switch (tag) + { + case null: + return composition.Person; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Attributes.MemberOrdinalAttributeScenario.IPerson."); + } + } } + } ```
diff --git a/readme/method-injection.md b/readme/method-injection.md index 578c38e74..6643be76c 100644 --- a/readme/method-injection.md +++ b/readme/method-injection.md @@ -40,30 +40,30 @@ service.Dependency.ShouldBeOfType(); ```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 : - class Dependency { - +Dependency() - } - Service --|> IService : - class Service { - +Service() - +SetDependency(IDependency dependency) : Void - } - class IDependency { - <> - } - class IService { - <> - } - Service *-- Dependency : IDependency - Composition ..> Service : IService Root + class Composition { + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + Dependency --|> IDependency : + class Dependency { + +Dependency() + } + Service --|> IService : + class Service { + +Service() + +SetDependency(IDependency dependency) : Void + } + class IDependency { + <> + } + class IService { + <> + } + Service *-- Dependency : IDependency + Composition ..> Service : IService Root ``` @@ -72,171 +72,171 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; + +public Composition() { - private readonly Composition _rootM04D27di; - - public Composition() - { - _rootM04D27di = this; - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - } - - public Pure.DI.UsageTests.Basics.MethodInjectionScenario.IService Root - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - Pure.DI.UsageTests.Basics.MethodInjectionScenario.Service transientM04D27di0_Service = new Pure.DI.UsageTests.Basics.MethodInjectionScenario.Service(); - transientM04D27di0_Service.SetDependency(new Pure.DI.UsageTests.Basics.MethodInjectionScenario.Dependency()); - return transientM04D27di0_Service; - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Basics.MethodInjectionScenario.IService), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Basics.MethodInjectionScenario.IService Resolve(Composition composition) - { - return composition.Root; - } - - public Pure.DI.UsageTests.Basics.MethodInjectionScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.Root; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Basics.MethodInjectionScenario.IService."); - } - } - } + _rootM04D27di = this; } + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; +} + +public Pure.DI.UsageTests.Basics.MethodInjectionScenario.IService Root +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + Pure.DI.UsageTests.Basics.MethodInjectionScenario.Service transientM04D27di0_Service = new Pure.DI.UsageTests.Basics.MethodInjectionScenario.Service(); + transientM04D27di0_Service.SetDependency(new Pure.DI.UsageTests.Basics.MethodInjectionScenario.Dependency()); + return transientM04D27di0_Service; + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Basics.MethodInjectionScenario.IService), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.Basics.MethodInjectionScenario.IService Resolve(Composition composition) + { + return composition.Root; + } + + public Pure.DI.UsageTests.Basics.MethodInjectionScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.Root; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Basics.MethodInjectionScenario.IService."); + } + } +} + } ```
diff --git a/readme/multi-contract-bindings.md b/readme/multi-contract-bindings.md index cc5ae054c..46ccd7eb4 100644 --- a/readme/multi-contract-bindings.md +++ b/readme/multi-contract-bindings.md @@ -36,34 +36,34 @@ var service = composition.Root; ```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 + 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 ``` @@ -72,173 +72,173 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; + +public Composition() { - private readonly Composition _rootM04D27di; - - public Composition() - { - _rootM04D27di = this; - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - } - - public Pure.DI.UsageTests.Basics.MultiContractBindingsScenario.IService Root - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - return new Pure.DI.UsageTests.Basics.MultiContractBindingsScenario.Service(new Pure.DI.UsageTests.Basics.MultiContractBindingsScenario.Dependency(), new Pure.DI.UsageTests.Basics.MultiContractBindingsScenario.Dependency()); - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Basics.MultiContractBindingsScenario.IService), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Basics.MultiContractBindingsScenario.IService Resolve(Composition composition) - { - return composition.Root; - } - - public Pure.DI.UsageTests.Basics.MultiContractBindingsScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.Root; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Basics.MultiContractBindingsScenario.IService."); - } - } - } + _rootM04D27di = this; } + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; +} + +public Pure.DI.UsageTests.Basics.MultiContractBindingsScenario.IService Root +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + return new Pure.DI.UsageTests.Basics.MultiContractBindingsScenario.Service(new Pure.DI.UsageTests.Basics.MultiContractBindingsScenario.Dependency(), new Pure.DI.UsageTests.Basics.MultiContractBindingsScenario.Dependency()); + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Basics.MultiContractBindingsScenario.IService), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.Basics.MultiContractBindingsScenario.IService Resolve(Composition composition) + { + return composition.Root; + } + + public Pure.DI.UsageTests.Basics.MultiContractBindingsScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.Root; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Basics.MultiContractBindingsScenario.IService."); + } + } +} + } ```
diff --git a/readme/oncannotresolve-hint.md b/readme/oncannotresolve-hint.md index 55c641fce..a75681743 100644 --- a/readme/oncannotresolve-hint.md +++ b/readme/oncannotresolve-hint.md @@ -61,31 +61,31 @@ For more hints, see [this](https://github.com/DevTeam/Pure.DI/blob/master/README ```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 String - Dependency --|> IDependency : - class Dependency { - +Dependency(String name) - } - Service --|> IService : - class Service { - +Service(IDependency dependency) - } - class IDependency { - <> - } - class IService { - <> - } - Dependency *-- String : String - Service *-- Dependency : IDependency - Composition ..> Service : IService Root + class Composition { + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + class String + Dependency --|> IDependency : + class Dependency { + +Dependency(String name) + } + Service --|> IService : + class Service { + +Service(IDependency dependency) + } + class IDependency { + <> + } + class IService { + <> + } + Dependency *-- String : String + Service *-- Dependency : IDependency + Composition ..> Service : IService Root ``` @@ -94,173 +94,173 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; + +public Composition() { - private readonly Composition _rootM04D27di; - - public Composition() - { - _rootM04D27di = this; - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - } - - public Pure.DI.UsageTests.Hints.OnCannotResolveHintScenario.IService Root - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - string transientM04D27di2_String = OnCannotResolve(null, Pure.DI.Lifetime.Transient); - return new Pure.DI.UsageTests.Hints.OnCannotResolveHintScenario.Service(new Pure.DI.UsageTests.Hints.OnCannotResolveHintScenario.Dependency(transientM04D27di2_String)); - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {type}."); - } - - private partial T OnCannotResolve(object? tag, global::Pure.DI.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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Hints.OnCannotResolveHintScenario.IService), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Hints.OnCannotResolveHintScenario.IService Resolve(Composition composition) - { - return composition.Root; - } - - public Pure.DI.UsageTests.Hints.OnCannotResolveHintScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.Root; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Hints.OnCannotResolveHintScenario.IService."); - } - } - } + _rootM04D27di = this; +} + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; +} + +public Pure.DI.UsageTests.Hints.OnCannotResolveHintScenario.IService Root +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + string transientM04D27di2_String = OnCannotResolve(null, Pure.DI.Lifetime.Transient); + return new Pure.DI.UsageTests.Hints.OnCannotResolveHintScenario.Service(new Pure.DI.UsageTests.Hints.OnCannotResolveHintScenario.Dependency(transientM04D27di2_String)); + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {type}."); +} + +private partial T OnCannotResolve(object? tag, global::Pure.DI.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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Hints.OnCannotResolveHintScenario.IService), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.Hints.OnCannotResolveHintScenario.IService Resolve(Composition composition) + { + return composition.Root; + } + + public Pure.DI.UsageTests.Hints.OnCannotResolveHintScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.Root; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Hints.OnCannotResolveHintScenario.IService."); + } + } } + } ```
diff --git a/readme/ondependencyinjection-hint.md b/readme/ondependencyinjection-hint.md index 0a8fb9b71..f8d7a0eb2 100644 --- a/readme/ondependencyinjection-hint.md +++ b/readme/ondependencyinjection-hint.md @@ -60,29 +60,29 @@ For more hints, see [this](https://github.com/DevTeam/Pure.DI/blob/master/README ```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 : - class Dependency { - +Dependency() - } - Service --|> IService : - class Service { - +Service(IDependency dependency) - } - class IDependency { - <> - } - class IService { - <> - } - Service *-- Dependency : IDependency - Composition ..> Service : IService Root + class Composition { + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + Dependency --|> IDependency : + class Dependency { + +Dependency() + } + Service --|> IService : + class Service { + +Service(IDependency dependency) + } + class IDependency { + <> + } + class IService { + <> + } + Service *-- Dependency : IDependency + Composition ..> Service : IService Root ``` @@ -91,170 +91,170 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; + +public Composition() { - private readonly Composition _rootM04D27di; - - public Composition() - { - _rootM04D27di = this; - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - } - - public Pure.DI.UsageTests.Hints.OnDependencyInjectionHintScenario.IService Root - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - return new Pure.DI.UsageTests.Hints.OnDependencyInjectionHintScenario.Service(OnDependencyInjection(new Pure.DI.UsageTests.Hints.OnDependencyInjectionHintScenario.Dependency(), null, Pure.DI.Lifetime.Transient)); - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {type}."); - } - - private partial T OnDependencyInjection(in T value, object? tag, global::Pure.DI.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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Hints.OnDependencyInjectionHintScenario.IService), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Hints.OnDependencyInjectionHintScenario.IService Resolve(Composition composition) - { - return composition.Root; - } - - public Pure.DI.UsageTests.Hints.OnDependencyInjectionHintScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.Root; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Hints.OnDependencyInjectionHintScenario.IService."); - } - } - } + _rootM04D27di = this; +} + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; +} + +public Pure.DI.UsageTests.Hints.OnDependencyInjectionHintScenario.IService Root +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + return new Pure.DI.UsageTests.Hints.OnDependencyInjectionHintScenario.Service(OnDependencyInjection(new Pure.DI.UsageTests.Hints.OnDependencyInjectionHintScenario.Dependency(), null, Pure.DI.Lifetime.Transient)); + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {type}."); +} + +private partial T OnDependencyInjection(in T value, object? tag, global::Pure.DI.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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Hints.OnDependencyInjectionHintScenario.IService), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.Hints.OnDependencyInjectionHintScenario.IService Resolve(Composition composition) + { + return composition.Root; + } + + public Pure.DI.UsageTests.Hints.OnDependencyInjectionHintScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.Root; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Hints.OnDependencyInjectionHintScenario.IService."); + } + } } + } ```
diff --git a/readme/onnewinstance-hint.md b/readme/onnewinstance-hint.md index f94a4f40f..7b7b8d4fd 100644 --- a/readme/onnewinstance-hint.md +++ b/readme/onnewinstance-hint.md @@ -62,29 +62,29 @@ For more hints, see [this](https://github.com/DevTeam/Pure.DI/blob/master/README ```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 : - class Dependency { - +Dependency() - } - Service --|> IService : - class Service { - +Service(IDependency dependency) - } - class IDependency { - <> - } - class IService { - <> - } - Service o-- "Singleton" Dependency : IDependency - Composition ..> Service : IService Root + class Composition { + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + Dependency --|> IDependency : + class Dependency { + +Dependency() + } + Service --|> IService : + class Service { + +Service(IDependency dependency) + } + class IDependency { + <> + } + class IService { + <> + } + Service o-- "Singleton" Dependency : IDependency + Composition ..> Service : IService Root ``` @@ -93,191 +93,191 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; +private readonly object _lockM04D27di; +private Pure.DI.UsageTests.Hints.OnNewInstanceHintScenario.Dependency _singletonM04D27di36_Dependency; + +public Composition() { - private readonly Composition _rootM04D27di; - private readonly object _lockM04D27di; - private Pure.DI.UsageTests.Hints.OnNewInstanceHintScenario.Dependency _singletonM04D27di36_Dependency; - - public Composition() - { - _rootM04D27di = this; - _lockM04D27di = new object(); - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - _lockM04D27di = _rootM04D27di._lockM04D27di; - } - - public Pure.DI.UsageTests.Hints.OnNewInstanceHintScenario.IService Root - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - if (_rootM04D27di._singletonM04D27di36_Dependency == null) - { - lock (_lockM04D27di) - { - if (_rootM04D27di._singletonM04D27di36_Dependency == null) - { - Pure.DI.UsageTests.Hints.OnNewInstanceHintScenario.Dependency _singletonM04D27di36_DependencyTemp; - _singletonM04D27di36_DependencyTemp = new Pure.DI.UsageTests.Hints.OnNewInstanceHintScenario.Dependency(); - OnNewInstance(ref _singletonM04D27di36_DependencyTemp, null, Pure.DI.Lifetime.Singleton); - global::System.Threading.Thread.MemoryBarrier(); - _singletonM04D27di36_Dependency = _singletonM04D27di36_DependencyTemp; - _rootM04D27di._singletonM04D27di36_Dependency = _singletonM04D27di36_Dependency; - } - } - } - Pure.DI.UsageTests.Hints.OnNewInstanceHintScenario.Service transientM04D27di0_Service = new Pure.DI.UsageTests.Hints.OnNewInstanceHintScenario.Service(_rootM04D27di._singletonM04D27di36_Dependency); - OnNewInstance(ref transientM04D27di0_Service, null, Pure.DI.Lifetime.Transient); - return transientM04D27di0_Service; - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {type}."); - } - - partial void OnNewInstance(ref T value, object? tag, global::Pure.DI.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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Hints.OnNewInstanceHintScenario.IService), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Hints.OnNewInstanceHintScenario.IService Resolve(Composition composition) - { - return composition.Root; - } - - public Pure.DI.UsageTests.Hints.OnNewInstanceHintScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.Root; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Hints.OnNewInstanceHintScenario.IService."); - } - } - } + _rootM04D27di = this; + _lockM04D27di = new object(); } + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; + _lockM04D27di = _rootM04D27di._lockM04D27di; +} + +public Pure.DI.UsageTests.Hints.OnNewInstanceHintScenario.IService Root +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + if (_rootM04D27di._singletonM04D27di36_Dependency == null) + { + lock (_lockM04D27di) + { + if (_rootM04D27di._singletonM04D27di36_Dependency == null) + { + Pure.DI.UsageTests.Hints.OnNewInstanceHintScenario.Dependency _singletonM04D27di36_DependencyTemp; + _singletonM04D27di36_DependencyTemp = new Pure.DI.UsageTests.Hints.OnNewInstanceHintScenario.Dependency(); + OnNewInstance(ref _singletonM04D27di36_DependencyTemp, null, Pure.DI.Lifetime.Singleton); + global::System.Threading.Thread.MemoryBarrier(); + _singletonM04D27di36_Dependency = _singletonM04D27di36_DependencyTemp; + _rootM04D27di._singletonM04D27di36_Dependency = _singletonM04D27di36_Dependency; + } + } + } + Pure.DI.UsageTests.Hints.OnNewInstanceHintScenario.Service transientM04D27di0_Service = new Pure.DI.UsageTests.Hints.OnNewInstanceHintScenario.Service(_rootM04D27di._singletonM04D27di36_Dependency); + OnNewInstance(ref transientM04D27di0_Service, null, Pure.DI.Lifetime.Transient); + return transientM04D27di0_Service; + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {type}."); +} + +partial void OnNewInstance(ref T value, object? tag, global::Pure.DI.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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Hints.OnNewInstanceHintScenario.IService), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.Hints.OnNewInstanceHintScenario.IService Resolve(Composition composition) + { + return composition.Root; + } + + public Pure.DI.UsageTests.Hints.OnNewInstanceHintScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.Root; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Hints.OnNewInstanceHintScenario.IService."); + } + } +} + } ```
diff --git a/readme/overriding-the-bcl-binding.md b/readme/overriding-the-bcl-binding.md index dd78bfc5f..994252964 100644 --- a/readme/overriding-the-bcl-binding.md +++ b/readme/overriding-the-bcl-binding.md @@ -46,23 +46,23 @@ service.Dependencies[2].ShouldBeOfType(); ```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 ArrayᐸIDependencyᐳ - Service --|> IService : - class Service { - +Service(ArrayᐸIDependencyᐳ dependencies) - } - class IService { - <> - } - Service *-- ArrayᐸIDependencyᐳ : ArrayᐸIDependencyᐳ - Composition ..> Service : IService Root + class Composition { + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + class ArrayᐸIDependencyᐳ + Service --|> IService : + class Service { + +Service(ArrayᐸIDependencyᐳ dependencies) + } + class IService { + <> + } + Service *-- ArrayᐸIDependencyᐳ : ArrayᐸIDependencyᐳ + Composition ..> Service : IService Root ``` @@ -71,168 +71,168 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; + +public Composition() { - private readonly Composition _rootM04D27di; - - public Composition() - { - _rootM04D27di = this; - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - } - - public Pure.DI.UsageTests.BCL.OverridingBclBindingScenario.IService Root - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - Pure.DI.UsageTests.BCL.OverridingBclBindingScenario.IDependency[] transientM04D27di1_ = new IDependency[] - { - new AbcDependency(), - new XyzDependency(), - new AbcDependency() - }; - return new Pure.DI.UsageTests.BCL.OverridingBclBindingScenario.Service(transientM04D27di1_); - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.BCL.OverridingBclBindingScenario.IService), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.BCL.OverridingBclBindingScenario.IService Resolve(Composition composition) - { - return composition.Root; - } - - public Pure.DI.UsageTests.BCL.OverridingBclBindingScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.Root; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.BCL.OverridingBclBindingScenario.IService."); - } - } - } + _rootM04D27di = this; +} + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; +} + +public Pure.DI.UsageTests.BCL.OverridingBclBindingScenario.IService Root +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + Pure.DI.UsageTests.BCL.OverridingBclBindingScenario.IDependency[] transientM04D27di1_ = new IDependency[] + { + new AbcDependency(), + new XyzDependency(), + new AbcDependency() + }; + return new Pure.DI.UsageTests.BCL.OverridingBclBindingScenario.Service(transientM04D27di1_); + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.BCL.OverridingBclBindingScenario.IService), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.BCL.OverridingBclBindingScenario.IService Resolve(Composition composition) + { + return composition.Root; + } + + public Pure.DI.UsageTests.BCL.OverridingBclBindingScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.Root; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.BCL.OverridingBclBindingScenario.IService."); + } + } } + } ```
diff --git a/readme/partial-class.md b/readme/partial-class.md index 5ae1f5ab1..48c41b930 100644 --- a/readme/partial-class.md +++ b/readme/partial-class.md @@ -70,30 +70,30 @@ The partial class is also useful for specifying access modifiers to the generate ```mermaid classDiagram - class Composition { - +Service Root - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - class Service { - +Service(String name, IDependency dependency1, IDependency dependency2) - } - class Int64 - class String - Dependency --|> IDependency : - class Dependency { - +Dependency(Int64 id) - } - class IDependency { - <> - } - Service *-- String : "name with id" String - Service *-- Dependency : IDependency - Service *-- Dependency : IDependency - Dependency *-- Int64 : Int64 - Composition ..> Service : Service Root + class Composition { + +Service Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + class Service { + +Service(String name, IDependency dependency1, IDependency dependency2) + } + class Int64 + class String + Dependency --|> IDependency : + class Dependency { + +Dependency(Int64 id) + } + class IDependency { + <> + } + Service *-- String : "name with id" String + Service *-- Dependency : IDependency + Service *-- Dependency : IDependency + Dependency *-- Int64 : Int64 + Composition ..> Service : Service Root ``` @@ -102,172 +102,172 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; + +public Composition() { - private readonly Composition _rootM04D27di; - - public Composition() - { - _rootM04D27di = this; - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - } - - internal Pure.DI.UsageTests.Advanced.PartialClassScenario.Service Root - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - long transientM04D27di5_Int64 = GenerateId(); - long transientM04D27di4_Int64 = GenerateId(); - string transientM04D27di1_String = $"{_serviceName}_{GenerateId()}"; - return new Pure.DI.UsageTests.Advanced.PartialClassScenario.Service(transientM04D27di1_String, new Pure.DI.UsageTests.Advanced.PartialClassScenario.Dependency(transientM04D27di5_Int64), new Pure.DI.UsageTests.Advanced.PartialClassScenario.Dependency(transientM04D27di4_Int64)); - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Advanced.PartialClassScenario.Service), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Advanced.PartialClassScenario.Service Resolve(Composition composition) - { - return composition.Root; - } - - public Pure.DI.UsageTests.Advanced.PartialClassScenario.Service ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.Root; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Advanced.PartialClassScenario.Service."); - } - } - } + _rootM04D27di = this; +} + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; +} + +internal Pure.DI.UsageTests.Advanced.PartialClassScenario.Service Root +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + long transientM04D27di5_Int64 = GenerateId(); + long transientM04D27di4_Int64 = GenerateId(); + string transientM04D27di1_String = $"{_serviceName}_{GenerateId()}"; + return new Pure.DI.UsageTests.Advanced.PartialClassScenario.Service(transientM04D27di1_String, new Pure.DI.UsageTests.Advanced.PartialClassScenario.Dependency(transientM04D27di5_Int64), new Pure.DI.UsageTests.Advanced.PartialClassScenario.Dependency(transientM04D27di4_Int64)); + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Advanced.PartialClassScenario.Service), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.Advanced.PartialClassScenario.Service Resolve(Composition composition) + { + return composition.Root; + } + + public Pure.DI.UsageTests.Advanced.PartialClassScenario.Service ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.Root; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Advanced.PartialClassScenario.Service."); + } + } } + } ```
diff --git a/readme/perblock.md b/readme/perblock.md index ea3741f0e..9cdb22297 100644 --- a/readme/perblock.md +++ b/readme/perblock.md @@ -45,36 +45,36 @@ service2.Dep1.ShouldNotBe(service1.Dep1); ```mermaid classDiagram - class Composition { - +Service Root - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - class ValueTupleᐸIDependencyˏIDependencyᐳ { - +ValueTuple(IDependency item1, IDependency item2) - } - class Service { - +Service(IDependency dep1, IDependency dep2, LazyᐸValueTupleᐸIDependencyˏIDependencyᐳᐳ deps) - } - Dependency --|> IDependency : - class Dependency { - +Dependency() - } - 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 - Service o-- "PerBlock" Dependency : IDependency - Service o-- "PerBlock" Dependency : IDependency - Service *-- LazyᐸValueTupleᐸIDependencyˏIDependencyᐳᐳ : LazyᐸValueTupleᐸIDependencyˏIDependencyᐳᐳ - Composition ..> Service : Service Root - LazyᐸValueTupleᐸIDependencyˏIDependencyᐳᐳ o-- "PerResolve" FuncᐸValueTupleᐸIDependencyˏIDependencyᐳᐳ : FuncᐸValueTupleᐸIDependencyˏIDependencyᐳᐳ - FuncᐸValueTupleᐸIDependencyˏIDependencyᐳᐳ *-- ValueTupleᐸIDependencyˏIDependencyᐳ : ValueTupleᐸIDependencyˏIDependencyᐳ + class Composition { + +Service Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + class ValueTupleᐸIDependencyˏIDependencyᐳ { + +ValueTuple(IDependency item1, IDependency item2) + } + class Service { + +Service(IDependency dep1, IDependency dep2, LazyᐸValueTupleᐸIDependencyˏIDependencyᐳᐳ deps) + } + Dependency --|> IDependency : + class Dependency { + +Dependency() + } + 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 + Service o-- "PerBlock" Dependency : IDependency + Service o-- "PerBlock" Dependency : IDependency + Service *-- LazyᐸValueTupleᐸIDependencyˏIDependencyᐳᐳ : LazyᐸValueTupleᐸIDependencyˏIDependencyᐳᐳ + Composition ..> Service : Service Root + LazyᐸValueTupleᐸIDependencyˏIDependencyᐳᐳ o-- "PerResolve" FuncᐸValueTupleᐸIDependencyˏIDependencyᐳᐳ : FuncᐸValueTupleᐸIDependencyˏIDependencyᐳᐳ + FuncᐸValueTupleᐸIDependencyˏIDependencyᐳᐳ *-- ValueTupleᐸIDependencyˏIDependencyᐳ : ValueTupleᐸIDependencyˏIDependencyᐳ ``` @@ -83,193 +83,193 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; +private readonly object _lockM04D27di; + +public Composition() { - private readonly Composition _rootM04D27di; - private readonly object _lockM04D27di; - - public Composition() - { - _rootM04D27di = this; - _lockM04D27di = new object(); - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - _lockM04D27di = _rootM04D27di._lockM04D27di; - } - - public Pure.DI.UsageTests.Lifetimes.PerBlockScenario.Service Root - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - var perResolveM04D27di43_Func = default(System.Func<(Pure.DI.UsageTests.Lifetimes.PerBlockScenario.IDependency dep3, Pure.DI.UsageTests.Lifetimes.PerBlockScenario.IDependency dep4)>); - perResolveM04D27di43_Func = new global::System.Func<(Pure.DI.UsageTests.Lifetimes.PerBlockScenario.IDependency dep3, Pure.DI.UsageTests.Lifetimes.PerBlockScenario.IDependency dep4)>( - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)768)] - () => - { - Pure.DI.UsageTests.Lifetimes.PerBlockScenario.Dependency perBlockM04D27di4_Dependency = new Pure.DI.UsageTests.Lifetimes.PerBlockScenario.Dependency(); - var value_M04D27di1 = (perBlockM04D27di4_Dependency, perBlockM04D27di4_Dependency); - return value_M04D27di1; - }); - System.Lazy<(Pure.DI.UsageTests.Lifetimes.PerBlockScenario.IDependency dep3, Pure.DI.UsageTests.Lifetimes.PerBlockScenario.IDependency dep4)> transientM04D27di2_Lazy; - { - var factory_M04D27di2 = perResolveM04D27di43_Func; - transientM04D27di2_Lazy = new global::System.Lazy<(Pure.DI.UsageTests.Lifetimes.PerBlockScenario.IDependency dep3, Pure.DI.UsageTests.Lifetimes.PerBlockScenario.IDependency dep4)>(factory_M04D27di2, true); - } - Pure.DI.UsageTests.Lifetimes.PerBlockScenario.Dependency perBlockM04D27di1_Dependency = new Pure.DI.UsageTests.Lifetimes.PerBlockScenario.Dependency(); - return new Pure.DI.UsageTests.Lifetimes.PerBlockScenario.Service(perBlockM04D27di1_Dependency, perBlockM04D27di1_Dependency, transientM04D27di2_Lazy); - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Lifetimes.PerBlockScenario.Service), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Lifetimes.PerBlockScenario.Service Resolve(Composition composition) - { - return composition.Root; - } - - public Pure.DI.UsageTests.Lifetimes.PerBlockScenario.Service ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.Root; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Lifetimes.PerBlockScenario.Service."); - } - } - } + _rootM04D27di = this; + _lockM04D27di = new object(); } + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; + _lockM04D27di = _rootM04D27di._lockM04D27di; +} + +public Pure.DI.UsageTests.Lifetimes.PerBlockScenario.Service Root +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + var perResolveM04D27di43_Func = default(System.Func<(Pure.DI.UsageTests.Lifetimes.PerBlockScenario.IDependency dep3, Pure.DI.UsageTests.Lifetimes.PerBlockScenario.IDependency dep4)>); + perResolveM04D27di43_Func = new global::System.Func<(Pure.DI.UsageTests.Lifetimes.PerBlockScenario.IDependency dep3, Pure.DI.UsageTests.Lifetimes.PerBlockScenario.IDependency dep4)>( + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)768)] + () => + { + Pure.DI.UsageTests.Lifetimes.PerBlockScenario.Dependency perBlockM04D27di4_Dependency = new Pure.DI.UsageTests.Lifetimes.PerBlockScenario.Dependency(); + var value_M04D27di1 = (perBlockM04D27di4_Dependency, perBlockM04D27di4_Dependency); + return value_M04D27di1; + }); + System.Lazy<(Pure.DI.UsageTests.Lifetimes.PerBlockScenario.IDependency dep3, Pure.DI.UsageTests.Lifetimes.PerBlockScenario.IDependency dep4)> transientM04D27di2_Lazy; + { + var factory_M04D27di2 = perResolveM04D27di43_Func; + transientM04D27di2_Lazy = new global::System.Lazy<(Pure.DI.UsageTests.Lifetimes.PerBlockScenario.IDependency dep3, Pure.DI.UsageTests.Lifetimes.PerBlockScenario.IDependency dep4)>(factory_M04D27di2, true); + } + Pure.DI.UsageTests.Lifetimes.PerBlockScenario.Dependency perBlockM04D27di1_Dependency = new Pure.DI.UsageTests.Lifetimes.PerBlockScenario.Dependency(); + return new Pure.DI.UsageTests.Lifetimes.PerBlockScenario.Service(perBlockM04D27di1_Dependency, perBlockM04D27di1_Dependency, transientM04D27di2_Lazy); + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Lifetimes.PerBlockScenario.Service), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.Lifetimes.PerBlockScenario.Service Resolve(Composition composition) + { + return composition.Root; + } + + public Pure.DI.UsageTests.Lifetimes.PerBlockScenario.Service ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.Root; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Lifetimes.PerBlockScenario.Service."); + } + } +} + } ```
diff --git a/readme/perresolve.md b/readme/perresolve.md index efbf68b56..f998e4725 100644 --- a/readme/perresolve.md +++ b/readme/perresolve.md @@ -45,36 +45,36 @@ service2.Dep1.ShouldNotBe(service1.Dep1); ```mermaid classDiagram - class Composition { - +Service Root - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - class ValueTupleᐸIDependencyˏIDependencyᐳ { - +ValueTuple(IDependency item1, IDependency item2) - } - class Service { - +Service(IDependency dep1, IDependency dep2, LazyᐸValueTupleᐸIDependencyˏIDependencyᐳᐳ deps) - } - Dependency --|> IDependency : - class Dependency { - +Dependency() - } - 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 - Service o-- "PerResolve" Dependency : IDependency - Service o-- "PerResolve" Dependency : IDependency - Service *-- LazyᐸValueTupleᐸIDependencyˏIDependencyᐳᐳ : LazyᐸValueTupleᐸIDependencyˏIDependencyᐳᐳ - Composition ..> Service : Service Root - LazyᐸValueTupleᐸIDependencyˏIDependencyᐳᐳ o-- "PerResolve" FuncᐸValueTupleᐸIDependencyˏIDependencyᐳᐳ : FuncᐸValueTupleᐸIDependencyˏIDependencyᐳᐳ - FuncᐸValueTupleᐸIDependencyˏIDependencyᐳᐳ *-- ValueTupleᐸIDependencyˏIDependencyᐳ : ValueTupleᐸIDependencyˏIDependencyᐳ + class Composition { + +Service Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + class ValueTupleᐸIDependencyˏIDependencyᐳ { + +ValueTuple(IDependency item1, IDependency item2) + } + class Service { + +Service(IDependency dep1, IDependency dep2, LazyᐸValueTupleᐸIDependencyˏIDependencyᐳᐳ deps) + } + Dependency --|> IDependency : + class Dependency { + +Dependency() + } + 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 + Service o-- "PerResolve" Dependency : IDependency + Service o-- "PerResolve" Dependency : IDependency + Service *-- LazyᐸValueTupleᐸIDependencyˏIDependencyᐳᐳ : LazyᐸValueTupleᐸIDependencyˏIDependencyᐳᐳ + Composition ..> Service : Service Root + LazyᐸValueTupleᐸIDependencyˏIDependencyᐳᐳ o-- "PerResolve" FuncᐸValueTupleᐸIDependencyˏIDependencyᐳᐳ : FuncᐸValueTupleᐸIDependencyˏIDependencyᐳᐳ + FuncᐸValueTupleᐸIDependencyˏIDependencyᐳᐳ *-- ValueTupleᐸIDependencyˏIDependencyᐳ : ValueTupleᐸIDependencyˏIDependencyᐳ ``` @@ -83,212 +83,212 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; +private readonly object _lockM04D27di; + +public Composition() { - private readonly Composition _rootM04D27di; - private readonly object _lockM04D27di; - - public Composition() - { - _rootM04D27di = this; - _lockM04D27di = new object(); - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - _lockM04D27di = _rootM04D27di._lockM04D27di; - } - - public Pure.DI.UsageTests.Lifetimes.PerResolveScenario.Service Root - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - var perResolveM04D27di36_Dependency = default(Pure.DI.UsageTests.Lifetimes.PerResolveScenario.Dependency); - var perResolveM04D27di43_Func = default(System.Func<(Pure.DI.UsageTests.Lifetimes.PerResolveScenario.IDependency dep3, Pure.DI.UsageTests.Lifetimes.PerResolveScenario.IDependency dep4)>); - perResolveM04D27di43_Func = new global::System.Func<(Pure.DI.UsageTests.Lifetimes.PerResolveScenario.IDependency dep3, Pure.DI.UsageTests.Lifetimes.PerResolveScenario.IDependency dep4)>( - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)768)] - () => - { - if (perResolveM04D27di36_Dependency == null) - { - lock (_lockM04D27di) - { - if (perResolveM04D27di36_Dependency == null) - { - perResolveM04D27di36_Dependency = new Pure.DI.UsageTests.Lifetimes.PerResolveScenario.Dependency(); - } - } - } - var value_M04D27di1 = (perResolveM04D27di36_Dependency, perResolveM04D27di36_Dependency); - return value_M04D27di1; - }); - System.Lazy<(Pure.DI.UsageTests.Lifetimes.PerResolveScenario.IDependency dep3, Pure.DI.UsageTests.Lifetimes.PerResolveScenario.IDependency dep4)> transientM04D27di1_Lazy; - { - var factory_M04D27di2 = perResolveM04D27di43_Func; - transientM04D27di1_Lazy = new global::System.Lazy<(Pure.DI.UsageTests.Lifetimes.PerResolveScenario.IDependency dep3, Pure.DI.UsageTests.Lifetimes.PerResolveScenario.IDependency dep4)>(factory_M04D27di2, true); - } - if (perResolveM04D27di36_Dependency == null) - { - lock (_lockM04D27di) - { - if (perResolveM04D27di36_Dependency == null) - { - perResolveM04D27di36_Dependency = new Pure.DI.UsageTests.Lifetimes.PerResolveScenario.Dependency(); - } - } - } - return new Pure.DI.UsageTests.Lifetimes.PerResolveScenario.Service(perResolveM04D27di36_Dependency, perResolveM04D27di36_Dependency, transientM04D27di1_Lazy); - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Lifetimes.PerResolveScenario.Service), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Lifetimes.PerResolveScenario.Service Resolve(Composition composition) - { - return composition.Root; - } - - public Pure.DI.UsageTests.Lifetimes.PerResolveScenario.Service ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.Root; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Lifetimes.PerResolveScenario.Service."); - } - } - } + _rootM04D27di = this; + _lockM04D27di = new object(); } + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; + _lockM04D27di = _rootM04D27di._lockM04D27di; +} + +public Pure.DI.UsageTests.Lifetimes.PerResolveScenario.Service Root +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + var perResolveM04D27di36_Dependency = default(Pure.DI.UsageTests.Lifetimes.PerResolveScenario.Dependency); + var perResolveM04D27di43_Func = default(System.Func<(Pure.DI.UsageTests.Lifetimes.PerResolveScenario.IDependency dep3, Pure.DI.UsageTests.Lifetimes.PerResolveScenario.IDependency dep4)>); + perResolveM04D27di43_Func = new global::System.Func<(Pure.DI.UsageTests.Lifetimes.PerResolveScenario.IDependency dep3, Pure.DI.UsageTests.Lifetimes.PerResolveScenario.IDependency dep4)>( + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)768)] + () => + { + if (perResolveM04D27di36_Dependency == null) + { + lock (_lockM04D27di) + { + if (perResolveM04D27di36_Dependency == null) + { + perResolveM04D27di36_Dependency = new Pure.DI.UsageTests.Lifetimes.PerResolveScenario.Dependency(); + } + } + } + var value_M04D27di1 = (perResolveM04D27di36_Dependency, perResolveM04D27di36_Dependency); + return value_M04D27di1; + }); + System.Lazy<(Pure.DI.UsageTests.Lifetimes.PerResolveScenario.IDependency dep3, Pure.DI.UsageTests.Lifetimes.PerResolveScenario.IDependency dep4)> transientM04D27di1_Lazy; + { + var factory_M04D27di2 = perResolveM04D27di43_Func; + transientM04D27di1_Lazy = new global::System.Lazy<(Pure.DI.UsageTests.Lifetimes.PerResolveScenario.IDependency dep3, Pure.DI.UsageTests.Lifetimes.PerResolveScenario.IDependency dep4)>(factory_M04D27di2, true); + } + if (perResolveM04D27di36_Dependency == null) + { + lock (_lockM04D27di) + { + if (perResolveM04D27di36_Dependency == null) + { + perResolveM04D27di36_Dependency = new Pure.DI.UsageTests.Lifetimes.PerResolveScenario.Dependency(); + } + } + } + return new Pure.DI.UsageTests.Lifetimes.PerResolveScenario.Service(perResolveM04D27di36_Dependency, perResolveM04D27di36_Dependency, transientM04D27di1_Lazy); + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Lifetimes.PerResolveScenario.Service), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.Lifetimes.PerResolveScenario.Service Resolve(Composition composition) + { + return composition.Root; + } + + public Pure.DI.UsageTests.Lifetimes.PerResolveScenario.Service ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.Root; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Lifetimes.PerResolveScenario.Service."); + } + } +} + } ```
diff --git a/readme/property-injection.md b/readme/property-injection.md index 1a53ed857..eb7bf9b39 100644 --- a/readme/property-injection.md +++ b/readme/property-injection.md @@ -37,30 +37,30 @@ service.Dependency.ShouldBeOfType(); ```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 : - class Dependency { - +Dependency() - } - Service --|> IService : - class Service { - +Service() - +IDependency Dependency - } - class IDependency { - <> - } - class IService { - <> - } - Service *-- Dependency : IDependency - Composition ..> Service : IService Root + class Composition { + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + Dependency --|> IDependency : + class Dependency { + +Dependency() + } + Service --|> IService : + class Service { + +Service() + +IDependency Dependency + } + class IDependency { + <> + } + class IService { + <> + } + Service *-- Dependency : IDependency + Composition ..> Service : IService Root ``` @@ -69,171 +69,171 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; + +public Composition() { - private readonly Composition _rootM04D27di; - - public Composition() - { - _rootM04D27di = this; - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - } - - public Pure.DI.UsageTests.Basics.PropertyInjectionScenario.IService Root - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - Pure.DI.UsageTests.Basics.PropertyInjectionScenario.Service transientM04D27di0_Service = new Pure.DI.UsageTests.Basics.PropertyInjectionScenario.Service(); - transientM04D27di0_Service.Dependency = new Pure.DI.UsageTests.Basics.PropertyInjectionScenario.Dependency(); - return transientM04D27di0_Service; - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Basics.PropertyInjectionScenario.IService), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Basics.PropertyInjectionScenario.IService Resolve(Composition composition) - { - return composition.Root; - } - - public Pure.DI.UsageTests.Basics.PropertyInjectionScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.Root; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Basics.PropertyInjectionScenario.IService."); - } - } - } + _rootM04D27di = this; } + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; +} + +public Pure.DI.UsageTests.Basics.PropertyInjectionScenario.IService Root +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + Pure.DI.UsageTests.Basics.PropertyInjectionScenario.Service transientM04D27di0_Service = new Pure.DI.UsageTests.Basics.PropertyInjectionScenario.Service(); + transientM04D27di0_Service.Dependency = new Pure.DI.UsageTests.Basics.PropertyInjectionScenario.Dependency(); + return transientM04D27di0_Service; + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Basics.PropertyInjectionScenario.IService), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.Basics.PropertyInjectionScenario.IService Resolve(Composition composition) + { + return composition.Root; + } + + public Pure.DI.UsageTests.Basics.PropertyInjectionScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.Root; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Basics.PropertyInjectionScenario.IService."); + } + } +} + } ```
diff --git a/readme/required-properties-or-fields.md b/readme/required-properties-or-fields.md index 712fec4cf..98821ecdd 100644 --- a/readme/required-properties-or-fields.md +++ b/readme/required-properties-or-fields.md @@ -44,33 +44,33 @@ service.Name.ShouldBe("My Service"); ```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 String - Dependency --|> IDependency : - class Dependency { - +Dependency() - } - Service --|> IService : - class Service { - +Service() - +String ServiceNameField - +IDependency Dependency - } - class IDependency { - <> - } - class IService { - <> - } - Service o-- String : Argument "name" - Service *-- Dependency : IDependency - Composition ..> Service : IService Root + class Composition { + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + class String + Dependency --|> IDependency : + class Dependency { + +Dependency() + } + Service --|> IService : + class Service { + +Service() + +String ServiceNameField + +IDependency Dependency + } + class IDependency { + <> + } + class IService { + <> + } + Service o-- String : Argument "name" + Service *-- Dependency : IDependency + Composition ..> Service : IService Root ``` @@ -79,185 +79,185 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; + +private readonly string _argM04D27di_name; + +public Composition(string name) { - private readonly Composition _rootM04D27di; - - private readonly string _argM04D27di_name; - - public Composition(string name) - { - _rootM04D27di = this; - if (ReferenceEquals(name, null)) - { - throw new global::System.ArgumentNullException("name"); - } - - _argM04D27di_name = name; - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - _argM04D27di_name = baseComposition._argM04D27di_name; - } - - public Pure.DI.UsageTests.Basics.RequiredPropertiesOrFieldsScenario.IService Root - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - return new Pure.DI.UsageTests.Basics.RequiredPropertiesOrFieldsScenario.Service() - { - ServiceNameField = _argM04D27di_name, - Dependency = new Pure.DI.UsageTests.Basics.RequiredPropertiesOrFieldsScenario.Dependency() - }; - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Basics.RequiredPropertiesOrFieldsScenario.IService), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Basics.RequiredPropertiesOrFieldsScenario.IService Resolve(Composition composition) - { - return composition.Root; - } - - public Pure.DI.UsageTests.Basics.RequiredPropertiesOrFieldsScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.Root; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Basics.RequiredPropertiesOrFieldsScenario.IService."); - } - } - } + _rootM04D27di = this; + if (ReferenceEquals(name, null)) + { + throw new global::System.ArgumentNullException("name"); + } + + _argM04D27di_name = name; } + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; + _argM04D27di_name = baseComposition._argM04D27di_name; +} + +public Pure.DI.UsageTests.Basics.RequiredPropertiesOrFieldsScenario.IService Root +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + return new Pure.DI.UsageTests.Basics.RequiredPropertiesOrFieldsScenario.Service() + { + ServiceNameField = _argM04D27di_name, + Dependency = new Pure.DI.UsageTests.Basics.RequiredPropertiesOrFieldsScenario.Dependency() + }; + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Basics.RequiredPropertiesOrFieldsScenario.IService), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.Basics.RequiredPropertiesOrFieldsScenario.IService Resolve(Composition composition) + { + return composition.Root; + } + + public Pure.DI.UsageTests.Basics.RequiredPropertiesOrFieldsScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.Root; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Basics.RequiredPropertiesOrFieldsScenario.IService."); + } + } +} + } ```
diff --git a/readme/resolve-hint.md b/readme/resolve-hint.md index 6bce8f99f..14a7d1463 100644 --- a/readme/resolve-hint.md +++ b/readme/resolve-hint.md @@ -33,27 +33,27 @@ For more hints, see [this](https://github.com/DevTeam/Pure.DI/blob/master/README ```mermaid classDiagram - class Composition { - +IDependency DependencyRoot - +IService Root - } - Dependency --|> IDependency : - class Dependency { - +Dependency() - } - Service --|> IService : - class Service { - +Service(IDependency dependency) - } - class IDependency { - <> - } - class IService { - <> - } - Service *-- Dependency : IDependency - Composition ..> Dependency : IDependency DependencyRoot - Composition ..> Service : IService Root + class Composition { + +IDependency DependencyRoot + +IService Root + } + Dependency --|> IDependency : + class Dependency { + +Dependency() + } + Service --|> IService : + class Service { + +Service(IDependency dependency) + } + class IDependency { + <> + } + class IService { + <> + } + Service *-- Dependency : IDependency + Composition ..> Dependency : IDependency DependencyRoot + Composition ..> Service : IService Root ``` @@ -62,66 +62,66 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; + +public Composition() { - private readonly Composition _rootM04D27di; - - public Composition() - { - _rootM04D27di = this; - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - } - - public Pure.DI.UsageTests.Hints.ResolveHintScenario.IDependency DependencyRoot - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - return new Pure.DI.UsageTests.Hints.ResolveHintScenario.Dependency(); - } - } - - public Pure.DI.UsageTests.Hints.ResolveHintScenario.IService Root - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - return new Pure.DI.UsageTests.Hints.ResolveHintScenario.Service(new Pure.DI.UsageTests.Hints.ResolveHintScenario.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"; - } - + _rootM04D27di = this; } + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; +} + +public Pure.DI.UsageTests.Hints.ResolveHintScenario.IDependency DependencyRoot +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + return new Pure.DI.UsageTests.Hints.ResolveHintScenario.Dependency(); + } +} + +public Pure.DI.UsageTests.Hints.ResolveHintScenario.IService Root +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + return new Pure.DI.UsageTests.Hints.ResolveHintScenario.Service(new Pure.DI.UsageTests.Hints.ResolveHintScenario.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 2c00c5442..a37cf05d8 100644 --- a/readme/resolve-methods.md +++ b/readme/resolve-methods.md @@ -47,37 +47,37 @@ var otherService2 = composition.Resolve(typeof(IService),"Other"); ```mermaid classDiagram - class Composition { - +IService OtherService - -IDependency _ - -IService _ - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - Dependency --|> IDependency : - class Dependency { - +Dependency() - } - Service --|> IService : - class Service { - +Service(IDependency dependency) - } - OtherService --|> IService : "Other" - class OtherService { - +OtherService() - } - class IDependency { - <> - } - class IService { - <> - } - Service *-- Dependency : IDependency - Composition ..> Dependency : IDependency _ - Composition ..> Service : IService _ - Composition ..> OtherService : IService OtherService + class Composition { + +IService OtherService + -IDependency _ + -IService _ + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + Dependency --|> IDependency : + class Dependency { + +Dependency() + } + Service --|> IService : + class Service { + +Service(IDependency dependency) + } + OtherService --|> IService : "Other" + class OtherService { + +OtherService() + } + class IDependency { + <> + } + class IService { + <> + } + Service *-- Dependency : IDependency + Composition ..> Dependency : IDependency _ + Composition ..> Service : IService _ + Composition ..> OtherService : IService OtherService ``` @@ -86,218 +86,218 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; + +public Composition() { - private readonly Composition _rootM04D27di; - - public Composition() - { - _rootM04D27di = this; - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - } - - public Pure.DI.UsageTests.Basics.ResolveScenario.IService OtherService - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - return new Pure.DI.UsageTests.Basics.ResolveScenario.OtherService(); - } - } - - private Pure.DI.UsageTests.Basics.ResolveScenario.IDependency RootM04D27di0001 - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - return new Pure.DI.UsageTests.Basics.ResolveScenario.Dependency(); - } - } - - private Pure.DI.UsageTests.Basics.ResolveScenario.IService RootM04D27di0002 - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - return new Pure.DI.UsageTests.Basics.ResolveScenario.Service(new Pure.DI.UsageTests.Basics.ResolveScenario.Dependency()); - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - var valResolverM04D27di_0001 = new ResolverM04D27di_0001(); - ResolverM04D27di.Value = valResolverM04D27di_0001; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 4, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[2] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Basics.ResolveScenario.IService), valResolverM04D27di_0000) - ,new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Basics.ResolveScenario.IDependency), valResolverM04D27di_0001) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Basics.ResolveScenario.IService Resolve(Composition composition) - { - return composition.RootM04D27di0002; - } - - public Pure.DI.UsageTests.Basics.ResolveScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case "Other": - return composition.OtherService; - case null: - return composition.RootM04D27di0002; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Basics.ResolveScenario.IService."); - } - } - } - - private sealed class ResolverM04D27di_0001: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Basics.ResolveScenario.IDependency Resolve(Composition composition) - { - return composition.RootM04D27di0001; - } - - public Pure.DI.UsageTests.Basics.ResolveScenario.IDependency ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.RootM04D27di0001; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Basics.ResolveScenario.IDependency."); - } - } - } + _rootM04D27di = this; } + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; +} + +public Pure.DI.UsageTests.Basics.ResolveScenario.IService OtherService +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + return new Pure.DI.UsageTests.Basics.ResolveScenario.OtherService(); + } +} + +private Pure.DI.UsageTests.Basics.ResolveScenario.IDependency RootM04D27di0001 +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + return new Pure.DI.UsageTests.Basics.ResolveScenario.Dependency(); + } +} + +private Pure.DI.UsageTests.Basics.ResolveScenario.IService RootM04D27di0002 +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + return new Pure.DI.UsageTests.Basics.ResolveScenario.Service(new Pure.DI.UsageTests.Basics.ResolveScenario.Dependency()); + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + var valResolverM04D27di_0001 = new ResolverM04D27di_0001(); + ResolverM04D27di.Value = valResolverM04D27di_0001; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 4, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[2] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Basics.ResolveScenario.IService), valResolverM04D27di_0000) + ,new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Basics.ResolveScenario.IDependency), valResolverM04D27di_0001) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.Basics.ResolveScenario.IService Resolve(Composition composition) + { + return composition.RootM04D27di0002; + } + + public Pure.DI.UsageTests.Basics.ResolveScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case "Other": + return composition.OtherService; + case null: + return composition.RootM04D27di0002; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Basics.ResolveScenario.IService."); + } + } +} + +private sealed class ResolverM04D27di_0001: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.Basics.ResolveScenario.IDependency Resolve(Composition composition) + { + return composition.RootM04D27di0001; + } + + public Pure.DI.UsageTests.Basics.ResolveScenario.IDependency ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.RootM04D27di0001; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Basics.ResolveScenario.IDependency."); + } + } +} + } ```
diff --git a/readme/root-arguments.md b/readme/root-arguments.md index 1de16b2b1..ca9df1561 100644 --- a/readme/root-arguments.md +++ b/readme/root-arguments.md @@ -70,30 +70,30 @@ When using composition root arguments, compilation warnings are shown if `Resolv ```mermaid classDiagram - class Composition { - +IService CreateService(int id, string dependencyName, string serviceName) - } - class Int32 - class String - Dependency --|> IDependency : - class Dependency { - +Dependency(Int32 id, String dependencyName) - } - Service --|> IService : - class Service { - +Service(String name, IDependency dependency) - } - class IDependency { - <> - } - class IService { - <> - } - Dependency o-- Int32 : Argument "id" - Dependency o-- String : Argument "dependencyName" - Service o-- String : "forService" Argument "serviceName" - Service *-- Dependency : IDependency - Composition ..> Service : IService CreateService(int id, string dependencyName, string serviceName) + class Composition { + +IService CreateService(int id, string dependencyName, string serviceName) + } + class Int32 + class String + Dependency --|> IDependency : + class Dependency { + +Dependency(Int32 id, String dependencyName) + } + Service --|> IService : + class Service { + +Service(String name, IDependency dependency) + } + class IDependency { + <> + } + class IService { + <> + } + Dependency o-- Int32 : Argument "id" + Dependency o-- String : Argument "dependencyName" + Service o-- String : "forService" Argument "serviceName" + Service *-- Dependency : IDependency + Composition ..> Service : IService CreateService(int id, string dependencyName, string serviceName) ``` @@ -102,57 +102,57 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; + +public Composition() { - private readonly Composition _rootM04D27di; - - public Composition() - { - _rootM04D27di = this; - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public Pure.DI.UsageTests.Basics.RootArgumentsScenario.IService CreateService(int id, string dependencyName, string serviceName) - { - return new Pure.DI.UsageTests.Basics.RootArgumentsScenario.Service(serviceName, new Pure.DI.UsageTests.Basics.RootArgumentsScenario.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)"; - } - + _rootM04D27di = this; } + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public Pure.DI.UsageTests.Basics.RootArgumentsScenario.IService CreateService(int id, string dependencyName, string serviceName) +{ + return new Pure.DI.UsageTests.Basics.RootArgumentsScenario.Service(serviceName, new Pure.DI.UsageTests.Basics.RootArgumentsScenario.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/rootbind.md index ab7fc3dcc..f835f08fe 100644 --- a/readme/rootbind.md +++ b/readme/rootbind.md @@ -21,21 +21,21 @@ composition.Root.ShouldBeOfType(); ```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 { - +Service() - } - class IService { - <> - } - Composition ..> Service : IService Root + 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 { + +Service() + } + class IService { + <> + } + Composition ..> Service : IService Root ``` @@ -44,160 +44,160 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; + +public Composition() { - private readonly Composition _rootM04D27di; - - public Composition() - { - _rootM04D27di = this; - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - } - - public Pure.DI.UsageTests.Basics.RootBindScenario.IService Root - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - return new Pure.DI.UsageTests.Basics.RootBindScenario.Service(); - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Basics.RootBindScenario.IService), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Basics.RootBindScenario.IService Resolve(Composition composition) - { - return composition.Root; - } - - public Pure.DI.UsageTests.Basics.RootBindScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.Root; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Basics.RootBindScenario.IService."); - } - } - } + _rootM04D27di = this; } + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; +} + +public Pure.DI.UsageTests.Basics.RootBindScenario.IService Root +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + return new Pure.DI.UsageTests.Basics.RootBindScenario.Service(); + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Basics.RootBindScenario.IService), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.Basics.RootBindScenario.IService Resolve(Composition composition) + { + return composition.Root; + } + + public Pure.DI.UsageTests.Basics.RootBindScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.Root; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Basics.RootBindScenario.IService."); + } + } +} + } ```
diff --git a/readme/scope.md b/readme/scope.md index 0fb756fbc..83efd1dd6 100644 --- a/readme/scope.md +++ b/readme/scope.md @@ -82,43 +82,43 @@ dependency2.IsDisposed.ShouldBeTrue(); ```mermaid classDiagram - class Composition { - +Program ProgramRoot - +IService SessionRoot - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - Composition --|> IDisposable - class Session { - +Session(Composition composition) - } - class Program { - +Program(FuncᐸSessionᐳ sessionFactory) - } - Dependency --|> IDependency : - class Dependency { - +Dependency() - } - Service --|> IService : - class Service { - +Service(IDependency dependency) - } - class Composition - class FuncᐸSessionᐳ - class IDependency { - <> - } - class IService { - <> - } - Session *-- Composition : Composition - Program o-- "PerResolve" FuncᐸSessionᐳ : FuncᐸSessionᐳ - Service o-- "Scoped" Dependency : IDependency - Composition ..> Service : IService SessionRoot - Composition ..> Program : Program ProgramRoot - FuncᐸSessionᐳ *-- Session : Session + class Composition { + +Program ProgramRoot + +IService SessionRoot + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + Composition --|> IDisposable + class Session { + +Session(Composition composition) + } + class Program { + +Program(FuncᐸSessionᐳ sessionFactory) + } + Dependency --|> IDependency : + class Dependency { + +Dependency() + } + Service --|> IService : + class Service { + +Service(IDependency dependency) + } + class Composition + class FuncᐸSessionᐳ + class IDependency { + <> + } + class IService { + <> + } + Session *-- Composition : Composition + Program o-- "PerResolve" FuncᐸSessionᐳ : FuncᐸSessionᐳ + Service o-- "Scoped" Dependency : IDependency + Composition ..> Service : IService SessionRoot + Composition ..> Program : Program ProgramRoot + FuncᐸSessionᐳ *-- Session : Session ``` @@ -127,274 +127,274 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition: global::System.IDisposable +artial class Composition: global::System.IDisposable + { +private readonly Composition _rootM04D27di; +private readonly object _lockM04D27di; +private object[] _disposablesM04D27di; +private int _disposeIndexM04D27di; +private Pure.DI.UsageTests.Lifetimes.ScopeScenario.Dependency _scopedM04D27di36_Dependency; + +public Composition() { - private readonly Composition _rootM04D27di; - private readonly object _lockM04D27di; - private object[] _disposablesM04D27di; - private int _disposeIndexM04D27di; - private Pure.DI.UsageTests.Lifetimes.ScopeScenario.Dependency _scopedM04D27di36_Dependency; - - public Composition() - { - _rootM04D27di = this; - _lockM04D27di = new object(); - _disposablesM04D27di = new object[1]; - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - _lockM04D27di = _rootM04D27di._lockM04D27di; - _disposablesM04D27di = new object[1]; - } - - public Pure.DI.UsageTests.Lifetimes.ScopeScenario.IService SessionRoot - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - if (_scopedM04D27di36_Dependency == null) - { - lock (_lockM04D27di) - { - if (_scopedM04D27di36_Dependency == null) - { - _scopedM04D27di36_Dependency = new Pure.DI.UsageTests.Lifetimes.ScopeScenario.Dependency(); - _disposablesM04D27di[_disposeIndexM04D27di++] = _scopedM04D27di36_Dependency; - } - } - } - return new Pure.DI.UsageTests.Lifetimes.ScopeScenario.Service(_scopedM04D27di36_Dependency); - } - } - - public Pure.DI.UsageTests.Lifetimes.ScopeScenario.Program ProgramRoot - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - var perResolveM04D27di43_Func = default(System.Func); - perResolveM04D27di43_Func = new global::System.Func( - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)768)] - () => - { - Pure.DI.UsageTests.Lifetimes.ScopeScenario.Composition transientM04D27di2_Composition = this; - var value_M04D27di1 = new Pure.DI.UsageTests.Lifetimes.ScopeScenario.Session(transientM04D27di2_Composition); - return value_M04D27di1; - }); - return new Pure.DI.UsageTests.Lifetimes.ScopeScenario.Program(perResolveM04D27di43_Func); - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {type}."); - } - - public void Dispose() - { - int disposeIndex; - object[] disposables; - lock (_lockM04D27di) - { - disposeIndex = _disposeIndexM04D27di; - _disposeIndexM04D27di = 0; - disposables = _disposablesM04D27di; - _disposablesM04D27di = new object[1]; - _scopedM04D27di36_Dependency = null; - } - - while (disposeIndex-- > 0) - { - switch (disposables[disposeIndex]) - { - case global::System.IDisposable disposableInstance: - try - { - disposableInstance.Dispose(); - } - catch (Exception exception) - { - OnDisposeException(disposableInstance, exception); - } - break; - } - } - } - - partial void OnDisposeException(T disposableInstance, Exception exception) where T : global::System.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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - var valResolverM04D27di_0001 = new ResolverM04D27di_0001(); - ResolverM04D27di.Value = valResolverM04D27di_0001; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 4, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[2] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Lifetimes.ScopeScenario.IService), valResolverM04D27di_0000) - ,new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Lifetimes.ScopeScenario.Program), valResolverM04D27di_0001) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Lifetimes.ScopeScenario.IService Resolve(Composition composition) - { - return composition.SessionRoot; - } - - public Pure.DI.UsageTests.Lifetimes.ScopeScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.SessionRoot; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Lifetimes.ScopeScenario.IService."); - } - } - } - - private sealed class ResolverM04D27di_0001: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Lifetimes.ScopeScenario.Program Resolve(Composition composition) - { - return composition.ProgramRoot; - } - - public Pure.DI.UsageTests.Lifetimes.ScopeScenario.Program ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.ProgramRoot; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Lifetimes.ScopeScenario.Program."); - } - } - } + _rootM04D27di = this; + _lockM04D27di = new object(); + _disposablesM04D27di = new object[1]; } + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; + _lockM04D27di = _rootM04D27di._lockM04D27di; + _disposablesM04D27di = new object[1]; +} + +public Pure.DI.UsageTests.Lifetimes.ScopeScenario.IService SessionRoot +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + if (_scopedM04D27di36_Dependency == null) + { + lock (_lockM04D27di) + { + if (_scopedM04D27di36_Dependency == null) + { + _scopedM04D27di36_Dependency = new Pure.DI.UsageTests.Lifetimes.ScopeScenario.Dependency(); + _disposablesM04D27di[_disposeIndexM04D27di++] = _scopedM04D27di36_Dependency; + } + } + } + return new Pure.DI.UsageTests.Lifetimes.ScopeScenario.Service(_scopedM04D27di36_Dependency); + } +} + +public Pure.DI.UsageTests.Lifetimes.ScopeScenario.Program ProgramRoot +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + var perResolveM04D27di43_Func = default(System.Func); + perResolveM04D27di43_Func = new global::System.Func( + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)768)] + () => + { + Pure.DI.UsageTests.Lifetimes.ScopeScenario.Composition transientM04D27di2_Composition = this; + var value_M04D27di1 = new Pure.DI.UsageTests.Lifetimes.ScopeScenario.Session(transientM04D27di2_Composition); + return value_M04D27di1; + }); + return new Pure.DI.UsageTests.Lifetimes.ScopeScenario.Program(perResolveM04D27di43_Func); + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {type}."); +} + +public void Dispose() +{ + int disposeIndex; + object[] disposables; + lock (_lockM04D27di) + { + disposeIndex = _disposeIndexM04D27di; + _disposeIndexM04D27di = 0; + disposables = _disposablesM04D27di; + _disposablesM04D27di = new object[1]; + _scopedM04D27di36_Dependency = null; + } + + while (disposeIndex-- > 0) + { + switch (disposables[disposeIndex]) + { + case global::System.IDisposable disposableInstance: + try + { + disposableInstance.Dispose(); + } + catch (Exception exception) + { + OnDisposeException(disposableInstance, exception); + } + break; + } + } +} + +partial void OnDisposeException(T disposableInstance, Exception exception) where T : global::System.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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + var valResolverM04D27di_0001 = new ResolverM04D27di_0001(); + ResolverM04D27di.Value = valResolverM04D27di_0001; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 4, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[2] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Lifetimes.ScopeScenario.IService), valResolverM04D27di_0000) + ,new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Lifetimes.ScopeScenario.Program), valResolverM04D27di_0001) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.Lifetimes.ScopeScenario.IService Resolve(Composition composition) + { + return composition.SessionRoot; + } + + public Pure.DI.UsageTests.Lifetimes.ScopeScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.SessionRoot; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Lifetimes.ScopeScenario.IService."); + } + } +} + +private sealed class ResolverM04D27di_0001: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.Lifetimes.ScopeScenario.Program Resolve(Composition composition) + { + return composition.ProgramRoot; + } + + public Pure.DI.UsageTests.Lifetimes.ScopeScenario.Program ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.ProgramRoot; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Lifetimes.ScopeScenario.Program."); + } + } +} + } ```
diff --git a/readme/service-collection.md b/readme/service-collection.md index 4d3701a2f..05a780e82 100644 --- a/readme/service-collection.md +++ b/readme/service-collection.md @@ -46,31 +46,31 @@ service.Dependency.ShouldBe(dependency); ```mermaid classDiagram - class Composition { - -IDependency _ - -IService _ - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - Dependency --|> IDependency : "Dependency Key" - class Dependency { - +Dependency() - } - Service --|> IService : - class Service { - +Service(IDependency dependency) - } - class IDependency { - <> - } - class IService { - <> - } - Service o-- "Singleton" Dependency : "Dependency Key" IDependency - Composition ..> Dependency : IDependency _ - Composition ..> Service : IService _ + class Composition { + -IDependency _ + -IService _ + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + Dependency --|> IDependency : "Dependency Key" + class Dependency { + +Dependency() + } + Service --|> IService : + class Service { + +Service(IDependency dependency) + } + class IDependency { + <> + } + class IService { + <> + } + Service o-- "Singleton" Dependency : "Dependency Key" IDependency + Composition ..> Dependency : IDependency _ + Composition ..> Service : IService _ ``` @@ -79,229 +79,229 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; +private readonly object _lockM04D27di; +private Pure.DI.UsageTests.BCL.ServiceCollectionScenario.Dependency _singletonM04D27di36_Dependency; + +public Composition() { - private readonly Composition _rootM04D27di; - private readonly object _lockM04D27di; - private Pure.DI.UsageTests.BCL.ServiceCollectionScenario.Dependency _singletonM04D27di36_Dependency; - - public Composition() - { - _rootM04D27di = this; - _lockM04D27di = new object(); - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - _lockM04D27di = _rootM04D27di._lockM04D27di; - } - - private Pure.DI.UsageTests.BCL.ServiceCollectionScenario.IDependency RootM04D27di0001 - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - if (_rootM04D27di._singletonM04D27di36_Dependency == null) - { - lock (_lockM04D27di) - { - if (_rootM04D27di._singletonM04D27di36_Dependency == null) - { - _singletonM04D27di36_Dependency = new Pure.DI.UsageTests.BCL.ServiceCollectionScenario.Dependency(); - _rootM04D27di._singletonM04D27di36_Dependency = _singletonM04D27di36_Dependency; - } - } - } - return _rootM04D27di._singletonM04D27di36_Dependency; - } - } - - private Pure.DI.UsageTests.BCL.ServiceCollectionScenario.IService RootM04D27di0002 - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - if (_rootM04D27di._singletonM04D27di36_Dependency == null) - { - lock (_lockM04D27di) - { - if (_rootM04D27di._singletonM04D27di36_Dependency == null) - { - _singletonM04D27di36_Dependency = new Pure.DI.UsageTests.BCL.ServiceCollectionScenario.Dependency(); - _rootM04D27di._singletonM04D27di36_Dependency = _singletonM04D27di36_Dependency; - } - } - } - return new Pure.DI.UsageTests.BCL.ServiceCollectionScenario.Service(_rootM04D27di._singletonM04D27di36_Dependency); - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - OnNewRoot(valResolverM04D27di_0000, "RootM04D27di0001", "Dependency Key", Pure.DI.Lifetime.Singleton); - ResolverM04D27di.Value = valResolverM04D27di_0000; - var valResolverM04D27di_0001 = new ResolverM04D27di_0001(); - OnNewRoot(valResolverM04D27di_0001, "RootM04D27di0002", null, Pure.DI.Lifetime.Transient); - ResolverM04D27di.Value = valResolverM04D27di_0001; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 4, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[2] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.BCL.ServiceCollectionScenario.IDependency), valResolverM04D27di_0000) - ,new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.BCL.ServiceCollectionScenario.IService), valResolverM04D27di_0001) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.BCL.ServiceCollectionScenario.IDependency Resolve(Composition composition) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type Pure.DI.UsageTests.BCL.ServiceCollectionScenario.IDependency."); - } - - public Pure.DI.UsageTests.BCL.ServiceCollectionScenario.IDependency ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case "Dependency Key": - return composition.RootM04D27di0001; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.BCL.ServiceCollectionScenario.IDependency."); - } - } - } - - private sealed class ResolverM04D27di_0001: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.BCL.ServiceCollectionScenario.IService Resolve(Composition composition) - { - return composition.RootM04D27di0002; - } - - public Pure.DI.UsageTests.BCL.ServiceCollectionScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.RootM04D27di0002; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.BCL.ServiceCollectionScenario.IService."); - } - } - } + _rootM04D27di = this; + _lockM04D27di = new object(); } + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; + _lockM04D27di = _rootM04D27di._lockM04D27di; +} + +private Pure.DI.UsageTests.BCL.ServiceCollectionScenario.IDependency RootM04D27di0001 +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + if (_rootM04D27di._singletonM04D27di36_Dependency == null) + { + lock (_lockM04D27di) + { + if (_rootM04D27di._singletonM04D27di36_Dependency == null) + { + _singletonM04D27di36_Dependency = new Pure.DI.UsageTests.BCL.ServiceCollectionScenario.Dependency(); + _rootM04D27di._singletonM04D27di36_Dependency = _singletonM04D27di36_Dependency; + } + } + } + return _rootM04D27di._singletonM04D27di36_Dependency; + } +} + +private Pure.DI.UsageTests.BCL.ServiceCollectionScenario.IService RootM04D27di0002 +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + if (_rootM04D27di._singletonM04D27di36_Dependency == null) + { + lock (_lockM04D27di) + { + if (_rootM04D27di._singletonM04D27di36_Dependency == null) + { + _singletonM04D27di36_Dependency = new Pure.DI.UsageTests.BCL.ServiceCollectionScenario.Dependency(); + _rootM04D27di._singletonM04D27di36_Dependency = _singletonM04D27di36_Dependency; + } + } + } + return new Pure.DI.UsageTests.BCL.ServiceCollectionScenario.Service(_rootM04D27di._singletonM04D27di36_Dependency); + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + OnNewRoot(valResolverM04D27di_0000, "RootM04D27di0001", "Dependency Key", Pure.DI.Lifetime.Singleton); + ResolverM04D27di.Value = valResolverM04D27di_0000; + var valResolverM04D27di_0001 = new ResolverM04D27di_0001(); + OnNewRoot(valResolverM04D27di_0001, "RootM04D27di0002", null, Pure.DI.Lifetime.Transient); + ResolverM04D27di.Value = valResolverM04D27di_0001; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 4, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[2] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.BCL.ServiceCollectionScenario.IDependency), valResolverM04D27di_0000) + ,new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.BCL.ServiceCollectionScenario.IService), valResolverM04D27di_0001) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.BCL.ServiceCollectionScenario.IDependency Resolve(Composition composition) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type Pure.DI.UsageTests.BCL.ServiceCollectionScenario.IDependency."); + } + + public Pure.DI.UsageTests.BCL.ServiceCollectionScenario.IDependency ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case "Dependency Key": + return composition.RootM04D27di0001; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.BCL.ServiceCollectionScenario.IDependency."); + } + } +} + +private sealed class ResolverM04D27di_0001: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.BCL.ServiceCollectionScenario.IService Resolve(Composition composition) + { + return composition.RootM04D27di0002; + } + + public Pure.DI.UsageTests.BCL.ServiceCollectionScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.RootM04D27di0002; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.BCL.ServiceCollectionScenario.IService."); + } + } +} + } ```
diff --git a/readme/service-provider-with-scope.md b/readme/service-provider-with-scope.md index 7edd9063b..369f432ba 100644 --- a/readme/service-provider-with-scope.md +++ b/readme/service-provider-with-scope.md @@ -74,32 +74,32 @@ dependency1.ShouldBe(dependency2); ```mermaid classDiagram - class Composition { - -IDependency _ - -IService _ - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object GetService(Type type) - + object GetRequiredKeyedService(Type type, object? tag) - } - Composition --|> IDisposable - Dependency --|> IDependency : - class Dependency { - +Dependency() - } - Service --|> IService : - class Service { - +Service(IDependency dependency) - } - class IDependency { - <> - } - class IService { - <> - } - Service o-- "Singleton" Dependency : IDependency - Composition ..> Dependency : IDependency _ - Composition ..> Service : IService _ + class Composition { + -IDependency _ + -IService _ + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object GetService(Type type) + + object GetRequiredKeyedService(Type type, object? tag) + } + Composition --|> IDisposable + Dependency --|> IDependency : + class Dependency { + +Dependency() + } + Service --|> IService : + class Service { + +Service(IDependency dependency) + } + class IDependency { + <> + } + class IService { + <> + } + Service o-- "Singleton" Dependency : IDependency + Composition ..> Dependency : IDependency _ + Composition ..> Service : IService _ ``` @@ -108,272 +108,272 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition: global::System.IDisposable +artial class Composition: global::System.IDisposable + { +private readonly Composition _rootM04D27di; +private readonly object _lockM04D27di; +private object[] _disposablesM04D27di; +private int _disposeIndexM04D27di; +private Pure.DI.UsageTests.BCL.ServiceProviderWithScopeScenario.Dependency _singletonM04D27di36_Dependency; +private Pure.DI.UsageTests.BCL.ServiceProviderWithScopeScenario.Service _scopedM04D27di37_Service; + +public Composition() { - private readonly Composition _rootM04D27di; - private readonly object _lockM04D27di; - private object[] _disposablesM04D27di; - private int _disposeIndexM04D27di; - private Pure.DI.UsageTests.BCL.ServiceProviderWithScopeScenario.Dependency _singletonM04D27di36_Dependency; - private Pure.DI.UsageTests.BCL.ServiceProviderWithScopeScenario.Service _scopedM04D27di37_Service; - - public Composition() - { - _rootM04D27di = this; - _lockM04D27di = new object(); - _disposablesM04D27di = new object[1]; - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - _lockM04D27di = _rootM04D27di._lockM04D27di; - _disposablesM04D27di = new object[1]; - } - - private Pure.DI.UsageTests.BCL.ServiceProviderWithScopeScenario.IDependency RootM04D27di0001 - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - if (_rootM04D27di._singletonM04D27di36_Dependency == null) - { - lock (_lockM04D27di) - { - if (_rootM04D27di._singletonM04D27di36_Dependency == null) - { - _singletonM04D27di36_Dependency = new Pure.DI.UsageTests.BCL.ServiceProviderWithScopeScenario.Dependency(); - _rootM04D27di._singletonM04D27di36_Dependency = _singletonM04D27di36_Dependency; - } - } - } - return _rootM04D27di._singletonM04D27di36_Dependency; - } - } - - private Pure.DI.UsageTests.BCL.ServiceProviderWithScopeScenario.IService RootM04D27di0002 - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - if (_scopedM04D27di37_Service == null) - { - lock (_lockM04D27di) - { - if (_scopedM04D27di37_Service == null) - { - if (_rootM04D27di._singletonM04D27di36_Dependency == null) - { - _singletonM04D27di36_Dependency = new Pure.DI.UsageTests.BCL.ServiceProviderWithScopeScenario.Dependency(); - _rootM04D27di._singletonM04D27di36_Dependency = _singletonM04D27di36_Dependency; - } - _scopedM04D27di37_Service = new Pure.DI.UsageTests.BCL.ServiceProviderWithScopeScenario.Service(_rootM04D27di._singletonM04D27di36_Dependency); - _disposablesM04D27di[_disposeIndexM04D27di++] = _scopedM04D27di37_Service; - } - } - } - return _scopedM04D27di37_Service; - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object GetService(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object GetRequiredKeyedService(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {type}."); - } - - public void Dispose() - { - int disposeIndex; - object[] disposables; - lock (_lockM04D27di) - { - disposeIndex = _disposeIndexM04D27di; - _disposeIndexM04D27di = 0; - disposables = _disposablesM04D27di; - _disposablesM04D27di = new object[1]; - _singletonM04D27di36_Dependency = null; - _scopedM04D27di37_Service = null; - } - - while (disposeIndex-- > 0) - { - switch (disposables[disposeIndex]) - { - case global::System.IDisposable disposableInstance: - try - { - disposableInstance.Dispose(); - } - catch (Exception exception) - { - OnDisposeException(disposableInstance, exception); - } - break; - } - } - } - - partial void OnDisposeException(T disposableInstance, Exception exception) where T : global::System.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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - var valResolverM04D27di_0001 = new ResolverM04D27di_0001(); - ResolverM04D27di.Value = valResolverM04D27di_0001; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 4, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[2] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.BCL.ServiceProviderWithScopeScenario.IDependency), valResolverM04D27di_0000) - ,new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.BCL.ServiceProviderWithScopeScenario.IService), valResolverM04D27di_0001) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.BCL.ServiceProviderWithScopeScenario.IDependency Resolve(Composition composition) - { - return composition.RootM04D27di0001; - } - - public Pure.DI.UsageTests.BCL.ServiceProviderWithScopeScenario.IDependency ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.RootM04D27di0001; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.BCL.ServiceProviderWithScopeScenario.IDependency."); - } - } - } - - private sealed class ResolverM04D27di_0001: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.BCL.ServiceProviderWithScopeScenario.IService Resolve(Composition composition) - { - return composition.RootM04D27di0002; - } - - public Pure.DI.UsageTests.BCL.ServiceProviderWithScopeScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.RootM04D27di0002; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.BCL.ServiceProviderWithScopeScenario.IService."); - } - } - } + _rootM04D27di = this; + _lockM04D27di = new object(); + _disposablesM04D27di = new object[1]; } + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; + _lockM04D27di = _rootM04D27di._lockM04D27di; + _disposablesM04D27di = new object[1]; +} + +private Pure.DI.UsageTests.BCL.ServiceProviderWithScopeScenario.IDependency RootM04D27di0001 +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + if (_rootM04D27di._singletonM04D27di36_Dependency == null) + { + lock (_lockM04D27di) + { + if (_rootM04D27di._singletonM04D27di36_Dependency == null) + { + _singletonM04D27di36_Dependency = new Pure.DI.UsageTests.BCL.ServiceProviderWithScopeScenario.Dependency(); + _rootM04D27di._singletonM04D27di36_Dependency = _singletonM04D27di36_Dependency; + } + } + } + return _rootM04D27di._singletonM04D27di36_Dependency; + } +} + +private Pure.DI.UsageTests.BCL.ServiceProviderWithScopeScenario.IService RootM04D27di0002 +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + if (_scopedM04D27di37_Service == null) + { + lock (_lockM04D27di) + { + if (_scopedM04D27di37_Service == null) + { + if (_rootM04D27di._singletonM04D27di36_Dependency == null) + { + _singletonM04D27di36_Dependency = new Pure.DI.UsageTests.BCL.ServiceProviderWithScopeScenario.Dependency(); + _rootM04D27di._singletonM04D27di36_Dependency = _singletonM04D27di36_Dependency; + } + _scopedM04D27di37_Service = new Pure.DI.UsageTests.BCL.ServiceProviderWithScopeScenario.Service(_rootM04D27di._singletonM04D27di36_Dependency); + _disposablesM04D27di[_disposeIndexM04D27di++] = _scopedM04D27di37_Service; + } + } + } + return _scopedM04D27di37_Service; + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object GetService(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object GetRequiredKeyedService(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {type}."); +} + +public void Dispose() +{ + int disposeIndex; + object[] disposables; + lock (_lockM04D27di) + { + disposeIndex = _disposeIndexM04D27di; + _disposeIndexM04D27di = 0; + disposables = _disposablesM04D27di; + _disposablesM04D27di = new object[1]; + _singletonM04D27di36_Dependency = null; + _scopedM04D27di37_Service = null; + } + + while (disposeIndex-- > 0) + { + switch (disposables[disposeIndex]) + { + case global::System.IDisposable disposableInstance: + try + { + disposableInstance.Dispose(); + } + catch (Exception exception) + { + OnDisposeException(disposableInstance, exception); + } + break; + } + } +} + +partial void OnDisposeException(T disposableInstance, Exception exception) where T : global::System.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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + var valResolverM04D27di_0001 = new ResolverM04D27di_0001(); + ResolverM04D27di.Value = valResolverM04D27di_0001; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 4, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[2] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.BCL.ServiceProviderWithScopeScenario.IDependency), valResolverM04D27di_0000) + ,new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.BCL.ServiceProviderWithScopeScenario.IService), valResolverM04D27di_0001) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.BCL.ServiceProviderWithScopeScenario.IDependency Resolve(Composition composition) + { + return composition.RootM04D27di0001; + } + + public Pure.DI.UsageTests.BCL.ServiceProviderWithScopeScenario.IDependency ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.RootM04D27di0001; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.BCL.ServiceProviderWithScopeScenario.IDependency."); + } + } +} + +private sealed class ResolverM04D27di_0001: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.BCL.ServiceProviderWithScopeScenario.IService Resolve(Composition composition) + { + return composition.RootM04D27di0002; + } + + public Pure.DI.UsageTests.BCL.ServiceProviderWithScopeScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.RootM04D27di0002; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.BCL.ServiceProviderWithScopeScenario.IService."); + } + } +} + } ```
diff --git a/readme/service-provider.md b/readme/service-provider.md index 74e6ba6cd..d62fec4b9 100644 --- a/readme/service-provider.md +++ b/readme/service-provider.md @@ -44,31 +44,31 @@ service.Dependency.ShouldBe(dependency); ```mermaid classDiagram - class Composition { - -IDependency _ - -IService _ - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object GetService(Type type) - + object Resolve(Type type, object? tag) - } - Dependency --|> IDependency : - class Dependency { - +Dependency() - } - Service --|> IService : - class Service { - +Service(IDependency dependency) - } - class IDependency { - <> - } - class IService { - <> - } - Service o-- "Singleton" Dependency : IDependency - Composition ..> Dependency : IDependency _ - Composition ..> Service : IService _ + class Composition { + -IDependency _ + -IService _ + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object GetService(Type type) + + object Resolve(Type type, object? tag) + } + Dependency --|> IDependency : + class Dependency { + +Dependency() + } + Service --|> IService : + class Service { + +Service(IDependency dependency) + } + class IDependency { + <> + } + class IService { + <> + } + Service o-- "Singleton" Dependency : IDependency + Composition ..> Dependency : IDependency _ + Composition ..> Service : IService _ ``` @@ -77,227 +77,227 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; +private readonly object _lockM04D27di; +private Pure.DI.UsageTests.BCL.ServiceProviderScenario.Dependency _singletonM04D27di36_Dependency; + +public Composition() { - private readonly Composition _rootM04D27di; - private readonly object _lockM04D27di; - private Pure.DI.UsageTests.BCL.ServiceProviderScenario.Dependency _singletonM04D27di36_Dependency; - - public Composition() - { - _rootM04D27di = this; - _lockM04D27di = new object(); - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - _lockM04D27di = _rootM04D27di._lockM04D27di; - } - - private Pure.DI.UsageTests.BCL.ServiceProviderScenario.IDependency RootM04D27di0001 - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - if (_rootM04D27di._singletonM04D27di36_Dependency == null) - { - lock (_lockM04D27di) - { - if (_rootM04D27di._singletonM04D27di36_Dependency == null) - { - _singletonM04D27di36_Dependency = new Pure.DI.UsageTests.BCL.ServiceProviderScenario.Dependency(); - _rootM04D27di._singletonM04D27di36_Dependency = _singletonM04D27di36_Dependency; - } - } - } - return _rootM04D27di._singletonM04D27di36_Dependency; - } - } - - private Pure.DI.UsageTests.BCL.ServiceProviderScenario.IService RootM04D27di0002 - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - if (_rootM04D27di._singletonM04D27di36_Dependency == null) - { - lock (_lockM04D27di) - { - if (_rootM04D27di._singletonM04D27di36_Dependency == null) - { - _singletonM04D27di36_Dependency = new Pure.DI.UsageTests.BCL.ServiceProviderScenario.Dependency(); - _rootM04D27di._singletonM04D27di36_Dependency = _singletonM04D27di36_Dependency; - } - } - } - return new Pure.DI.UsageTests.BCL.ServiceProviderScenario.Service(_rootM04D27di._singletonM04D27di36_Dependency); - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object GetService(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - var valResolverM04D27di_0001 = new ResolverM04D27di_0001(); - ResolverM04D27di.Value = valResolverM04D27di_0001; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 4, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[2] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.BCL.ServiceProviderScenario.IDependency), valResolverM04D27di_0000) - ,new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.BCL.ServiceProviderScenario.IService), valResolverM04D27di_0001) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.BCL.ServiceProviderScenario.IDependency Resolve(Composition composition) - { - return composition.RootM04D27di0001; - } - - public Pure.DI.UsageTests.BCL.ServiceProviderScenario.IDependency ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.RootM04D27di0001; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.BCL.ServiceProviderScenario.IDependency."); - } - } - } - - private sealed class ResolverM04D27di_0001: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.BCL.ServiceProviderScenario.IService Resolve(Composition composition) - { - return composition.RootM04D27di0002; - } - - public Pure.DI.UsageTests.BCL.ServiceProviderScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.RootM04D27di0002; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.BCL.ServiceProviderScenario.IService."); - } - } - } + _rootM04D27di = this; + _lockM04D27di = new object(); } + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; + _lockM04D27di = _rootM04D27di._lockM04D27di; +} + +private Pure.DI.UsageTests.BCL.ServiceProviderScenario.IDependency RootM04D27di0001 +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + if (_rootM04D27di._singletonM04D27di36_Dependency == null) + { + lock (_lockM04D27di) + { + if (_rootM04D27di._singletonM04D27di36_Dependency == null) + { + _singletonM04D27di36_Dependency = new Pure.DI.UsageTests.BCL.ServiceProviderScenario.Dependency(); + _rootM04D27di._singletonM04D27di36_Dependency = _singletonM04D27di36_Dependency; + } + } + } + return _rootM04D27di._singletonM04D27di36_Dependency; + } +} + +private Pure.DI.UsageTests.BCL.ServiceProviderScenario.IService RootM04D27di0002 +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + if (_rootM04D27di._singletonM04D27di36_Dependency == null) + { + lock (_lockM04D27di) + { + if (_rootM04D27di._singletonM04D27di36_Dependency == null) + { + _singletonM04D27di36_Dependency = new Pure.DI.UsageTests.BCL.ServiceProviderScenario.Dependency(); + _rootM04D27di._singletonM04D27di36_Dependency = _singletonM04D27di36_Dependency; + } + } + } + return new Pure.DI.UsageTests.BCL.ServiceProviderScenario.Service(_rootM04D27di._singletonM04D27di36_Dependency); + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object GetService(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + var valResolverM04D27di_0001 = new ResolverM04D27di_0001(); + ResolverM04D27di.Value = valResolverM04D27di_0001; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 4, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[2] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.BCL.ServiceProviderScenario.IDependency), valResolverM04D27di_0000) + ,new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.BCL.ServiceProviderScenario.IService), valResolverM04D27di_0001) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.BCL.ServiceProviderScenario.IDependency Resolve(Composition composition) + { + return composition.RootM04D27di0001; + } + + public Pure.DI.UsageTests.BCL.ServiceProviderScenario.IDependency ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.RootM04D27di0001; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.BCL.ServiceProviderScenario.IDependency."); + } + } +} + +private sealed class ResolverM04D27di_0001: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.BCL.ServiceProviderScenario.IService Resolve(Composition composition) + { + return composition.RootM04D27di0002; + } + + public Pure.DI.UsageTests.BCL.ServiceProviderScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.RootM04D27di0002; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.BCL.ServiceProviderScenario.IService."); + } + } +} + } ```
diff --git a/readme/simplified-binding.md b/readme/simplified-binding.md index 4d5c06446..18f700861 100644 --- a/readme/simplified-binding.md +++ b/readme/simplified-binding.md @@ -57,27 +57,27 @@ Special types from the list above will not be added to bindings: ```mermaid classDiagram - class Composition { - +Service MyService - } - class Service { - +Service(Dependency dependencyImpl, IDependency dependency, IOtherDependency otherDependency) - } - Dependency --|> IDependency : - Dependency --|> IOtherDependency : - class Dependency { - +Dependency() - } - class IDependency { - <> - } - class IOtherDependency { - <> - } - Service o-- "PerBlock" Dependency : Dependency - Service o-- "PerBlock" Dependency : IDependency - Service o-- "PerBlock" Dependency : IOtherDependency - Composition ..> Service : Service MyService + class Composition { + +Service MyService + } + class Service { + +Service(Dependency dependencyImpl, IDependency dependency, IOtherDependency otherDependency) + } + Dependency --|> IDependency : + Dependency --|> IOtherDependency : + class Dependency { + +Dependency() + } + class IDependency { + <> + } + class IOtherDependency { + <> + } + Service o-- "PerBlock" Dependency : Dependency + Service o-- "PerBlock" Dependency : IDependency + Service o-- "PerBlock" Dependency : IOtherDependency + Composition ..> Service : Service MyService ``` @@ -86,58 +86,58 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; + +public Composition() { - private readonly Composition _rootM04D27di; - - public Composition() - { - _rootM04D27di = this; - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - } - - public Pure.DI.UsageTests.Basics.SimplifiedBindingScenario.Service MyService - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - Pure.DI.UsageTests.Basics.SimplifiedBindingScenario.Dependency perBlockM04D27di1_Dependency = new Pure.DI.UsageTests.Basics.SimplifiedBindingScenario.Dependency(); - return new Pure.DI.UsageTests.Basics.SimplifiedBindingScenario.Service(perBlockM04D27di1_Dependency, perBlockM04D27di1_Dependency, perBlockM04D27di1_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"; - } - + _rootM04D27di = this; } + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; +} + +public Pure.DI.UsageTests.Basics.SimplifiedBindingScenario.Service MyService +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + Pure.DI.UsageTests.Basics.SimplifiedBindingScenario.Dependency perBlockM04D27di1_Dependency = new Pure.DI.UsageTests.Basics.SimplifiedBindingScenario.Dependency(); + return new Pure.DI.UsageTests.Basics.SimplifiedBindingScenario.Service(perBlockM04D27di1_Dependency, perBlockM04D27di1_Dependency, perBlockM04D27di1_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 e7f19a1b4..2ab808fe7 100644 --- a/readme/singleton.md +++ b/readme/singleton.md @@ -42,30 +42,30 @@ service2.Dependency1.ShouldBe(service1.Dependency1); ```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 : - class Dependency { - +Dependency() - } - Service --|> IService : - class Service { - +Service(IDependency dependency1, IDependency dependency2) - } - class IDependency { - <> - } - class IService { - <> - } - Service o-- "Singleton" Dependency : IDependency - Service o-- "Singleton" Dependency : IDependency - Composition ..> Service : IService Root + class Composition { + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + Dependency --|> IDependency : + class Dependency { + +Dependency() + } + Service --|> IService : + class Service { + +Service(IDependency dependency1, IDependency dependency2) + } + class IDependency { + <> + } + class IService { + <> + } + Service o-- "Singleton" Dependency : IDependency + Service o-- "Singleton" Dependency : IDependency + Composition ..> Service : IService Root ``` @@ -74,184 +74,184 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; +private readonly object _lockM04D27di; +private Pure.DI.UsageTests.Lifetimes.SingletonScenario.Dependency _singletonM04D27di36_Dependency; + +public Composition() { - private readonly Composition _rootM04D27di; - private readonly object _lockM04D27di; - private Pure.DI.UsageTests.Lifetimes.SingletonScenario.Dependency _singletonM04D27di36_Dependency; - - public Composition() - { - _rootM04D27di = this; - _lockM04D27di = new object(); - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - _lockM04D27di = _rootM04D27di._lockM04D27di; - } - - public Pure.DI.UsageTests.Lifetimes.SingletonScenario.IService Root - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - if (_rootM04D27di._singletonM04D27di36_Dependency == null) - { - lock (_lockM04D27di) - { - if (_rootM04D27di._singletonM04D27di36_Dependency == null) - { - _singletonM04D27di36_Dependency = new Pure.DI.UsageTests.Lifetimes.SingletonScenario.Dependency(); - _rootM04D27di._singletonM04D27di36_Dependency = _singletonM04D27di36_Dependency; - } - } - } - return new Pure.DI.UsageTests.Lifetimes.SingletonScenario.Service(_singletonM04D27di36_Dependency, _rootM04D27di._singletonM04D27di36_Dependency); - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Lifetimes.SingletonScenario.IService), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Lifetimes.SingletonScenario.IService Resolve(Composition composition) - { - return composition.Root; - } - - public Pure.DI.UsageTests.Lifetimes.SingletonScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.Root; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Lifetimes.SingletonScenario.IService."); - } - } - } + _rootM04D27di = this; + _lockM04D27di = new object(); } + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; + _lockM04D27di = _rootM04D27di._lockM04D27di; +} + +public Pure.DI.UsageTests.Lifetimes.SingletonScenario.IService Root +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + if (_rootM04D27di._singletonM04D27di36_Dependency == null) + { + lock (_lockM04D27di) + { + if (_rootM04D27di._singletonM04D27di36_Dependency == null) + { + _singletonM04D27di36_Dependency = new Pure.DI.UsageTests.Lifetimes.SingletonScenario.Dependency(); + _rootM04D27di._singletonM04D27di36_Dependency = _singletonM04D27di36_Dependency; + } + } + } + return new Pure.DI.UsageTests.Lifetimes.SingletonScenario.Service(_singletonM04D27di36_Dependency, _rootM04D27di._singletonM04D27di36_Dependency); + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Lifetimes.SingletonScenario.IService), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.Lifetimes.SingletonScenario.IService Resolve(Composition composition) + { + return composition.Root; + } + + public Pure.DI.UsageTests.Lifetimes.SingletonScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.Root; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Lifetimes.SingletonScenario.IService."); + } + } +} + } ```
diff --git a/readme/span-and-readonlyspan.md b/readme/span-and-readonlyspan.md index 2fb34576b..a1bb2bd13 100644 --- a/readme/span-and-readonlyspan.md +++ b/readme/span-and-readonlyspan.md @@ -48,29 +48,29 @@ public IService Root ```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 Dependency { - +Dependency() - } - Service --|> IService : - class Service { - +Service(ReadOnlySpanᐸDependencyᐳ dependencies) - } - class ReadOnlySpanᐸDependencyᐳ - class IService { - <> - } - Service *-- ReadOnlySpanᐸDependencyᐳ : ReadOnlySpanᐸDependencyᐳ - Composition ..> Service : IService Root - ReadOnlySpanᐸDependencyᐳ *-- Dependency : 'a' Dependency - ReadOnlySpanᐸDependencyᐳ *-- Dependency : 'b' Dependency - ReadOnlySpanᐸDependencyᐳ *-- Dependency : 'c' Dependency + class Composition { + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + class Dependency { + +Dependency() + } + Service --|> IService : + class Service { + +Service(ReadOnlySpanᐸDependencyᐳ dependencies) + } + class ReadOnlySpanᐸDependencyᐳ + class IService { + <> + } + Service *-- ReadOnlySpanᐸDependencyᐳ : ReadOnlySpanᐸDependencyᐳ + Composition ..> Service : IService Root + ReadOnlySpanᐸDependencyᐳ *-- Dependency : 'a' Dependency + ReadOnlySpanᐸDependencyᐳ *-- Dependency : 'b' Dependency + ReadOnlySpanᐸDependencyᐳ *-- Dependency : 'c' Dependency ``` @@ -79,174 +79,174 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; + +public Composition() { - private readonly Composition _rootM04D27di; - - public Composition() - { - _rootM04D27di = this; - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - } - - public Pure.DI.UsageTests.BCL.SpanScenario.IService Root - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - System.ReadOnlySpan transientM04D27di1_ReadOnlySpan = stackalloc Pure.DI.UsageTests.BCL.SpanScenario.Dependency[3] - { - new Pure.DI.UsageTests.BCL.SpanScenario.Dependency(), - new Pure.DI.UsageTests.BCL.SpanScenario.Dependency(), - new Pure.DI.UsageTests.BCL.SpanScenario.Dependency() - }; - return new Pure.DI.UsageTests.BCL.SpanScenario.Service(transientM04D27di1_ReadOnlySpan); - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.BCL.SpanScenario.IService), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.BCL.SpanScenario.IService Resolve(Composition composition) - { - return composition.Root; - } - - public Pure.DI.UsageTests.BCL.SpanScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.Root; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.BCL.SpanScenario.IService."); - } - } - } + _rootM04D27di = this; +} + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; +} + +public Pure.DI.UsageTests.BCL.SpanScenario.IService Root +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + System.ReadOnlySpan transientM04D27di1_ReadOnlySpan = stackalloc Pure.DI.UsageTests.BCL.SpanScenario.Dependency[3] + { + new Pure.DI.UsageTests.BCL.SpanScenario.Dependency(), + new Pure.DI.UsageTests.BCL.SpanScenario.Dependency(), + new Pure.DI.UsageTests.BCL.SpanScenario.Dependency() + }; + return new Pure.DI.UsageTests.BCL.SpanScenario.Service(transientM04D27di1_ReadOnlySpan); + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.BCL.SpanScenario.IService), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.BCL.SpanScenario.IService Resolve(Composition composition) + { + return composition.Root; + } + + public Pure.DI.UsageTests.BCL.SpanScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.Root; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.BCL.SpanScenario.IService."); + } + } } + } ```
diff --git a/readme/tag-attribute.md b/readme/tag-attribute.md index 4b251521a..03d755688 100644 --- a/readme/tag-attribute.md +++ b/readme/tag-attribute.md @@ -51,34 +51,34 @@ The tag can be a constant, a type, or a value of an enumerated type. This attrib ```mermaid classDiagram - class Composition { - +IService Root - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - AbcDependency --|> IDependency : "Abc" - class AbcDependency { - +AbcDependency() - } - XyzDependency --|> IDependency : "Xyz" - class XyzDependency { - +XyzDependency() - } - Service --|> IService : - class Service { - +Service(IDependency dependency1, IDependency dependency2) - } - class IDependency { - <> - } - class IService { - <> - } - Service *-- AbcDependency : "Abc" IDependency - Service *-- XyzDependency : "Xyz" IDependency - Composition ..> Service : IService Root + class Composition { + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + AbcDependency --|> IDependency : "Abc" + class AbcDependency { + +AbcDependency() + } + XyzDependency --|> IDependency : "Xyz" + class XyzDependency { + +XyzDependency() + } + Service --|> IService : + class Service { + +Service(IDependency dependency1, IDependency dependency2) + } + class IDependency { + <> + } + class IService { + <> + } + Service *-- AbcDependency : "Abc" IDependency + Service *-- XyzDependency : "Xyz" IDependency + Composition ..> Service : IService Root ``` @@ -87,173 +87,173 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; + +public Composition() { - private readonly Composition _rootM04D27di; - - public Composition() - { - _rootM04D27di = this; - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - } - - public Pure.DI.UsageTests.Basics.TagAttributeScenario.IService Root - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - return new Pure.DI.UsageTests.Basics.TagAttributeScenario.Service(new Pure.DI.UsageTests.Basics.TagAttributeScenario.AbcDependency(), new Pure.DI.UsageTests.Basics.TagAttributeScenario.XyzDependency()); - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Basics.TagAttributeScenario.IService), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Basics.TagAttributeScenario.IService Resolve(Composition composition) - { - return composition.Root; - } - - public Pure.DI.UsageTests.Basics.TagAttributeScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.Root; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Basics.TagAttributeScenario.IService."); - } - } - } + _rootM04D27di = this; } + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; +} + +public Pure.DI.UsageTests.Basics.TagAttributeScenario.IService Root +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + return new Pure.DI.UsageTests.Basics.TagAttributeScenario.Service(new Pure.DI.UsageTests.Basics.TagAttributeScenario.AbcDependency(), new Pure.DI.UsageTests.Basics.TagAttributeScenario.XyzDependency()); + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Basics.TagAttributeScenario.IService), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.Basics.TagAttributeScenario.IService Resolve(Composition composition) + { + return composition.Root; + } + + public Pure.DI.UsageTests.Basics.TagAttributeScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.Root; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Basics.TagAttributeScenario.IService."); + } + } +} + } ```
diff --git a/readme/tag-type.md b/readme/tag-type.md index df0016823..37c583173 100644 --- a/readme/tag-type.md +++ b/readme/tag-type.md @@ -59,38 +59,38 @@ service.Dependency3.ShouldBeOfType(); ```mermaid classDiagram - class Composition { - +IService Root - +IDependency XyzRoot - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - AbcDependency --|> IDependency : typeof(Pure.DI.UsageTests.Advanced.TagTypeScenario.AbcDependency) - AbcDependency --|> IDependency : - class AbcDependency { - +AbcDependency() - } - XyzDependency --|> IDependency : typeof(Pure.DI.UsageTests.Advanced.TagTypeScenario.XyzDependency) - class XyzDependency { - +XyzDependency() - } - Service --|> IService : - class Service { - +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 - Service *-- AbcDependency : IDependency - Composition ..> Service : IService Root - Composition ..> XyzDependency : IDependency XyzRoot + class Composition { + +IService Root + +IDependency XyzRoot + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + AbcDependency --|> IDependency : typeof(Pure.DI.UsageTests.Advanced.TagTypeScenario.AbcDependency) + AbcDependency --|> IDependency : + class AbcDependency { + +AbcDependency() + } + XyzDependency --|> IDependency : typeof(Pure.DI.UsageTests.Advanced.TagTypeScenario.XyzDependency) + class XyzDependency { + +XyzDependency() + } + Service --|> IService : + class Service { + +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 + Service *-- AbcDependency : IDependency + Composition ..> Service : IService Root + Composition ..> XyzDependency : IDependency XyzRoot ``` @@ -99,233 +99,233 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; +private readonly object _lockM04D27di; +private Pure.DI.UsageTests.Advanced.TagTypeScenario.XyzDependency _singletonM04D27di37_XyzDependency; + +public Composition() { - private readonly Composition _rootM04D27di; - private readonly object _lockM04D27di; - private Pure.DI.UsageTests.Advanced.TagTypeScenario.XyzDependency _singletonM04D27di37_XyzDependency; - - public Composition() - { - _rootM04D27di = this; - _lockM04D27di = new object(); - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - _lockM04D27di = _rootM04D27di._lockM04D27di; - } - - public Pure.DI.UsageTests.Advanced.TagTypeScenario.IDependency XyzRoot - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - if (_rootM04D27di._singletonM04D27di37_XyzDependency == null) - { - lock (_lockM04D27di) - { - if (_rootM04D27di._singletonM04D27di37_XyzDependency == null) - { - _singletonM04D27di37_XyzDependency = new Pure.DI.UsageTests.Advanced.TagTypeScenario.XyzDependency(); - _rootM04D27di._singletonM04D27di37_XyzDependency = _singletonM04D27di37_XyzDependency; - } - } - } - return _rootM04D27di._singletonM04D27di37_XyzDependency; - } - } - - public Pure.DI.UsageTests.Advanced.TagTypeScenario.IService Root - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - if (_rootM04D27di._singletonM04D27di37_XyzDependency == null) - { - lock (_lockM04D27di) - { - if (_rootM04D27di._singletonM04D27di37_XyzDependency == null) - { - _singletonM04D27di37_XyzDependency = new Pure.DI.UsageTests.Advanced.TagTypeScenario.XyzDependency(); - _rootM04D27di._singletonM04D27di37_XyzDependency = _singletonM04D27di37_XyzDependency; - } - } - } - return new Pure.DI.UsageTests.Advanced.TagTypeScenario.Service(new Pure.DI.UsageTests.Advanced.TagTypeScenario.AbcDependency(), _rootM04D27di._singletonM04D27di37_XyzDependency, new Pure.DI.UsageTests.Advanced.TagTypeScenario.AbcDependency()); - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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(Pure.DI.UsageTests.Advanced.TagTypeScenario.AbcDependency) \n" + - " AbcDependency --|> IDependency : \n" + - " class AbcDependency {\n" + - " +AbcDependency()\n" + - " }\n" + - " XyzDependency --|> IDependency : typeof(Pure.DI.UsageTests.Advanced.TagTypeScenario.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(Pure.DI.UsageTests.Advanced.TagTypeScenario.AbcDependency) IDependency\n" + - " Service o-- \"Singleton\" XyzDependency : typeof(Pure.DI.UsageTests.Advanced.TagTypeScenario.XyzDependency) IDependency\n" + - " Service *-- AbcDependency : IDependency\n" + - " Composition ..> Service : IService Root\n" + - " Composition ..> XyzDependency : IDependency XyzRoot"; - } - - private readonly static int _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - var valResolverM04D27di_0001 = new ResolverM04D27di_0001(); - ResolverM04D27di.Value = valResolverM04D27di_0001; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 4, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[2] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Advanced.TagTypeScenario.IDependency), valResolverM04D27di_0000) - ,new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Advanced.TagTypeScenario.IService), valResolverM04D27di_0001) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Advanced.TagTypeScenario.IDependency Resolve(Composition composition) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type Pure.DI.UsageTests.Advanced.TagTypeScenario.IDependency."); - } - - public Pure.DI.UsageTests.Advanced.TagTypeScenario.IDependency ResolveByTag(Composition composition, object tag) - { - if (Equals(tag, typeof(Pure.DI.UsageTests.Advanced.TagTypeScenario.XyzDependency))) return composition.XyzRoot; - switch (tag) - { - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Advanced.TagTypeScenario.IDependency."); - } - } - } - - private sealed class ResolverM04D27di_0001: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Advanced.TagTypeScenario.IService Resolve(Composition composition) - { - return composition.Root; - } - - public Pure.DI.UsageTests.Advanced.TagTypeScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.Root; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Advanced.TagTypeScenario.IService."); - } - } - } + _rootM04D27di = this; + _lockM04D27di = new object(); } + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; + _lockM04D27di = _rootM04D27di._lockM04D27di; +} + +public Pure.DI.UsageTests.Advanced.TagTypeScenario.IDependency XyzRoot +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + if (_rootM04D27di._singletonM04D27di37_XyzDependency == null) + { + lock (_lockM04D27di) + { + if (_rootM04D27di._singletonM04D27di37_XyzDependency == null) + { + _singletonM04D27di37_XyzDependency = new Pure.DI.UsageTests.Advanced.TagTypeScenario.XyzDependency(); + _rootM04D27di._singletonM04D27di37_XyzDependency = _singletonM04D27di37_XyzDependency; + } + } + } + return _rootM04D27di._singletonM04D27di37_XyzDependency; + } +} + +public Pure.DI.UsageTests.Advanced.TagTypeScenario.IService Root +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + if (_rootM04D27di._singletonM04D27di37_XyzDependency == null) + { + lock (_lockM04D27di) + { + if (_rootM04D27di._singletonM04D27di37_XyzDependency == null) + { + _singletonM04D27di37_XyzDependency = new Pure.DI.UsageTests.Advanced.TagTypeScenario.XyzDependency(); + _rootM04D27di._singletonM04D27di37_XyzDependency = _singletonM04D27di37_XyzDependency; + } + } + } + return new Pure.DI.UsageTests.Advanced.TagTypeScenario.Service(new Pure.DI.UsageTests.Advanced.TagTypeScenario.AbcDependency(), _rootM04D27di._singletonM04D27di37_XyzDependency, new Pure.DI.UsageTests.Advanced.TagTypeScenario.AbcDependency()); + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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(Pure.DI.UsageTests.Advanced.TagTypeScenario.AbcDependency) \n" + + " AbcDependency --|> IDependency : \n" + + " class AbcDependency {\n" + + " +AbcDependency()\n" + + " }\n" + + " XyzDependency --|> IDependency : typeof(Pure.DI.UsageTests.Advanced.TagTypeScenario.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(Pure.DI.UsageTests.Advanced.TagTypeScenario.AbcDependency) IDependency\n" + + " Service o-- \"Singleton\" XyzDependency : typeof(Pure.DI.UsageTests.Advanced.TagTypeScenario.XyzDependency) IDependency\n" + + " Service *-- AbcDependency : IDependency\n" + + " Composition ..> Service : IService Root\n" + + " Composition ..> XyzDependency : IDependency XyzRoot"; +} + +private readonly static int _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + var valResolverM04D27di_0001 = new ResolverM04D27di_0001(); + ResolverM04D27di.Value = valResolverM04D27di_0001; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 4, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[2] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Advanced.TagTypeScenario.IDependency), valResolverM04D27di_0000) + ,new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Advanced.TagTypeScenario.IService), valResolverM04D27di_0001) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.Advanced.TagTypeScenario.IDependency Resolve(Composition composition) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type Pure.DI.UsageTests.Advanced.TagTypeScenario.IDependency."); + } + + public Pure.DI.UsageTests.Advanced.TagTypeScenario.IDependency ResolveByTag(Composition composition, object tag) + { + if (Equals(tag, typeof(Pure.DI.UsageTests.Advanced.TagTypeScenario.XyzDependency))) return composition.XyzRoot; + switch (tag) + { + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Advanced.TagTypeScenario.IDependency."); + } + } +} + +private sealed class ResolverM04D27di_0001: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.Advanced.TagTypeScenario.IService Resolve(Composition composition) + { + return composition.Root; + } + + public Pure.DI.UsageTests.Advanced.TagTypeScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.Root; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Advanced.TagTypeScenario.IService."); + } + } +} + } ```
diff --git a/readme/tag-unique.md b/readme/tag-unique.md index 8f32bfafa..9f9b29bf1 100644 --- a/readme/tag-unique.md +++ b/readme/tag-unique.md @@ -40,36 +40,36 @@ stringService.Dependencies.Length.ShouldBe(2); ```mermaid classDiagram - class Composition { - +IServiceᐸStringᐳ Root - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - ServiceᐸStringᐳ --|> IServiceᐸStringᐳ : - class ServiceᐸStringᐳ { - +Service(IEnumerableᐸIDependencyᐸStringᐳᐳ dependencies) - } - class IEnumerableᐸIDependencyᐸStringᐳᐳ - AbcDependencyᐸStringᐳ --|> IDependencyᐸStringᐳ : Unique tag 1 - class AbcDependencyᐸStringᐳ { - +AbcDependency() - } - XyzDependencyᐸStringᐳ --|> IDependencyᐸStringᐳ : Unique tag 2 - class XyzDependencyᐸStringᐳ { - +XyzDependency() - } - class IServiceᐸStringᐳ { - <> - } - class IDependencyᐸStringᐳ { - <> - } - Composition ..> ServiceᐸStringᐳ : IServiceᐸStringᐳ Root - ServiceᐸStringᐳ o-- "PerBlock" IEnumerableᐸIDependencyᐸStringᐳᐳ : IEnumerableᐸIDependencyᐸStringᐳᐳ - IEnumerableᐸIDependencyᐸStringᐳᐳ *-- AbcDependencyᐸStringᐳ : Unique tag 1 IDependencyᐸStringᐳ - IEnumerableᐸIDependencyᐸStringᐳᐳ *-- XyzDependencyᐸStringᐳ : Unique tag 2 IDependencyᐸStringᐳ + class Composition { + +IServiceᐸStringᐳ Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + ServiceᐸStringᐳ --|> IServiceᐸStringᐳ : + class ServiceᐸStringᐳ { + +Service(IEnumerableᐸIDependencyᐸStringᐳᐳ dependencies) + } + class IEnumerableᐸIDependencyᐸStringᐳᐳ + AbcDependencyᐸStringᐳ --|> IDependencyᐸStringᐳ : Unique tag 1 + class AbcDependencyᐸStringᐳ { + +AbcDependency() + } + XyzDependencyᐸStringᐳ --|> IDependencyᐸStringᐳ : Unique tag 2 + class XyzDependencyᐸStringᐳ { + +XyzDependency() + } + class IServiceᐸStringᐳ { + <> + } + class IDependencyᐸStringᐳ { + <> + } + Composition ..> ServiceᐸStringᐳ : IServiceᐸStringᐳ Root + ServiceᐸStringᐳ o-- "PerBlock" IEnumerableᐸIDependencyᐸStringᐳᐳ : IEnumerableᐸIDependencyᐸStringᐳᐳ + IEnumerableᐸIDependencyᐸStringᐳᐳ *-- AbcDependencyᐸStringᐳ : Unique tag 1 IDependencyᐸStringᐳ + IEnumerableᐸIDependencyᐸStringᐳᐳ *-- XyzDependencyᐸStringᐳ : Unique tag 2 IDependencyᐸStringᐳ ``` @@ -78,182 +78,182 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; + +public Composition() { - private readonly Composition _rootM04D27di; - - public Composition() - { - _rootM04D27di = this; - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - } - - public Pure.DI.UsageTests.Advanced.TagUniqueScenario.IService Root - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x200)] - System.Collections.Generic.IEnumerable> LocalperBlockM04D27di1_IEnumerable() - { - yield return new Pure.DI.UsageTests.Advanced.TagUniqueScenario.AbcDependency(); - yield return new Pure.DI.UsageTests.Advanced.TagUniqueScenario.XyzDependency(); - } - System.Collections.Generic.IEnumerable> perBlockM04D27di1_IEnumerable = LocalperBlockM04D27di1_IEnumerable(); - return new Pure.DI.UsageTests.Advanced.TagUniqueScenario.Service(perBlockM04D27di1_IEnumerable); - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di>.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Advanced.TagUniqueScenario.IService), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver> - { - public Pure.DI.UsageTests.Advanced.TagUniqueScenario.IService Resolve(Composition composition) - { - return composition.Root; - } - - public Pure.DI.UsageTests.Advanced.TagUniqueScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.Root; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Advanced.TagUniqueScenario.IService."); - } - } - } + _rootM04D27di = this; } + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; +} + +public Pure.DI.UsageTests.Advanced.TagUniqueScenario.IService Root +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x200)] + System.Collections.Generic.IEnumerable> LocalperBlockM04D27di1_IEnumerable() + { + yield return new Pure.DI.UsageTests.Advanced.TagUniqueScenario.AbcDependency(); + yield return new Pure.DI.UsageTests.Advanced.TagUniqueScenario.XyzDependency(); + } + System.Collections.Generic.IEnumerable> perBlockM04D27di1_IEnumerable = LocalperBlockM04D27di1_IEnumerable(); + return new Pure.DI.UsageTests.Advanced.TagUniqueScenario.Service(perBlockM04D27di1_IEnumerable); + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di>.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Advanced.TagUniqueScenario.IService), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver> +{ + public Pure.DI.UsageTests.Advanced.TagUniqueScenario.IService Resolve(Composition composition) + { + return composition.Root; + } + + public Pure.DI.UsageTests.Advanced.TagUniqueScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.Root; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Advanced.TagUniqueScenario.IService."); + } + } +} + } ```
diff --git a/readme/tags.md b/readme/tags.md index de8e44e3c..84194a59e 100644 --- a/readme/tags.md +++ b/readme/tags.md @@ -63,38 +63,38 @@ The tag can be a constant, a type, or a value of an enumerated type. The _defaul ```mermaid classDiagram - class Composition { - +IService Root - +IDependency XyzRoot - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - AbcDependency --|> IDependency : "Abc" - AbcDependency --|> IDependency : - class AbcDependency { - +AbcDependency() - } - XyzDependency --|> IDependency : "Xyz" - class XyzDependency { - +XyzDependency() - } - Service --|> IService : - class Service { - +Service(IDependency dependency1, IDependency dependency2, IDependency dependency3) - } - class IDependency { - <> - } - class IService { - <> - } - Service *-- AbcDependency : "Abc" IDependency - Service o-- "Singleton" XyzDependency : "Xyz" IDependency - Service *-- AbcDependency : IDependency - Composition ..> XyzDependency : IDependency XyzRoot - Composition ..> Service : IService Root + class Composition { + +IService Root + +IDependency XyzRoot + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + AbcDependency --|> IDependency : "Abc" + AbcDependency --|> IDependency : + class AbcDependency { + +AbcDependency() + } + XyzDependency --|> IDependency : "Xyz" + class XyzDependency { + +XyzDependency() + } + Service --|> IService : + class Service { + +Service(IDependency dependency1, IDependency dependency2, IDependency dependency3) + } + class IDependency { + <> + } + class IService { + <> + } + Service *-- AbcDependency : "Abc" IDependency + Service o-- "Singleton" XyzDependency : "Xyz" IDependency + Service *-- AbcDependency : IDependency + Composition ..> XyzDependency : IDependency XyzRoot + Composition ..> Service : IService Root ``` @@ -103,234 +103,234 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; +private readonly object _lockM04D27di; +private Pure.DI.UsageTests.Basics.TagsScenario.XyzDependency _singletonM04D27di37_XyzDependency; + +public Composition() { - private readonly Composition _rootM04D27di; - private readonly object _lockM04D27di; - private Pure.DI.UsageTests.Basics.TagsScenario.XyzDependency _singletonM04D27di37_XyzDependency; - - public Composition() - { - _rootM04D27di = this; - _lockM04D27di = new object(); - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - _lockM04D27di = _rootM04D27di._lockM04D27di; - } - - public Pure.DI.UsageTests.Basics.TagsScenario.IDependency XyzRoot - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - if (_rootM04D27di._singletonM04D27di37_XyzDependency == null) - { - lock (_lockM04D27di) - { - if (_rootM04D27di._singletonM04D27di37_XyzDependency == null) - { - _singletonM04D27di37_XyzDependency = new Pure.DI.UsageTests.Basics.TagsScenario.XyzDependency(); - _rootM04D27di._singletonM04D27di37_XyzDependency = _singletonM04D27di37_XyzDependency; - } - } - } - return _rootM04D27di._singletonM04D27di37_XyzDependency; - } - } - - public Pure.DI.UsageTests.Basics.TagsScenario.IService Root - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - if (_rootM04D27di._singletonM04D27di37_XyzDependency == null) - { - lock (_lockM04D27di) - { - if (_rootM04D27di._singletonM04D27di37_XyzDependency == null) - { - _singletonM04D27di37_XyzDependency = new Pure.DI.UsageTests.Basics.TagsScenario.XyzDependency(); - _rootM04D27di._singletonM04D27di37_XyzDependency = _singletonM04D27di37_XyzDependency; - } - } - } - return new Pure.DI.UsageTests.Basics.TagsScenario.Service(new Pure.DI.UsageTests.Basics.TagsScenario.AbcDependency(), _rootM04D27di._singletonM04D27di37_XyzDependency, new Pure.DI.UsageTests.Basics.TagsScenario.AbcDependency()); - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - var valResolverM04D27di_0001 = new ResolverM04D27di_0001(); - ResolverM04D27di.Value = valResolverM04D27di_0001; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 4, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[2] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Basics.TagsScenario.IDependency), valResolverM04D27di_0000) - ,new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Basics.TagsScenario.IService), valResolverM04D27di_0001) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Basics.TagsScenario.IDependency Resolve(Composition composition) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type Pure.DI.UsageTests.Basics.TagsScenario.IDependency."); - } - - public Pure.DI.UsageTests.Basics.TagsScenario.IDependency ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case "Xyz": - return composition.XyzRoot; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Basics.TagsScenario.IDependency."); - } - } - } - - private sealed class ResolverM04D27di_0001: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Basics.TagsScenario.IService Resolve(Composition composition) - { - return composition.Root; - } - - public Pure.DI.UsageTests.Basics.TagsScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.Root; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Basics.TagsScenario.IService."); - } - } - } + _rootM04D27di = this; + _lockM04D27di = new object(); } + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; + _lockM04D27di = _rootM04D27di._lockM04D27di; +} + +public Pure.DI.UsageTests.Basics.TagsScenario.IDependency XyzRoot +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + if (_rootM04D27di._singletonM04D27di37_XyzDependency == null) + { + lock (_lockM04D27di) + { + if (_rootM04D27di._singletonM04D27di37_XyzDependency == null) + { + _singletonM04D27di37_XyzDependency = new Pure.DI.UsageTests.Basics.TagsScenario.XyzDependency(); + _rootM04D27di._singletonM04D27di37_XyzDependency = _singletonM04D27di37_XyzDependency; + } + } + } + return _rootM04D27di._singletonM04D27di37_XyzDependency; + } +} + +public Pure.DI.UsageTests.Basics.TagsScenario.IService Root +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + if (_rootM04D27di._singletonM04D27di37_XyzDependency == null) + { + lock (_lockM04D27di) + { + if (_rootM04D27di._singletonM04D27di37_XyzDependency == null) + { + _singletonM04D27di37_XyzDependency = new Pure.DI.UsageTests.Basics.TagsScenario.XyzDependency(); + _rootM04D27di._singletonM04D27di37_XyzDependency = _singletonM04D27di37_XyzDependency; + } + } + } + return new Pure.DI.UsageTests.Basics.TagsScenario.Service(new Pure.DI.UsageTests.Basics.TagsScenario.AbcDependency(), _rootM04D27di._singletonM04D27di37_XyzDependency, new Pure.DI.UsageTests.Basics.TagsScenario.AbcDependency()); + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 4)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + var valResolverM04D27di_0001 = new ResolverM04D27di_0001(); + ResolverM04D27di.Value = valResolverM04D27di_0001; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 4, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[2] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Basics.TagsScenario.IDependency), valResolverM04D27di_0000) + ,new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Basics.TagsScenario.IService), valResolverM04D27di_0001) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.Basics.TagsScenario.IDependency Resolve(Composition composition) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type Pure.DI.UsageTests.Basics.TagsScenario.IDependency."); + } + + public Pure.DI.UsageTests.Basics.TagsScenario.IDependency ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case "Xyz": + return composition.XyzRoot; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Basics.TagsScenario.IDependency."); + } + } +} + +private sealed class ResolverM04D27di_0001: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.Basics.TagsScenario.IService Resolve(Composition composition) + { + return composition.Root; + } + + public Pure.DI.UsageTests.Basics.TagsScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.Root; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Basics.TagsScenario.IService."); + } + } +} + } ```
diff --git a/readme/task.md b/readme/task.md index 3baabebf2..9db323f47 100644 --- a/readme/task.md +++ b/readme/task.md @@ -62,44 +62,44 @@ await service.RunAsync(cancellationTokenSource.Token); ```mermaid classDiagram - class Composition { - +IService GetRoot(System.Threading.CancellationToken cancellationToken) - } - class TaskCreationOptions - class TaskContinuationOptions - class TaskFactory - class TaskScheduler - class CancellationToken - Dependency --|> IDependency : - class Dependency { - +Dependency() - } - Service --|> IService : - class Service { - +Service(TaskᐸIDependencyᐳ dependencyTask) - } - class TaskᐸIDependencyᐳ - class FuncᐸIDependencyᐳ - class TaskFactoryᐸIDependencyᐳ - class IDependency { - <> - } - class IService { - <> - } - TaskFactory o-- CancellationToken : Argument "cancellationToken" - TaskFactory *-- TaskCreationOptions : TaskCreationOptions - TaskFactory *-- TaskContinuationOptions : TaskContinuationOptions - TaskFactory *-- TaskScheduler : TaskScheduler - Service *-- TaskᐸIDependencyᐳ : TaskᐸIDependencyᐳ - Composition ..> Service : IService GetRoot(System.Threading.CancellationToken cancellationToken) - TaskᐸIDependencyᐳ o-- "PerResolve" FuncᐸIDependencyᐳ : FuncᐸIDependencyᐳ - TaskᐸIDependencyᐳ o-- "PerBlock" TaskFactoryᐸIDependencyᐳ : TaskFactoryᐸIDependencyᐳ - FuncᐸIDependencyᐳ *-- Dependency : IDependency - TaskFactoryᐸIDependencyᐳ o-- CancellationToken : Argument "cancellationToken" - TaskFactoryᐸIDependencyᐳ *-- TaskCreationOptions : TaskCreationOptions - TaskFactoryᐸIDependencyᐳ *-- TaskContinuationOptions : TaskContinuationOptions - TaskFactoryᐸIDependencyᐳ *-- TaskScheduler : TaskScheduler + class Composition { + +IService GetRoot(System.Threading.CancellationToken cancellationToken) + } + class TaskCreationOptions + class TaskContinuationOptions + class TaskFactory + class TaskScheduler + class CancellationToken + Dependency --|> IDependency : + class Dependency { + +Dependency() + } + Service --|> IService : + class Service { + +Service(TaskᐸIDependencyᐳ dependencyTask) + } + class TaskᐸIDependencyᐳ + class FuncᐸIDependencyᐳ + class TaskFactoryᐸIDependencyᐳ + class IDependency { + <> + } + class IService { + <> + } + TaskFactory o-- CancellationToken : Argument "cancellationToken" + TaskFactory *-- TaskCreationOptions : TaskCreationOptions + TaskFactory *-- TaskContinuationOptions : TaskContinuationOptions + TaskFactory *-- TaskScheduler : TaskScheduler + Service *-- TaskᐸIDependencyᐳ : TaskᐸIDependencyᐳ + Composition ..> Service : IService GetRoot(System.Threading.CancellationToken cancellationToken) + TaskᐸIDependencyᐳ o-- "PerResolve" FuncᐸIDependencyᐳ : FuncᐸIDependencyᐳ + TaskᐸIDependencyᐳ o-- "PerBlock" TaskFactoryᐸIDependencyᐳ : TaskFactoryᐸIDependencyᐳ + FuncᐸIDependencyᐳ *-- Dependency : IDependency + TaskFactoryᐸIDependencyᐳ o-- CancellationToken : Argument "cancellationToken" + TaskFactoryᐸIDependencyᐳ *-- TaskCreationOptions : TaskCreationOptions + TaskFactoryᐸIDependencyᐳ *-- TaskContinuationOptions : TaskContinuationOptions + TaskFactoryᐸIDependencyᐳ *-- TaskScheduler : TaskScheduler ``` @@ -108,99 +108,99 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; +private readonly object _lockM04D27di; + +public Composition() { - private readonly Composition _rootM04D27di; - private readonly object _lockM04D27di; - - public Composition() - { - _rootM04D27di = this; - _lockM04D27di = new object(); - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - _lockM04D27di = _rootM04D27di._lockM04D27di; - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public Pure.DI.UsageTests.BCL.TaskScenario.IService GetRoot(System.Threading.CancellationToken cancellationToken) - { - var perResolveM04D27di42_Func = default(System.Func); - System.Threading.Tasks.TaskScheduler transientM04D27di5_TaskScheduler = TaskScheduler.Current; - System.Threading.Tasks.TaskContinuationOptions transientM04D27di4_TaskContinuationOptions = global::System.Threading.Tasks.TaskContinuationOptions.None; - System.Threading.Tasks.TaskCreationOptions transientM04D27di3_TaskCreationOptions = global::System.Threading.Tasks.TaskCreationOptions.None; - System.Threading.Tasks.TaskFactory perBlockM04D27di2_TaskFactory; - { - var cancellationToken_M04D27di1 = cancellationToken; - var taskCreationOptions_M04D27di2 = transientM04D27di3_TaskCreationOptions; - var taskContinuationOptions_M04D27di3 = transientM04D27di4_TaskContinuationOptions; - var taskScheduler_M04D27di4 = transientM04D27di5_TaskScheduler; - perBlockM04D27di2_TaskFactory = new global::System.Threading.Tasks.TaskFactory(cancellationToken_M04D27di1, taskCreationOptions_M04D27di2, taskContinuationOptions_M04D27di3, taskScheduler_M04D27di4); - } - perResolveM04D27di42_Func = new global::System.Func( - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)768)] - () => - { - var value_M04D27di5 = new Pure.DI.UsageTests.BCL.TaskScenario.Dependency(); - return value_M04D27di5; - }); - System.Threading.Tasks.Task transientM04D27di1_Task; - { - var factory_M04D27di6 = perResolveM04D27di42_Func; - var taskFactory_M04D27di7 = perBlockM04D27di2_TaskFactory; - transientM04D27di1_Task = taskFactory_M04D27di7.StartNew(factory_M04D27di6); - } - return new Pure.DI.UsageTests.BCL.TaskScenario.Service(transientM04D27di1_Task); - } - - public override string ToString() - { - return - "classDiagram\n" + - " class Composition {\n" + - " +IService GetRoot(System.Threading.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(System.Threading.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"; - } - + _rootM04D27di = this; + _lockM04D27di = new object(); +} + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; + _lockM04D27di = _rootM04D27di._lockM04D27di; +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public Pure.DI.UsageTests.BCL.TaskScenario.IService GetRoot(System.Threading.CancellationToken cancellationToken) +{ + var perResolveM04D27di42_Func = default(System.Func); + System.Threading.Tasks.TaskScheduler transientM04D27di5_TaskScheduler = TaskScheduler.Current; + System.Threading.Tasks.TaskContinuationOptions transientM04D27di4_TaskContinuationOptions = global::System.Threading.Tasks.TaskContinuationOptions.None; + System.Threading.Tasks.TaskCreationOptions transientM04D27di3_TaskCreationOptions = global::System.Threading.Tasks.TaskCreationOptions.None; + System.Threading.Tasks.TaskFactory perBlockM04D27di2_TaskFactory; + { + var cancellationToken_M04D27di1 = cancellationToken; + var taskCreationOptions_M04D27di2 = transientM04D27di3_TaskCreationOptions; + var taskContinuationOptions_M04D27di3 = transientM04D27di4_TaskContinuationOptions; + var taskScheduler_M04D27di4 = transientM04D27di5_TaskScheduler; + perBlockM04D27di2_TaskFactory = new global::System.Threading.Tasks.TaskFactory(cancellationToken_M04D27di1, taskCreationOptions_M04D27di2, taskContinuationOptions_M04D27di3, taskScheduler_M04D27di4); + } + perResolveM04D27di42_Func = new global::System.Func( + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)768)] + () => + { + var value_M04D27di5 = new Pure.DI.UsageTests.BCL.TaskScenario.Dependency(); + return value_M04D27di5; + }); + System.Threading.Tasks.Task transientM04D27di1_Task; + { + var factory_M04D27di6 = perResolveM04D27di42_Func; + var taskFactory_M04D27di7 = perBlockM04D27di2_TaskFactory; + transientM04D27di1_Task = taskFactory_M04D27di7.StartNew(factory_M04D27di6); + } + return new Pure.DI.UsageTests.BCL.TaskScenario.Service(transientM04D27di1_Task); +} + +public override string ToString() +{ + return + "classDiagram\n" + + " class Composition {\n" + + " +IService GetRoot(System.Threading.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(System.Threading.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 4e66d6d32..082db9c6c 100644 --- a/readme/threadsafe-hint.md +++ b/readme/threadsafe-hint.md @@ -32,29 +32,29 @@ For more hints, see [this](https://github.com/DevTeam/Pure.DI/blob/master/README ```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 : - class Dependency { - +Dependency() - } - Service --|> IService : - class Service { - +Service(IDependency dependency) - } - class IDependency { - <> - } - class IService { - <> - } - Service *-- Dependency : IDependency - Composition ..> Service : IService Root + class Composition { + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + Dependency --|> IDependency : + class Dependency { + +Dependency() + } + Service --|> IService : + class Service { + +Service(IDependency dependency) + } + class IDependency { + <> + } + class IService { + <> + } + Service *-- Dependency : IDependency + Composition ..> Service : IService Root ``` @@ -63,168 +63,168 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; + +public Composition() { - private readonly Composition _rootM04D27di; - - public Composition() - { - _rootM04D27di = this; - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - } - - public Pure.DI.UsageTests.Hints.ThreadSafeHintScenario.IService Root - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - return new Pure.DI.UsageTests.Hints.ThreadSafeHintScenario.Service(new Pure.DI.UsageTests.Hints.ThreadSafeHintScenario.Dependency()); - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Hints.ThreadSafeHintScenario.IService), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Hints.ThreadSafeHintScenario.IService Resolve(Composition composition) - { - return composition.Root; - } - - public Pure.DI.UsageTests.Hints.ThreadSafeHintScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.Root; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Hints.ThreadSafeHintScenario.IService."); - } - } - } + _rootM04D27di = this; } + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; +} + +public Pure.DI.UsageTests.Hints.ThreadSafeHintScenario.IService Root +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + return new Pure.DI.UsageTests.Hints.ThreadSafeHintScenario.Service(new Pure.DI.UsageTests.Hints.ThreadSafeHintScenario.Dependency()); + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Hints.ThreadSafeHintScenario.IService), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.Hints.ThreadSafeHintScenario.IService Resolve(Composition composition) + { + return composition.Root; + } + + public Pure.DI.UsageTests.Hints.ThreadSafeHintScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.Root; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Hints.ThreadSafeHintScenario.IService."); + } + } +} + } ```
diff --git a/readme/tostring-hint.md b/readme/tostring-hint.md index e5831d6d3..62206e634 100644 --- a/readme/tostring-hint.md +++ b/readme/tostring-hint.md @@ -30,29 +30,29 @@ For more hints, see [this](https://github.com/DevTeam/Pure.DI/blob/master/README ```mermaid classDiagram - class Composition { - +IService MyService - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - Dependency --|> IDependency : - class Dependency { - +Dependency() - } - Service --|> IService : - class Service { - +Service(IDependency dependency) - } - class IDependency { - <> - } - class IService { - <> - } - Service *-- Dependency : IDependency - Composition ..> Service : IService MyService + class Composition { + +IService MyService + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + Dependency --|> IDependency : + class Dependency { + +Dependency() + } + Service --|> IService : + class Service { + +Service(IDependency dependency) + } + class IDependency { + <> + } + class IService { + <> + } + Service *-- Dependency : IDependency + Composition ..> Service : IService MyService ``` @@ -61,168 +61,168 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; + +public Composition() { - private readonly Composition _rootM04D27di; - - public Composition() - { - _rootM04D27di = this; - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - } - - public Pure.DI.UsageTests.Hints.ToStringHintScenario.IService MyService - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - return new Pure.DI.UsageTests.Hints.ToStringHintScenario.Service(new Pure.DI.UsageTests.Hints.ToStringHintScenario.Dependency()); - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Hints.ToStringHintScenario.IService), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Hints.ToStringHintScenario.IService Resolve(Composition composition) - { - return composition.MyService; - } - - public Pure.DI.UsageTests.Hints.ToStringHintScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.MyService; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Hints.ToStringHintScenario.IService."); - } - } - } + _rootM04D27di = this; } + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; +} + +public Pure.DI.UsageTests.Hints.ToStringHintScenario.IService MyService +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + return new Pure.DI.UsageTests.Hints.ToStringHintScenario.Service(new Pure.DI.UsageTests.Hints.ToStringHintScenario.Dependency()); + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Hints.ToStringHintScenario.IService), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.Hints.ToStringHintScenario.IService Resolve(Composition composition) + { + return composition.MyService; + } + + public Pure.DI.UsageTests.Hints.ToStringHintScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.MyService; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Hints.ToStringHintScenario.IService."); + } + } +} + } ```
diff --git a/readme/tracking-async-disposable-instances-in-delegates.md b/readme/tracking-async-disposable-instances-in-delegates.md index 732025780..25a8a1b1e 100644 --- a/readme/tracking-async-disposable-instances-in-delegates.md +++ b/readme/tracking-async-disposable-instances-in-delegates.md @@ -74,39 +74,39 @@ root1.Dependency.IsDisposed.ShouldBeTrue(); ```mermaid classDiagram - class Composition { - +Service Root - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - class Owned - Dependency --|> IDependency : - class Dependency { - +Dependency() - } - Service --|> IService : - Service --|> IAsyncDisposable : - class Service { - +Service(FuncᐸOwnedᐸIDependencyᐳᐳ dependencyFactory) - } - 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 - FuncᐸOwnedᐸIDependencyᐳᐳ o-- "PerBlock" OwnedᐸIDependencyᐳ : OwnedᐸIDependencyᐳ - OwnedᐸIDependencyᐳ *-- Owned : Owned - OwnedᐸIDependencyᐳ *-- Dependency : IDependency + class Composition { + +Service Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + class Owned + Dependency --|> IDependency : + class Dependency { + +Dependency() + } + Service --|> IService : + Service --|> IAsyncDisposable : + class Service { + +Service(FuncᐸOwnedᐸIDependencyᐳᐳ dependencyFactory) + } + 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 + FuncᐸOwnedᐸIDependencyᐳᐳ o-- "PerBlock" OwnedᐸIDependencyᐳ : OwnedᐸIDependencyᐳ + OwnedᐸIDependencyᐳ *-- Owned : Owned + OwnedᐸIDependencyᐳ *-- Dependency : IDependency ``` @@ -115,205 +115,205 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; +private readonly object _lockM04D27di; + +public Composition() { - private readonly Composition _rootM04D27di; - private readonly object _lockM04D27di; - - public Composition() - { - _rootM04D27di = this; - _lockM04D27di = new object(); - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - _lockM04D27di = _rootM04D27di._lockM04D27di; - } - - public Pure.DI.UsageTests.Basics.TrackingAsyncDisposableInDelegatesScenario.Service Root - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - var perResolveM04D27di39_Func = default(System.Func>); - perResolveM04D27di39_Func = new global::System.Func>( - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)768)] - () => - { - var accumulatorM04D27di38 = new Pure.DI.Owned(); - Pure.DI.UsageTests.Basics.TrackingAsyncDisposableInDelegatesScenario.Dependency transientM04D27di3_Dependency = new Pure.DI.UsageTests.Basics.TrackingAsyncDisposableInDelegatesScenario.Dependency(); - lock (_lockM04D27di) - { - accumulatorM04D27di38.Add(transientM04D27di3_Dependency); - } - Pure.DI.Owned perBlockM04D27di1_Owned; - { - var owned_M04D27di2 = accumulatorM04D27di38; - var value_M04D27di3 = transientM04D27di3_Dependency; - perBlockM04D27di1_Owned = new Owned(value_M04D27di3, owned_M04D27di2); - } - lock (_lockM04D27di) - { - accumulatorM04D27di38.Add(perBlockM04D27di1_Owned); - } - var value_M04D27di1 = perBlockM04D27di1_Owned; - return value_M04D27di1; - }); - return new Pure.DI.UsageTests.Basics.TrackingAsyncDisposableInDelegatesScenario.Service(perResolveM04D27di39_Func); - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Basics.TrackingAsyncDisposableInDelegatesScenario.Service), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Basics.TrackingAsyncDisposableInDelegatesScenario.Service Resolve(Composition composition) - { - return composition.Root; - } - - public Pure.DI.UsageTests.Basics.TrackingAsyncDisposableInDelegatesScenario.Service ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.Root; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Basics.TrackingAsyncDisposableInDelegatesScenario.Service."); - } - } - } + _rootM04D27di = this; + _lockM04D27di = new object(); +} + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; + _lockM04D27di = _rootM04D27di._lockM04D27di; +} + +public Pure.DI.UsageTests.Basics.TrackingAsyncDisposableInDelegatesScenario.Service Root +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + var perResolveM04D27di39_Func = default(System.Func>); + perResolveM04D27di39_Func = new global::System.Func>( + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)768)] + () => + { + var accumulatorM04D27di38 = new Pure.DI.Owned(); + Pure.DI.UsageTests.Basics.TrackingAsyncDisposableInDelegatesScenario.Dependency transientM04D27di3_Dependency = new Pure.DI.UsageTests.Basics.TrackingAsyncDisposableInDelegatesScenario.Dependency(); + lock (_lockM04D27di) + { + accumulatorM04D27di38.Add(transientM04D27di3_Dependency); + } + Pure.DI.Owned perBlockM04D27di1_Owned; + { + var owned_M04D27di2 = accumulatorM04D27di38; + var value_M04D27di3 = transientM04D27di3_Dependency; + perBlockM04D27di1_Owned = new Owned(value_M04D27di3, owned_M04D27di2); + } + lock (_lockM04D27di) + { + accumulatorM04D27di38.Add(perBlockM04D27di1_Owned); + } + var value_M04D27di1 = perBlockM04D27di1_Owned; + return value_M04D27di1; + }); + return new Pure.DI.UsageTests.Basics.TrackingAsyncDisposableInDelegatesScenario.Service(perResolveM04D27di39_Func); + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Basics.TrackingAsyncDisposableInDelegatesScenario.Service), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.Basics.TrackingAsyncDisposableInDelegatesScenario.Service Resolve(Composition composition) + { + return composition.Root; + } + + public Pure.DI.UsageTests.Basics.TrackingAsyncDisposableInDelegatesScenario.Service ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.Root; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Basics.TrackingAsyncDisposableInDelegatesScenario.Service."); + } + } } + } ```
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 69af284db..f144639c6 100644 --- a/readme/tracking-async-disposable-instances-per-a-composition-root.md +++ b/readme/tracking-async-disposable-instances-per-a-composition-root.md @@ -67,36 +67,36 @@ root1.Value.Dependency.IsDisposed.ShouldBeTrue(); ```mermaid classDiagram - class Composition { - +OwnedᐸIServiceᐳ Root - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - class Owned - Dependency --|> IDependency : - Dependency --|> IAsyncDisposable : - class Dependency { - +Dependency() - } - Service --|> IService : - class Service { - +Service(IDependency dependency) - } - class IDependency { - <> - } - class IAsyncDisposable { - <> - } - class IService { - <> - } - Service *-- Dependency : IDependency - Composition ..> OwnedᐸIServiceᐳ : OwnedᐸIServiceᐳ Root - OwnedᐸIServiceᐳ *-- Owned : Owned - OwnedᐸIServiceᐳ *-- Service : IService + class Composition { + +OwnedᐸIServiceᐳ Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + class Owned + Dependency --|> IDependency : + Dependency --|> IAsyncDisposable : + class Dependency { + +Dependency() + } + Service --|> IService : + class Service { + +Service(IDependency dependency) + } + class IDependency { + <> + } + class IAsyncDisposable { + <> + } + class IService { + <> + } + Service *-- Dependency : IDependency + Composition ..> OwnedᐸIServiceᐳ : OwnedᐸIServiceᐳ Root + OwnedᐸIServiceᐳ *-- Owned : Owned + OwnedᐸIServiceᐳ *-- Service : IService ``` @@ -105,123 +105,123 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; +private readonly object _lockM04D27di; + +public Composition() { - private readonly Composition _rootM04D27di; - private readonly object _lockM04D27di; - - public Composition() - { - _rootM04D27di = this; - _lockM04D27di = new object(); - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - _lockM04D27di = _rootM04D27di._lockM04D27di; - } - - public Pure.DI.Owned Root - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - var accumulatorM04D27di38 = new Pure.DI.Owned(); - Pure.DI.UsageTests.Basics.TrackingAsyncDisposableScenario.Dependency transientM04D27di3_Dependency = new Pure.DI.UsageTests.Basics.TrackingAsyncDisposableScenario.Dependency(); - lock (_lockM04D27di) - { - accumulatorM04D27di38.Add(transientM04D27di3_Dependency); - } - Pure.DI.Owned perBlockM04D27di0_Owned; - { - var owned_M04D27di1 = accumulatorM04D27di38; - var value_M04D27di2 = new Pure.DI.UsageTests.Basics.TrackingAsyncDisposableScenario.Service(transientM04D27di3_Dependency); - perBlockM04D27di0_Owned = new Owned(value_M04D27di2, owned_M04D27di1); - } - lock (_lockM04D27di) - { - accumulatorM04D27di38.Add(perBlockM04D27di0_Owned); - } - return perBlockM04D27di0_Owned; - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } + _rootM04D27di = this; + _lockM04D27di = new object(); +} + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; + _lockM04D27di = _rootM04D27di._lockM04D27di; +} + +public Pure.DI.Owned Root +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + var accumulatorM04D27di38 = new Pure.DI.Owned(); + Pure.DI.UsageTests.Basics.TrackingAsyncDisposableScenario.Dependency transientM04D27di3_Dependency = new Pure.DI.UsageTests.Basics.TrackingAsyncDisposableScenario.Dependency(); + lock (_lockM04D27di) + { + accumulatorM04D27di38.Add(transientM04D27di3_Dependency); + } + Pure.DI.Owned perBlockM04D27di0_Owned; + { + var owned_M04D27di1 = accumulatorM04D27di38; + var value_M04D27di2 = new Pure.DI.UsageTests.Basics.TrackingAsyncDisposableScenario.Service(transientM04D27di3_Dependency); + perBlockM04D27di0_Owned = new Owned(value_M04D27di2, owned_M04D27di1); + } + lock (_lockM04D27di) + { + accumulatorM04D27di38.Add(perBlockM04D27di0_Owned); + } + return perBlockM04D27di0_Owned; + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } } + } ```
diff --git a/readme/tracking-disposable-instances-in-delegates.md b/readme/tracking-disposable-instances-in-delegates.md index cced6689b..207a33fe1 100644 --- a/readme/tracking-disposable-instances-in-delegates.md +++ b/readme/tracking-disposable-instances-in-delegates.md @@ -67,35 +67,35 @@ root1.Dependency.IsDisposed.ShouldBeTrue(); ```mermaid classDiagram - class Composition { - +Service Root - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - class Owned - Dependency --|> IDependency : - class Dependency { - +Dependency() - } - Service --|> IService : - class Service { - +Service(FuncᐸOwnedᐸIDependencyᐳᐳ dependencyFactory) - } - class FuncᐸOwnedᐸIDependencyᐳᐳ - class OwnedᐸIDependencyᐳ - class IDependency { - <> - } - class IService { - <> - } - Service o-- "PerResolve" FuncᐸOwnedᐸIDependencyᐳᐳ : FuncᐸOwnedᐸIDependencyᐳᐳ - Composition ..> Service : Service Root - FuncᐸOwnedᐸIDependencyᐳᐳ o-- "PerBlock" OwnedᐸIDependencyᐳ : OwnedᐸIDependencyᐳ - OwnedᐸIDependencyᐳ *-- Owned : Owned - OwnedᐸIDependencyᐳ *-- Dependency : IDependency + class Composition { + +Service Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + class Owned + Dependency --|> IDependency : + class Dependency { + +Dependency() + } + Service --|> IService : + class Service { + +Service(FuncᐸOwnedᐸIDependencyᐳᐳ dependencyFactory) + } + class FuncᐸOwnedᐸIDependencyᐳᐳ + class OwnedᐸIDependencyᐳ + class IDependency { + <> + } + class IService { + <> + } + Service o-- "PerResolve" FuncᐸOwnedᐸIDependencyᐳᐳ : FuncᐸOwnedᐸIDependencyᐳᐳ + Composition ..> Service : Service Root + FuncᐸOwnedᐸIDependencyᐳᐳ o-- "PerBlock" OwnedᐸIDependencyᐳ : OwnedᐸIDependencyᐳ + OwnedᐸIDependencyᐳ *-- Owned : Owned + OwnedᐸIDependencyᐳ *-- Dependency : IDependency ``` @@ -104,201 +104,201 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; +private readonly object _lockM04D27di; + +public Composition() +{ + _rootM04D27di = this; + _lockM04D27di = new object(); +} + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; + _lockM04D27di = _rootM04D27di._lockM04D27di; +} + +public Pure.DI.UsageTests.Basics.TrackingDisposableInDelegatesScenario.Service Root +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + var perResolveM04D27di39_Func = default(System.Func>); + perResolveM04D27di39_Func = new global::System.Func>( + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)768)] + () => + { + var accumulatorM04D27di38 = new Pure.DI.Owned(); + Pure.DI.UsageTests.Basics.TrackingDisposableInDelegatesScenario.Dependency transientM04D27di3_Dependency = new Pure.DI.UsageTests.Basics.TrackingDisposableInDelegatesScenario.Dependency(); + lock (_lockM04D27di) + { + accumulatorM04D27di38.Add(transientM04D27di3_Dependency); + } + Pure.DI.Owned perBlockM04D27di1_Owned; + { + var owned_M04D27di2 = accumulatorM04D27di38; + var value_M04D27di3 = transientM04D27di3_Dependency; + perBlockM04D27di1_Owned = new Owned(value_M04D27di3, owned_M04D27di2); + } + lock (_lockM04D27di) + { + accumulatorM04D27di38.Add(perBlockM04D27di1_Owned); + } + var value_M04D27di1 = perBlockM04D27di1_Owned; + return value_M04D27di1; + }); + return new Pure.DI.UsageTests.Basics.TrackingDisposableInDelegatesScenario.Service(perResolveM04D27di39_Func); + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Basics.TrackingDisposableInDelegatesScenario.Service), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver { - private readonly Composition _rootM04D27di; - private readonly object _lockM04D27di; - - public Composition() - { - _rootM04D27di = this; - _lockM04D27di = new object(); - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - _lockM04D27di = _rootM04D27di._lockM04D27di; - } - - public Pure.DI.UsageTests.Basics.TrackingDisposableInDelegatesScenario.Service Root - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - var perResolveM04D27di39_Func = default(System.Func>); - perResolveM04D27di39_Func = new global::System.Func>( - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)768)] - () => - { - var accumulatorM04D27di38 = new Pure.DI.Owned(); - Pure.DI.UsageTests.Basics.TrackingDisposableInDelegatesScenario.Dependency transientM04D27di3_Dependency = new Pure.DI.UsageTests.Basics.TrackingDisposableInDelegatesScenario.Dependency(); - lock (_lockM04D27di) - { - accumulatorM04D27di38.Add(transientM04D27di3_Dependency); - } - Pure.DI.Owned perBlockM04D27di1_Owned; - { - var owned_M04D27di2 = accumulatorM04D27di38; - var value_M04D27di3 = transientM04D27di3_Dependency; - perBlockM04D27di1_Owned = new Owned(value_M04D27di3, owned_M04D27di2); - } - lock (_lockM04D27di) - { - accumulatorM04D27di38.Add(perBlockM04D27di1_Owned); - } - var value_M04D27di1 = perBlockM04D27di1_Owned; - return value_M04D27di1; - }); - return new Pure.DI.UsageTests.Basics.TrackingDisposableInDelegatesScenario.Service(perResolveM04D27di39_Func); - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Basics.TrackingDisposableInDelegatesScenario.Service), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Basics.TrackingDisposableInDelegatesScenario.Service Resolve(Composition composition) - { - return composition.Root; - } - - public Pure.DI.UsageTests.Basics.TrackingDisposableInDelegatesScenario.Service ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.Root; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Basics.TrackingDisposableInDelegatesScenario.Service."); - } - } - } + public Pure.DI.UsageTests.Basics.TrackingDisposableInDelegatesScenario.Service Resolve(Composition composition) + { + return composition.Root; + } + + public Pure.DI.UsageTests.Basics.TrackingDisposableInDelegatesScenario.Service ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.Root; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Basics.TrackingDisposableInDelegatesScenario.Service."); + } + } } + } ```
diff --git a/readme/tracking-disposable-instances-per-a-composition-root.md b/readme/tracking-disposable-instances-per-a-composition-root.md index d7fd6e53c..3d15faaa1 100644 --- a/readme/tracking-disposable-instances-per-a-composition-root.md +++ b/readme/tracking-disposable-instances-per-a-composition-root.md @@ -63,32 +63,32 @@ root1.Value.Dependency.IsDisposed.ShouldBeTrue(); ```mermaid classDiagram - class Composition { - +OwnedᐸIServiceᐳ Root - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - class Owned - Dependency --|> IDependency : - class Dependency { - +Dependency() - } - Service --|> IService : - class Service { - +Service(IDependency dependency) - } - class IDependency { - <> - } - class IService { - <> - } - Service *-- Dependency : IDependency - Composition ..> OwnedᐸIServiceᐳ : OwnedᐸIServiceᐳ Root - OwnedᐸIServiceᐳ *-- Owned : Owned - OwnedᐸIServiceᐳ *-- Service : IService + class Composition { + +OwnedᐸIServiceᐳ Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + class Owned + Dependency --|> IDependency : + class Dependency { + +Dependency() + } + Service --|> IService : + class Service { + +Service(IDependency dependency) + } + class IDependency { + <> + } + class IService { + <> + } + Service *-- Dependency : IDependency + Composition ..> OwnedᐸIServiceᐳ : OwnedᐸIServiceᐳ Root + OwnedᐸIServiceᐳ *-- Owned : Owned + OwnedᐸIServiceᐳ *-- Service : IService ``` @@ -97,119 +97,119 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; +private readonly object _lockM04D27di; + +public Composition() +{ + _rootM04D27di = this; + _lockM04D27di = new object(); +} + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; + _lockM04D27di = _rootM04D27di._lockM04D27di; +} + +public Pure.DI.Owned Root +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + var accumulatorM04D27di38 = new Pure.DI.Owned(); + Pure.DI.UsageTests.Basics.TrackingDisposableScenario.Dependency transientM04D27di3_Dependency = new Pure.DI.UsageTests.Basics.TrackingDisposableScenario.Dependency(); + lock (_lockM04D27di) + { + accumulatorM04D27di38.Add(transientM04D27di3_Dependency); + } + Pure.DI.Owned perBlockM04D27di0_Owned; + { + var owned_M04D27di1 = accumulatorM04D27di38; + var value_M04D27di2 = new Pure.DI.UsageTests.Basics.TrackingDisposableScenario.Service(transientM04D27di3_Dependency); + perBlockM04D27di0_Owned = new Owned(value_M04D27di2, owned_M04D27di1); + } + lock (_lockM04D27di) + { + accumulatorM04D27di38.Add(perBlockM04D27di0_Owned); + } + return perBlockM04D27di0_Owned; + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 sealed class ResolverM04D27di: global::Pure.DI.IResolver { - private readonly Composition _rootM04D27di; - private readonly object _lockM04D27di; - - public Composition() - { - _rootM04D27di = this; - _lockM04D27di = new object(); - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - _lockM04D27di = _rootM04D27di._lockM04D27di; - } - - public Pure.DI.Owned Root - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - var accumulatorM04D27di38 = new Pure.DI.Owned(); - Pure.DI.UsageTests.Basics.TrackingDisposableScenario.Dependency transientM04D27di3_Dependency = new Pure.DI.UsageTests.Basics.TrackingDisposableScenario.Dependency(); - lock (_lockM04D27di) - { - accumulatorM04D27di38.Add(transientM04D27di3_Dependency); - } - Pure.DI.Owned perBlockM04D27di0_Owned; - { - var owned_M04D27di1 = accumulatorM04D27di38; - var value_M04D27di2 = new Pure.DI.UsageTests.Basics.TrackingDisposableScenario.Service(transientM04D27di3_Dependency); - perBlockM04D27di0_Owned = new Owned(value_M04D27di2, owned_M04D27di1); - } - lock (_lockM04D27di) - { - accumulatorM04D27di38.Add(perBlockM04D27di0_Owned); - } - return perBlockM04D27di0_Owned; - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } } + } ```
diff --git a/readme/transient.md b/readme/transient.md index dea8016cf..f1cbed0e4 100644 --- a/readme/transient.md +++ b/readme/transient.md @@ -42,30 +42,30 @@ service2.Dependency1.ShouldNotBe(service1.Dependency1); ```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 : - class Dependency { - +Dependency() - } - Service --|> IService : - class Service { - +Service(IDependency dependency1, IDependency dependency2) - } - class IDependency { - <> - } - class IService { - <> - } - Service *-- Dependency : IDependency - Service *-- Dependency : IDependency - Composition ..> Service : IService Root + class Composition { + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + Dependency --|> IDependency : + class Dependency { + +Dependency() + } + Service --|> IService : + class Service { + +Service(IDependency dependency1, IDependency dependency2) + } + class IDependency { + <> + } + class IService { + <> + } + Service *-- Dependency : IDependency + Service *-- Dependency : IDependency + Composition ..> Service : IService Root ``` @@ -74,169 +74,169 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; + +public Composition() { - private readonly Composition _rootM04D27di; - - public Composition() - { - _rootM04D27di = this; - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - } - - public Pure.DI.UsageTests.Lifetimes.TransientScenario.IService Root - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - return new Pure.DI.UsageTests.Lifetimes.TransientScenario.Service(new Pure.DI.UsageTests.Lifetimes.TransientScenario.Dependency(), new Pure.DI.UsageTests.Lifetimes.TransientScenario.Dependency()); - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Lifetimes.TransientScenario.IService), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Lifetimes.TransientScenario.IService Resolve(Composition composition) - { - return composition.Root; - } - - public Pure.DI.UsageTests.Lifetimes.TransientScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.Root; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Lifetimes.TransientScenario.IService."); - } - } - } + _rootM04D27di = this; } + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; +} + +public Pure.DI.UsageTests.Lifetimes.TransientScenario.IService Root +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + return new Pure.DI.UsageTests.Lifetimes.TransientScenario.Service(new Pure.DI.UsageTests.Lifetimes.TransientScenario.Dependency(), new Pure.DI.UsageTests.Lifetimes.TransientScenario.Dependency()); + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Lifetimes.TransientScenario.IService), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.Lifetimes.TransientScenario.IService Resolve(Composition composition) + { + return composition.Root; + } + + public Pure.DI.UsageTests.Lifetimes.TransientScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.Root; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Lifetimes.TransientScenario.IService."); + } + } +} + } ```
diff --git a/readme/tuple.md b/readme/tuple.md index 9fea0240b..54652d4a5 100644 --- a/readme/tuple.md +++ b/readme/tuple.md @@ -38,35 +38,35 @@ var root = composition.Root; ```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 ValueTupleᐸPointˏIDependencyᐳ { - +ValueTuple(Point item1, IDependency item2) - } - class Point - Dependency --|> IDependency : - class Dependency { - +Dependency() - } - Service --|> IService : - class Service { - +Service(ValueTupleᐸPointˏIDependencyᐳ tuple) - } - class IDependency { - <> - } - class IService { - <> - } - ValueTupleᐸPointˏIDependencyᐳ *-- Point : Point - ValueTupleᐸPointˏIDependencyᐳ *-- Dependency : IDependency - Service *-- ValueTupleᐸPointˏIDependencyᐳ : ValueTupleᐸPointˏIDependencyᐳ - Composition ..> Service : IService Root + class Composition { + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + class ValueTupleᐸPointˏIDependencyᐳ { + +ValueTuple(Point item1, IDependency item2) + } + class Point + Dependency --|> IDependency : + class Dependency { + +Dependency() + } + Service --|> IService : + class Service { + +Service(ValueTupleᐸPointˏIDependencyᐳ tuple) + } + class IDependency { + <> + } + class IService { + <> + } + ValueTupleᐸPointˏIDependencyᐳ *-- Point : Point + ValueTupleᐸPointˏIDependencyᐳ *-- Dependency : IDependency + Service *-- ValueTupleᐸPointˏIDependencyᐳ : ValueTupleᐸPointˏIDependencyᐳ + Composition ..> Service : IService Root ``` @@ -75,175 +75,175 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; + +public Composition() { - private readonly Composition _rootM04D27di; - - public Composition() - { - _rootM04D27di = this; - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - } - - public Pure.DI.UsageTests.BCL.TupleScenario.IService Root - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - Pure.DI.UsageTests.BCL.TupleScenario.Point transientM04D27di2_Point = new Point(7, 9); - return new Pure.DI.UsageTests.BCL.TupleScenario.Service((transientM04D27di2_Point, new Pure.DI.UsageTests.BCL.TupleScenario.Dependency())); - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.BCL.TupleScenario.IService), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.BCL.TupleScenario.IService Resolve(Composition composition) - { - return composition.Root; - } - - public Pure.DI.UsageTests.BCL.TupleScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.Root; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.BCL.TupleScenario.IService."); - } - } - } + _rootM04D27di = this; } + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; +} + +public Pure.DI.UsageTests.BCL.TupleScenario.IService Root +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + Pure.DI.UsageTests.BCL.TupleScenario.Point transientM04D27di2_Point = new Point(7, 9); + return new Pure.DI.UsageTests.BCL.TupleScenario.Service((transientM04D27di2_Point, new Pure.DI.UsageTests.BCL.TupleScenario.Dependency())); + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.BCL.TupleScenario.IService), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.BCL.TupleScenario.IService Resolve(Composition composition) + { + return composition.Root; + } + + public Pure.DI.UsageTests.BCL.TupleScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.Root; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.BCL.TupleScenario.IService."); + } + } +} + } ```
diff --git a/readme/type-attribute.md b/readme/type-attribute.md index d015a8c46..5754141dd 100644 --- a/readme/type-attribute.md +++ b/readme/type-attribute.md @@ -47,29 +47,29 @@ This attribute is part of the API, but you can use your own attribute at any tim ```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 XyzDependency { - +XyzDependency() - } - class AbcDependency { - +AbcDependency() - } - Service --|> IService : - class Service { - +Service(IDependency dependency1, IDependency dependency2) - } - class IService { - <> - } - Service *-- AbcDependency : AbcDependency - Service *-- XyzDependency : XyzDependency - Composition ..> Service : IService Root + class Composition { + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + class XyzDependency { + +XyzDependency() + } + class AbcDependency { + +AbcDependency() + } + Service --|> IService : + class Service { + +Service(IDependency dependency1, IDependency dependency2) + } + class IService { + <> + } + Service *-- AbcDependency : AbcDependency + Service *-- XyzDependency : XyzDependency + Composition ..> Service : IService Root ``` @@ -78,168 +78,168 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; + +public Composition() { - private readonly Composition _rootM04D27di; - - public Composition() - { - _rootM04D27di = this; - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - } - - public Pure.DI.UsageTests.Attributes.TypeAttributeScenario.IService Root - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - return new Pure.DI.UsageTests.Attributes.TypeAttributeScenario.Service(new Pure.DI.UsageTests.Attributes.TypeAttributeScenario.AbcDependency(), new Pure.DI.UsageTests.Attributes.TypeAttributeScenario.XyzDependency()); - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Attributes.TypeAttributeScenario.IService), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.Attributes.TypeAttributeScenario.IService Resolve(Composition composition) - { - return composition.Root; - } - - public Pure.DI.UsageTests.Attributes.TypeAttributeScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.Root; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Attributes.TypeAttributeScenario.IService."); - } - } - } + _rootM04D27di = this; } + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; +} + +public Pure.DI.UsageTests.Attributes.TypeAttributeScenario.IService Root +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + return new Pure.DI.UsageTests.Attributes.TypeAttributeScenario.Service(new Pure.DI.UsageTests.Attributes.TypeAttributeScenario.AbcDependency(), new Pure.DI.UsageTests.Attributes.TypeAttributeScenario.XyzDependency()); + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.Attributes.TypeAttributeScenario.IService), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.Attributes.TypeAttributeScenario.IService Resolve(Composition composition) + { + return composition.Root; + } + + public Pure.DI.UsageTests.Attributes.TypeAttributeScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.Root; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.Attributes.TypeAttributeScenario.IService."); + } + } +} + } ```
diff --git a/readme/valuetask.md b/readme/valuetask.md index 5d9be10c4..9acbd7970 100644 --- a/readme/valuetask.md +++ b/readme/valuetask.md @@ -44,31 +44,31 @@ await service.RunAsync(); ```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 : - class Dependency { - +Dependency() - } - Service --|> IService : - class Service { - +Service(ValueTaskᐸIDependencyᐳ dependencyTask) - } - class ValueTaskᐸIDependencyᐳ - class IDependency { - <> - } - class IService { - <> - } - Service *-- ValueTaskᐸIDependencyᐳ : ValueTaskᐸIDependencyᐳ - Composition ..> Service : IService Root - ValueTaskᐸIDependencyᐳ *-- Dependency : IDependency + class Composition { + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + Dependency --|> IDependency : + class Dependency { + +Dependency() + } + Service --|> IService : + class Service { + +Service(ValueTaskᐸIDependencyᐳ dependencyTask) + } + class ValueTaskᐸIDependencyᐳ + class IDependency { + <> + } + class IService { + <> + } + Service *-- ValueTaskᐸIDependencyᐳ : ValueTaskᐸIDependencyᐳ + Composition ..> Service : IService Root + ValueTaskᐸIDependencyᐳ *-- Dependency : IDependency ``` @@ -77,175 +77,175 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition -{ - private readonly Composition _rootM04D27di; - - public Composition() - { - _rootM04D27di = this; - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - } - - public Pure.DI.UsageTests.BCL.ValueTaskScenario.IService Root - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - System.Threading.Tasks.ValueTask transientM04D27di1_ValueTask; - { - var value_M04D27di1 = new Pure.DI.UsageTests.BCL.ValueTaskScenario.Dependency(); - transientM04D27di1_ValueTask = new global::System.Threading.Tasks.ValueTask(value_M04D27di1); - } - return new Pure.DI.UsageTests.BCL.ValueTaskScenario.Service(transientM04D27di1_ValueTask); - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.BCL.ValueTaskScenario.IService), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.BCL.ValueTaskScenario.IService Resolve(Composition composition) - { - return composition.Root; - } - - public Pure.DI.UsageTests.BCL.ValueTaskScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.Root; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.BCL.ValueTaskScenario.IService."); - } - } - } +artial class Composition + { +private readonly Composition _rootM04D27di; + +public Composition() +{ + _rootM04D27di = this; +} + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; +} + +public Pure.DI.UsageTests.BCL.ValueTaskScenario.IService Root +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + System.Threading.Tasks.ValueTask transientM04D27di1_ValueTask; + { + var value_M04D27di1 = new Pure.DI.UsageTests.BCL.ValueTaskScenario.Dependency(); + transientM04D27di1_ValueTask = new global::System.Threading.Tasks.ValueTask(value_M04D27di1); + } + return new Pure.DI.UsageTests.BCL.ValueTaskScenario.Service(transientM04D27di1_ValueTask); + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.BCL.ValueTaskScenario.IService), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.BCL.ValueTaskScenario.IService Resolve(Composition composition) + { + return composition.Root; + } + + public Pure.DI.UsageTests.BCL.ValueTaskScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.Root; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.BCL.ValueTaskScenario.IService."); + } + } } + } ```
diff --git a/readme/weak-reference.md b/readme/weak-reference.md index cd26beea7..19aff35ff 100644 --- a/readme/weak-reference.md +++ b/readme/weak-reference.md @@ -33,33 +33,33 @@ var service = composition.Root; ```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 WeakReferenceᐸIDependencyᐳ { - +WeakReference(IDependency target) - } - Dependency --|> IDependency : - class Dependency { - +Dependency() - } - Service --|> IService : - class Service { - +Service(WeakReferenceᐸIDependencyᐳ dependency) - } - class IDependency { - <> - } - class IService { - <> - } - WeakReferenceᐸIDependencyᐳ *-- Dependency : IDependency - Service *-- WeakReferenceᐸIDependencyᐳ : WeakReferenceᐸIDependencyᐳ - Composition ..> Service : IService Root + class Composition { + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + class WeakReferenceᐸIDependencyᐳ { + +WeakReference(IDependency target) + } + Dependency --|> IDependency : + class Dependency { + +Dependency() + } + Service --|> IService : + class Service { + +Service(WeakReferenceᐸIDependencyᐳ dependency) + } + class IDependency { + <> + } + class IService { + <> + } + WeakReferenceᐸIDependencyᐳ *-- Dependency : IDependency + Service *-- WeakReferenceᐸIDependencyᐳ : WeakReferenceᐸIDependencyᐳ + Composition ..> Service : IService Root ``` @@ -68,172 +68,172 @@ classDiagram Pure.DI-generated partial class Composition
```c# -partial class Composition +artial class Composition + { +private readonly Composition _rootM04D27di; + +public Composition() { - private readonly Composition _rootM04D27di; - - public Composition() - { - _rootM04D27di = this; - } - - internal Composition(Composition baseComposition) - { - _rootM04D27di = baseComposition._rootM04D27di; - } - - public Pure.DI.UsageTests.BCL.WeakReferenceScenario.IService Root - { - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - get - { - return new Pure.DI.UsageTests.BCL.WeakReferenceScenario.Service(new System.WeakReference(new Pure.DI.UsageTests.BCL.WeakReferenceScenario.Dependency())); - } - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve() - { - return ResolverM04D27di.Value.Resolve(this); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public T Resolve(object? tag) - { - return ResolverM04D27di.Value.ResolveByTag(this, tag); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.Resolve(this); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] - public object Resolve(global::System.Type type, object? tag) - { - var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); - ref var pair = ref _bucketsM04D27di[index]; - return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); - } - - [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] - private object ResolveM04D27di(global::System.Type type, object? tag, int index) - { - var finish = index + _bucketSizeM04D27di; - while (++index < finish) - { - ref var pair = ref _bucketsM04D27di[index]; - if (pair.Key == type) - { - return pair.Value.ResolveByTag(this, tag); - } - } - - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; - private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; - - static Composition() - { - var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); - ResolverM04D27di.Value = valResolverM04D27di_0000; - _bucketsM04D27di = global::Pure.DI.Buckets>.Create( - 1, - out _bucketSizeM04D27di, - new global::Pure.DI.Pair>[1] - { - new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.BCL.WeakReferenceScenario.IService), valResolverM04D27di_0000) - }); - } - - private sealed class ResolverM04D27di: global::Pure.DI.IResolver - { - public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); - - public T Resolve(Composition composite) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); - } - - public T ResolveByTag(Composition composite, object tag) - { - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); - } - } - - private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver - { - public Pure.DI.UsageTests.BCL.WeakReferenceScenario.IService Resolve(Composition composition) - { - return composition.Root; - } - - public Pure.DI.UsageTests.BCL.WeakReferenceScenario.IService ResolveByTag(Composition composition, object tag) - { - switch (tag) - { - case null: - return composition.Root; - default: - throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.BCL.WeakReferenceScenario.IService."); - } - } - } + _rootM04D27di = this; } + +internal Composition(Composition baseComposition) +{ + _rootM04D27di = baseComposition._rootM04D27di; +} + +public Pure.DI.UsageTests.BCL.WeakReferenceScenario.IService Root +{ + [global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] + get + { + return new Pure.DI.UsageTests.BCL.WeakReferenceScenario.Service(new System.WeakReference(new Pure.DI.UsageTests.BCL.WeakReferenceScenario.Dependency())); + } +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve() +{ + return ResolverM04D27di.Value.Resolve(this); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public T Resolve(object? tag) +{ + return ResolverM04D27di.Value.ResolveByTag(this, tag); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.Resolve(this) : ResolveM04D27di(type, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.Resolve(this); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}."); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)] +public object Resolve(global::System.Type type, object? tag) +{ + var index = (int)(_bucketSizeM04D27di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1)); + ref var pair = ref _bucketsM04D27di[index]; + return pair.Key == type ? pair.Value.ResolveByTag(this, tag) : ResolveM04D27di(type, tag, index); +} + +[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x8)] +private object ResolveM04D27di(global::System.Type type, object? tag, int index) +{ + var finish = index + _bucketSizeM04D27di; + while (++index < finish) + { + ref var pair = ref _bucketsM04D27di[index]; + if (pair.Key == type) + { + return pair.Value.ResolveByTag(this, tag); + } + } + + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {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 _bucketSizeM04D27di; +private readonly static global::Pure.DI.Pair>[] _bucketsM04D27di; + +static Composition() +{ + var valResolverM04D27di_0000 = new ResolverM04D27di_0000(); + ResolverM04D27di.Value = valResolverM04D27di_0000; + _bucketsM04D27di = global::Pure.DI.Buckets>.Create( + 1, + out _bucketSizeM04D27di, + new global::Pure.DI.Pair>[1] + { + new global::Pure.DI.Pair>(typeof(Pure.DI.UsageTests.BCL.WeakReferenceScenario.IService), valResolverM04D27di_0000) + }); +} + +private sealed class ResolverM04D27di: global::Pure.DI.IResolver +{ + public static global::Pure.DI.IResolver Value = new ResolverM04D27di(); + + public T Resolve(Composition composite) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {typeof(T)}."); + } + + public T ResolveByTag(Composition composite, object tag) + { + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {typeof(T)}."); + } +} + +private sealed class ResolverM04D27di_0000: global::Pure.DI.IResolver +{ + public Pure.DI.UsageTests.BCL.WeakReferenceScenario.IService Resolve(Composition composition) + { + return composition.Root; + } + + public Pure.DI.UsageTests.BCL.WeakReferenceScenario.IService ResolveByTag(Composition composition, object tag) + { + switch (tag) + { + case null: + return composition.Root; + default: + throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type Pure.DI.UsageTests.BCL.WeakReferenceScenario.IService."); + } + } +} + } ```