From aa75463c866ec20b98eda63e3255bd4a31923b65 Mon Sep 17 00:00:00 2001 From: Nikolay Pianikov Date: Mon, 13 May 2024 16:25:33 +0300 Subject: [PATCH] Improved readme --- build/ReadmeTarget.cs | 27 ++-- readme/ArrayDetails.md | 6 +- readme/EnumDetails.md | 6 +- readme/FuncDetails.md | 6 +- readme/SingletonDetails.md | 6 +- readme/TransientDetails.md | 6 +- readme/a-few-partial-classes.md | 67 +++++---- readme/accumulators.md | 91 ++++++------ readme/advanced-interception.md | 67 +++++---- readme/arguments.md | 75 +++++----- readme/array.md | 81 ++++++----- readme/async-disposable-scope.md | 105 +++++++------- readme/async-disposable-singleton.md | 79 +++++------ readme/async-enumerable.md | 81 ++++++----- readme/auto-bindings.md | 43 +++--- readme/auto-scoped.md | 81 ++++++----- readme/check-for-a-root.md | 73 +++++----- readme/complex-generics.md | 91 ++++++------ readme/composition-root-kinds.md | 83 ++++++----- readme/composition-roots.md | 83 ++++++----- readme/constructor-ordinal-attribute.md | 55 ++++---- readme/custom-attributes.md | 61 ++++----- readme/decorator.md | 61 ++++----- readme/default-lifetime.md | 67 +++++---- readme/default-values.md | 69 +++++----- readme/dependent-compositions.md | 85 ++++++------ readme/disposable-singleton.md | 69 +++++----- readme/enumerable-generics.md | 129 +++++++++--------- readme/enumerable.md | 81 ++++++----- readme/factory.md | 63 ++++----- readme/field-injection.md | 69 +++++----- readme/func-with-arguments.md | 83 ++++++----- readme/func-with-tag.md | 71 +++++----- readme/func.md | 71 +++++----- ...eric-composition-roots-with-constraints.md | 75 +++++----- readme/generic-composition-roots.md | 69 +++++----- readme/generics.md | 83 ++++++----- readme/global-compositions.md | 4 + readme/injections-of-abstractions.md | 65 ++++----- readme/interception.md | 51 ++++--- readme/keyed-service-provider.md | 71 +++++----- readme/lazy.md | 75 +++++----- readme/manually-started-tasks.md | 81 ++++++----- readme/member-ordinal-attribute.md | 69 +++++----- readme/method-injection.md | 69 +++++----- readme/oncannotresolve-hint.md | 71 +++++----- readme/ondependencyinjection-hint.md | 67 +++++---- readme/onnewinstance-hint.md | 67 +++++---- readme/overriding-the-bcl-binding.md | 55 ++++---- readme/partial-class.md | 67 +++++---- readme/perblock.md | 77 +++++------ readme/perresolve.md | 77 +++++------ readme/property-injection.md | 69 +++++----- readme/required-properties-or-fields.md | 75 +++++----- readme/resolve-hint.md | 63 ++++----- readme/resolve-methods.md | 83 ++++++----- readme/root-arguments.md | 59 ++++---- readme/root-binding.md | 51 ++++--- readme/scope.md | 95 ++++++------- readme/service-collection.md | 71 +++++----- readme/service-provider-with-scope.md | 73 +++++----- readme/service-provider.md | 71 +++++----- readme/simplified-binding.md | 63 ++++----- readme/singleton.md | 67 +++++---- readme/span-and-readonlyspan.md | 67 +++++---- readme/tag-attribute.md | 77 +++++------ readme/tag-type.md | 85 ++++++------ readme/tag-unique.md | 81 ++++++----- readme/tags.md | 85 ++++++------ readme/task.md | 97 +++++++------ readme/threadsafe-hint.md | 67 +++++---- readme/tostring-hint.md | 67 +++++---- ...async-disposable-instances-in-delegates.md | 87 ++++++------ ...osable-instances-per-a-composition-root.md | 81 ++++++----- ...cking-disposable-instances-in-delegates.md | 79 +++++------ ...osable-instances-per-a-composition-root.md | 73 +++++----- readme/transient.md | 67 +++++---- readme/tuple.md | 79 +++++------ readme/type-attribute.md | 67 +++++---- readme/valuetask.md | 71 +++++----- readme/weak-reference.md | 75 +++++----- 81 files changed, 2568 insertions(+), 2961 deletions(-) diff --git a/build/ReadmeTarget.cs b/build/ReadmeTarget.cs index 44ca4421a..69aae8a16 100644 --- a/build/ReadmeTarget.cs +++ b/build/ReadmeTarget.cs @@ -269,29 +269,35 @@ private async Task GenerateExamples(IEnumerable<(string GroupName, Dictionary"); - await examplesWriter.WriteLineAsync("Class Diagram"); + await examplesWriter.WriteLineAsync("Class diagram:"); await examplesWriter.WriteLineAsync(""); await examplesWriter.WriteLineAsync("```mermaid"); var classDiagram = await File.ReadAllTextAsync(classDiagramFile); await examplesWriter.WriteLineAsync(classDiagram); await examplesWriter.WriteLineAsync("```"); - await examplesWriter.WriteLineAsync(""); - await examplesWriter.WriteLineAsync(""); - await examplesWriter.WriteLineAsync(""); } } @@ -323,8 +324,7 @@ private static async Task AddExample(string logsDirectory, string exampleSearchP { var ns = string.Join('.', Path.GetFileName(generatedCodeFile).Split('.').Reverse().Skip(3).Reverse()) + "."; var name = Path.GetFileName(generatedCodeFile).Split('.').Reverse().Skip(2).FirstOrDefault() ?? "Generated"; - await examplesWriter.WriteLineAsync("
"); - await examplesWriter.WriteLineAsync($"Pure.DI-generated partial class {name}
"); + await examplesWriter.WriteLineAsync("The following partial class will be generated:"); await examplesWriter.WriteLineAsync(""); await examplesWriter.WriteLineAsync("```c#"); var generatedCode = await File.ReadAllTextAsync(generatedCodeFile); @@ -369,9 +369,6 @@ private static async Task AddExample(string logsDirectory, string exampleSearchP .Replace("(MethodImplOptions)0x8", "MethodImplOptions.NoInlining"))); await examplesWriter.WriteLineAsync(generatedCode); await examplesWriter.WriteLineAsync("```"); - await examplesWriter.WriteLineAsync(""); - await examplesWriter.WriteLineAsync("
"); - await examplesWriter.WriteLineAsync(""); } } diff --git a/readme/ArrayDetails.md b/readme/ArrayDetails.md index ef81d680a..01cfc587b 100644 --- a/readme/ArrayDetails.md +++ b/readme/ArrayDetails.md @@ -82,8 +82,7 @@ classDiagram ### Generated code -
-Pure.DI-generated partial class Array
+The following partial class will be generated: ```c# partial class Array @@ -221,6 +220,3 @@ partial class Array } } ``` - -
- diff --git a/readme/EnumDetails.md b/readme/EnumDetails.md index a0f2f06a1..1fb5ab9a7 100644 --- a/readme/EnumDetails.md +++ b/readme/EnumDetails.md @@ -82,8 +82,7 @@ classDiagram ### Generated code -
-Pure.DI-generated partial class Enum
+The following partial class will be generated: ```c# partial class Enum @@ -230,6 +229,3 @@ partial class Enum } } ``` - -
- diff --git a/readme/FuncDetails.md b/readme/FuncDetails.md index db5950b21..8dfc8b8a8 100644 --- a/readme/FuncDetails.md +++ b/readme/FuncDetails.md @@ -61,8 +61,7 @@ classDiagram ### Generated code -
-Pure.DI-generated partial class Func
+The following partial class will be generated: ```c# partial class Func @@ -207,6 +206,3 @@ partial class Func } } ``` - -
- diff --git a/readme/SingletonDetails.md b/readme/SingletonDetails.md index 52a9870df..0497e512d 100644 --- a/readme/SingletonDetails.md +++ b/readme/SingletonDetails.md @@ -63,8 +63,7 @@ classDiagram ### Generated code -
-Pure.DI-generated partial class Singleton
+The following partial class will be generated: ```c# partial class Singleton @@ -212,6 +211,3 @@ partial class Singleton } } ``` - -
- diff --git a/readme/TransientDetails.md b/readme/TransientDetails.md index fc9aae9ab..4d4aeac7f 100644 --- a/readme/TransientDetails.md +++ b/readme/TransientDetails.md @@ -63,8 +63,7 @@ classDiagram ### Generated code -
-Pure.DI-generated partial class Transient
+The following partial class will be generated: ```c# partial class Transient @@ -202,6 +201,3 @@ partial class Transient } } ``` - -
- diff --git a/readme/a-few-partial-classes.md b/readme/a-few-partial-classes.md index a7184f4ee..f0efb56c2 100644 --- a/readme/a-few-partial-classes.md +++ b/readme/a-few-partial-classes.md @@ -4,6 +4,7 @@ The setting code for one Composition can be located in several methods and/or in several partial classes. + ```c# interface IDependency; @@ -41,41 +42,7 @@ var composition = new Composition(); var service = composition.Root; ``` -
-Class Diagram - -```mermaid -classDiagram - class Composition { - <> - +IService Root - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - Dependency --|> IDependency : - class Dependency { - +Dependency() - } - Service --|> IService : - class Service { - +Service(IDependency dependency) - } - class IDependency { - <> - } - class IService { - <> - } - Service *-- Dependency : IDependency - Composition ..> Service : IService Root -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -217,5 +184,33 @@ partial class Composition } ``` -
+Class diagram: + +```mermaid +classDiagram + class Composition { + <> + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + Dependency --|> IDependency : + class Dependency { + +Dependency() + } + Service --|> IService : + class Service { + +Service(IDependency dependency) + } + class IDependency { + <> + } + class IService { + <> + } + Service *-- Dependency : IDependency + Composition ..> Service : IService Root +``` diff --git a/readme/accumulators.md b/readme/accumulators.md index e3cd6e735..b6ebc74e0 100644 --- a/readme/accumulators.md +++ b/readme/accumulators.md @@ -4,6 +4,7 @@ Accumulators allow you to accumulate instances of certain types and lifetimes. + ```c# interface IAccumulating; @@ -40,53 +41,7 @@ accumulator[2].ShouldBeOfType(); ``` -
-Class Diagram - -```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 -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -267,5 +222,45 @@ partial class Composition } ``` -
+Class diagram: + +```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 +``` diff --git a/readme/advanced-interception.md b/readme/advanced-interception.md index 3539a99ab..46b1dedf6 100644 --- a/readme/advanced-interception.md +++ b/readme/advanced-interception.md @@ -4,6 +4,7 @@ This approach of interception maximizes performance by precompiling the proxy object factory. + ```c# public interface IDependency { @@ -109,41 +110,7 @@ log.ShouldBe( "DependencyCall")); ``` -
-Class Diagram - -```mermaid -classDiagram - class Composition { - <> - +IService Root - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - Dependency --|> IDependency : - class Dependency { - +Dependency() - } - Service --|> IService : - class Service { - +Service(IDependency dependency) - } - class IDependency { - <> - } - class IService { - <> - } - Service *-- Dependency : IDependency - Composition ..> Service : IService Root -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -287,5 +254,33 @@ partial class Composition } ``` -
+Class diagram: + +```mermaid +classDiagram + class Composition { + <> + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + Dependency --|> IDependency : + class Dependency { + +Dependency() + } + Service --|> IService : + class Service { + +Service(IDependency dependency) + } + class IDependency { + <> + } + class IService { + <> + } + Service *-- Dependency : IDependency + Composition ..> Service : IService Root +``` diff --git a/readme/arguments.md b/readme/arguments.md index 4da2e02c1..47dfa3162 100644 --- a/readme/arguments.md +++ b/readme/arguments.md @@ -4,6 +4,7 @@ Sometimes you need to pass some state to a composition class to use it when resolving dependencies. To do this, just use the `Arg(string argName)` method, specify the type of argument and its name. You can also specify a tag for each argument. You can then use them as dependencies when building the object graph. If you have multiple arguments of the same type, just use tags to distinguish them. The values of the arguments are manipulated when you create a composition class by calling its constructor. It is important to remember that only those arguments that are used in the object graph will appear in the constructor. Arguments that are not involved will not be added to the constructor arguments. + ```c# interface IDependency { @@ -54,45 +55,7 @@ service.Name.ShouldBe("Abc"); service.Dependency.Id.ShouldBe(123); ``` -
-Class Diagram - -```mermaid -classDiagram - class Composition { - <> - +IService Root - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - class 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 -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -241,5 +204,37 @@ partial class Composition } ``` -
+Class diagram: + +```mermaid +classDiagram + class Composition { + <> + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + class 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 +``` diff --git a/readme/array.md b/readme/array.md index b1a8ba0ec..6a9e4415e 100644 --- a/readme/array.md +++ b/readme/array.md @@ -4,6 +4,7 @@ Specifying `T[]` as the injection type allows instances from all bindings that implement the `T` type to be injected. + ```c# interface IDependency; @@ -62,48 +63,7 @@ In addition to arrays, other collection types are also supported, such as: - System.Collections.Immutable.IImmutableStack And of course this list can easily be supplemented on its own. -
-Class Diagram - -```mermaid -classDiagram - class Composition { - <> - +IService Root - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - 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 -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -245,5 +205,40 @@ partial class Composition } ``` -
+Class diagram: + +```mermaid +classDiagram + class Composition { + <> + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + 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 +``` diff --git a/readme/async-disposable-scope.md b/readme/async-disposable-scope.md index c067ff0cf..6e5fc97a1 100644 --- a/readme/async-disposable-scope.md +++ b/readme/async-disposable-scope.md @@ -2,6 +2,7 @@ [![CSharp](https://img.shields.io/badge/C%23-code-blue.svg)](../tests/Pure.DI.UsageTests/Lifetimes/AsyncDisposableScopeScenario.cs) + ```c# interface IDependency { @@ -79,60 +80,7 @@ await session2.DisposeAsync(); dependency2.IsDisposed.ShouldBeTrue(); ``` -
-Class Diagram - -```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 -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition: IDisposable, IAsyncDisposable @@ -404,5 +352,52 @@ partial class Composition: IDisposable, IAsyncDisposable } ``` -
+Class diagram: + +```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 +``` diff --git a/readme/async-disposable-singleton.md b/readme/async-disposable-singleton.md index ce28ab96b..4b35abef3 100644 --- a/readme/async-disposable-singleton.md +++ b/readme/async-disposable-singleton.md @@ -4,6 +4,7 @@ If at least one of these objects implements the `IAsyncDisposable` interface, then the composition implements `IAsyncDisposable` as well. To dispose of all created singleton instances in an asynchronous manner, simply dispose of the composition instance in an asynchronous manner: + ```c# interface IDependency { @@ -45,47 +46,7 @@ await using (var composition = new Composition()) dependency.IsDisposed.ShouldBeTrue(); ``` -
-Class Diagram - -```mermaid -classDiagram - class Composition { - <> - +IService Root - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - 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 -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition: IDisposable, IAsyncDisposable @@ -316,5 +277,39 @@ partial class Composition: IDisposable, IAsyncDisposable } ``` -
+Class diagram: + +```mermaid +classDiagram + class Composition { + <> + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + 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 +``` diff --git a/readme/async-enumerable.md b/readme/async-enumerable.md index 366926bea..143e8101e 100644 --- a/readme/async-enumerable.md +++ b/readme/async-enumerable.md @@ -4,6 +4,7 @@ Specifying `IAsyncEnumerable` as the injection type allows instances of all bindings implementing type `T` to be injected in an asynchronous-lazy manner - the instances will be provided one at a time, in an order corresponding to the sequence of the bindings. + ```c# interface IDependency; @@ -45,48 +46,7 @@ dependencies[0].ShouldBeOfType(); dependencies[1].ShouldBeOfType(); ``` -
-Class Diagram - -```mermaid -classDiagram - class Composition { - <> - +IService Root - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - 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 -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -236,5 +196,40 @@ partial class Composition } ``` -
+Class diagram: + +```mermaid +classDiagram + class Composition { + <> + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + 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 +``` diff --git a/readme/auto-bindings.md b/readme/auto-bindings.md index 5b0b26d14..74363d641 100644 --- a/readme/auto-bindings.md +++ b/readme/auto-bindings.md @@ -4,6 +4,7 @@ Injection of non-abstract types is possible without any additional effort. + ```c# class Dependency; @@ -25,29 +26,7 @@ var service = composition.MyService; It is better to inject abstract dependencies, for example, in the form of interfaces. Use bindings to map abstract types to their implementations as in almost all [other examples](injections-of-abstractions.md). -
-Class Diagram - -```mermaid -classDiagram - class Composition { - <> - +Service MyService - } - class Dependency { - +Dependency() - } - class Service { - +Service(Dependency dependency) - } - Service *-- Dependency : Dependency - Composition ..> Service : Service MyService -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -75,5 +54,21 @@ partial class Composition } ``` -
+Class diagram: + +```mermaid +classDiagram + class Composition { + <> + +Service MyService + } + class Dependency { + +Dependency() + } + class Service { + +Service(Dependency dependency) + } + Service *-- Dependency : Dependency + Composition ..> Service : Service MyService +``` diff --git a/readme/auto-scoped.md b/readme/auto-scoped.md index ee6bb39b1..07faf7f2a 100644 --- a/readme/auto-scoped.md +++ b/readme/auto-scoped.md @@ -4,6 +4,7 @@ You can use the following example to automatically create a session when creating instances of a particular type: + ```c# interface IDependency; @@ -61,48 +62,7 @@ var service2 = program.CreateService(); service1.Dependency.ShouldNotBe(service2.Dependency); ``` -
-Class Diagram - -```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 -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -306,5 +266,40 @@ partial class Composition } ``` -
+Class diagram: + +```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 +``` diff --git a/readme/check-for-a-root.md b/readme/check-for-a-root.md index e4a42a582..0d9f4cce9 100644 --- a/readme/check-for-a-root.md +++ b/readme/check-for-a-root.md @@ -4,6 +4,7 @@ Sometimes you need to check if you can get the root of a composition using the _Resolve_ method before calling it, this example will show you how to do it: + ```c# interface IDependency; @@ -58,44 +59,7 @@ Composition.HasRoot(typeof(IComparable)).ShouldBeFalse(); ``` -
-Class Diagram - -```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 -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -276,5 +240,36 @@ partial class Composition } ``` -
+Class diagram: + +```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 +``` diff --git a/readme/complex-generics.md b/readme/complex-generics.md index 5b13a95cd..7e53ca62d 100644 --- a/readme/complex-generics.md +++ b/readme/complex-generics.md @@ -4,6 +4,7 @@ Defining generic type arguments using particular marker types like ```TT``` in this sample is a distinguishing and outstanding feature. This allows binding complex generic types with nested generic types and with any type constraints. For instance ```IService where T2: struct where TList: IList where TDictionary: IDictionary { }``` and its binding to the some implementation ```.Bind, TTDictionary>>().To, TTDictionary>>()``` with all checks and code-generation at the compile time. It is clear that this example is exaggerated, it just demonstrates the ease of working with marker types like ```TT, TTEnumerable, TTSet``` and etc. for binding complex generic types. + ```c# interface IDependency; @@ -60,53 +61,7 @@ service.Dependency2.ShouldBeOfType>(); It can also be useful in a very simple scenario where, for example, the sequence of type arguments does not match the sequence of arguments of the contract that implements the type. -
-Class Diagram - -```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ᐳ -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -248,5 +203,45 @@ partial class Composition } ``` -
+Class diagram: + +```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ᐳ +``` diff --git a/readme/composition-root-kinds.md b/readme/composition-root-kinds.md index 418a3b8a4..792105807 100644 --- a/readme/composition-root-kinds.md +++ b/readme/composition-root-kinds.md @@ -2,6 +2,7 @@ [![CSharp](https://img.shields.io/badge/C%23-code-blue.svg)](../tests/Pure.DI.UsageTests/Advanced/CompositionRootKindsScenario.cs) + ```c# interface IDependency; @@ -44,49 +45,7 @@ var otherService = composition.GetOtherService(); var dependency = Composition.Dependency; ``` -
-Class Diagram - -```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 -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -266,5 +225,41 @@ partial class Composition } ``` -
+Class diagram: + +```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 +``` diff --git a/readme/composition-roots.md b/readme/composition-roots.md index 5fa3fe182..0949dceea 100644 --- a/readme/composition-roots.md +++ b/readme/composition-roots.md @@ -4,6 +4,7 @@ This example demonstrates several ways to create a composition root. There is no limit to the number of roots, but you should consider limiting the number of roots. Ideally, an application should have a single composition root. + ```c# interface IDependency; @@ -65,49 +66,7 @@ DI.Setup("Composition") ``` This can be done if these methods are not needed, in case only certain composition roots are used. It's not significant then, but it will help save resources during compilation. -
-Class Diagram - -```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 ..> Service : IService MyRoot - Composition ..> Dependency : IDependency _ - Composition ..> OtherService : IService SomeOtherService -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -293,5 +252,41 @@ partial class Composition } ``` -
+Class diagram: + +```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 ..> Service : IService MyRoot + Composition ..> Dependency : IDependency _ + Composition ..> OtherService : IService SomeOtherService +``` diff --git a/readme/constructor-ordinal-attribute.md b/readme/constructor-ordinal-attribute.md index 94c6d2050..6ab365737 100644 --- a/readme/constructor-ordinal-attribute.md +++ b/readme/constructor-ordinal-attribute.md @@ -4,6 +4,7 @@ When applied to any constructor in a type, automatic injection constructor selection is disabled. The selection will only focus on constructors marked with this attribute, in the appropriate order from smallest value to largest. + ```c# interface IDependency; @@ -44,35 +45,7 @@ service.ToString().ShouldBe("Xyz"); The attribute `Ordinal` is part of the API, but you can use your own attribute at any time, and this allows you to define them in the assembly and namespace you want. -
-Class Diagram - -```mermaid -classDiagram - class Composition { - <> - +IService Root - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - class String - Service --|> IService : - class Service { - ~Service(String name) - } - class IService { - <> - } - Service o-- String : Argument "serviceName" - Composition ..> Service : IService Root -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -218,5 +191,27 @@ partial class Composition } ``` -
+Class diagram: + +```mermaid +classDiagram + class Composition { + <> + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + class String + Service --|> IService : + class Service { + ~Service(String name) + } + class IService { + <> + } + Service o-- String : Argument "serviceName" + Composition ..> Service : IService Root +``` diff --git a/readme/custom-attributes.md b/readme/custom-attributes.md index 010a810f2..17cc45134 100644 --- a/readme/custom-attributes.md +++ b/readme/custom-attributes.md @@ -8,6 +8,7 @@ It's very easy to use your attributes. To do this, you need to create a descenda - `TagAttribute` You can also use combined attributes, and each method in the list above has an optional parameter that defines the argument number (the default is 0) from where to get the appropriate metadata for _tag_, _ordinal_, or _type_. + ```c# [AttributeUsage( AttributeTargets.Constructor @@ -55,38 +56,7 @@ var person = composition.Person; person.ToString().ShouldBe("123 Nik"); ``` -
-Class Diagram - -```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 -``` - -
- -
-Pure.DI-generated partial class PersonComposition
+The following partial class will be generated: ```c# partial class PersonComposition @@ -235,5 +205,30 @@ partial class PersonComposition } ``` -
+Class diagram: + +```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 +``` diff --git a/readme/decorator.md b/readme/decorator.md index dc2125acd..5a7f5eaae 100644 --- a/readme/decorator.md +++ b/readme/decorator.md @@ -4,6 +4,7 @@ _Decorator_ is a well-known and useful design pattern. It is convenient to use tagged dependencies to build a chain of nested decorators, as in the example below: + ```c# interface IService { string GetMessage(); } @@ -29,38 +30,7 @@ service.GetMessage().ShouldBe("Hello World !!!"); Here an instance of the _Service_ type, labeled _"base"_, is embedded in the decorator _DecoratorService_. You can use any tag that semantically reflects the feature of the abstraction being embedded. The tag can be a constant, a type, or a value of an enumerated type. -
-Class Diagram - -```mermaid -classDiagram - class Composition { - <> - +IService Root - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - Service --|> IService : "base" - class Service { - +Service() - } - GreetingService --|> IService : - class GreetingService { - +GreetingService(IService baseService) - } - class IService { - <> - } - GreetingService *-- Service : "base" IService - Composition ..> GreetingService : IService Root -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -202,5 +172,30 @@ partial class Composition } ``` -
+Class diagram: + +```mermaid +classDiagram + class Composition { + <> + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + Service --|> IService : "base" + class Service { + +Service() + } + GreetingService --|> IService : + class GreetingService { + +GreetingService(IService baseService) + } + class IService { + <> + } + GreetingService *-- Service : "base" IService + Composition ..> GreetingService : IService Root +``` diff --git a/readme/default-lifetime.md b/readme/default-lifetime.md index e4f684312..313c9b4ca 100644 --- a/readme/default-lifetime.md +++ b/readme/default-lifetime.md @@ -4,6 +4,7 @@ For example, if some lifetime is used more often than others, you can make it the default lifetime: + ```c# interface IDependency; @@ -42,41 +43,7 @@ service1.ShouldBe(service2); service1.Dependency1.ShouldBe(service1.Dependency2); ``` -
-Class Diagram - -```mermaid -classDiagram - class Composition { - <> - +IService Root - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - Dependency --|> IDependency : - class Dependency { - +Dependency() - } - Service --|> IService : - class Service { - +Service(IDependency dependency1, IDependency dependency2) - } - class IDependency { - <> - } - class IService { - <> - } - Service o-- "2 Singleton" Dependency : IDependency - Composition ..> Service : IService Root -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -237,5 +204,33 @@ partial class Composition } ``` -
+Class diagram: + +```mermaid +classDiagram + class Composition { + <> + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + Dependency --|> IDependency : + class Dependency { + +Dependency() + } + Service --|> IService : + class Service { + +Service(IDependency dependency1, IDependency dependency2) + } + class IDependency { + <> + } + class IService { + <> + } + Service o-- "2 Singleton" Dependency : IDependency + Composition ..> Service : IService Root +``` diff --git a/readme/default-values.md b/readme/default-values.md index 09679f83c..3f714d0bf 100644 --- a/readme/default-values.md +++ b/readme/default-values.md @@ -2,6 +2,7 @@ [![CSharp](https://img.shields.io/badge/C%23-code-blue.svg)](../tests/Pure.DI.UsageTests/Basics/DefaultValuesScenario.cs) + ```c# interface IDependency; @@ -36,42 +37,7 @@ service.Dependency.ShouldBeOfType(); service.Name.ShouldBe("My Service"); ``` -
-Class Diagram - -```mermaid -classDiagram - class Composition { - <> - +IService Root - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - Dependency --|> IDependency : - class Dependency { - +Dependency() - } - Service --|> IService : - class Service { - +Service(String name) - +IDependency Dependency - } - class IDependency { - <> - } - class IService { - <> - } - Service *-- Dependency : IDependency - Composition ..> Service : IService Root -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -216,5 +182,34 @@ partial class Composition } ``` -
+Class diagram: + +```mermaid +classDiagram + class Composition { + <> + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + Dependency --|> IDependency : + class Dependency { + +Dependency() + } + Service --|> IService : + class Service { + +Service(String name) + +IDependency Dependency + } + class IDependency { + <> + } + class IService { + <> + } + Service *-- Dependency : IDependency + Composition ..> Service : IService Root +``` diff --git a/readme/dependent-compositions.md b/readme/dependent-compositions.md index de6731bc1..b52a989b0 100644 --- a/readme/dependent-compositions.md +++ b/readme/dependent-compositions.md @@ -7,6 +7,7 @@ The _Setup_ method has an additional argument _kind_, which defines the type of - _CompositionKind.Internal_ - the composition class will not be created, but that composition can be used to create other compositions by calling the _DependsOn_ method with its name - _CompositionKind.Global_ - the composition class will also not be created, but that composition will automatically be used to create other compositions + ```c# interface IDependency; @@ -46,47 +47,7 @@ var otherComposition = new OtherComposition(); service = otherComposition.Program.Service; ``` -
-Class Diagram - -```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 -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -227,11 +188,7 @@ partial class Composition } } ``` - -
- -
-Pure.DI-generated partial class OtherComposition
+The following partial class will be generated: ```c# partial class OtherComposition @@ -405,5 +362,39 @@ partial class OtherComposition } ``` -
+Class diagram: + +```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 +``` diff --git a/readme/disposable-singleton.md b/readme/disposable-singleton.md index 71f3a5f80..4a2ab30b3 100644 --- a/readme/disposable-singleton.md +++ b/readme/disposable-singleton.md @@ -4,6 +4,7 @@ To dispose all created singleton instances, simply dispose the composition instance: + ```c# interface IDependency { @@ -43,42 +44,7 @@ dependency.IsDisposed.ShouldBeTrue(); A composition class becomes disposable if it creates at least one disposable singleton instance. -
-Class Diagram - -```mermaid -classDiagram - class Composition { - <> - +IService Root - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - 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 -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition: IDisposable @@ -272,5 +238,34 @@ partial class Composition: IDisposable } ``` -
+Class diagram: + +```mermaid +classDiagram + class Composition { + <> + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + 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 +``` diff --git a/readme/enumerable-generics.md b/readme/enumerable-generics.md index 0a69ecd79..93238f996 100644 --- a/readme/enumerable-generics.md +++ b/readme/enumerable-generics.md @@ -2,6 +2,7 @@ [![CSharp](https://img.shields.io/badge/C%23-code-blue.svg)](../tests/Pure.DI.UsageTests/BaseClassLibrary/EnumerableGenericsScenario.cs) + ```c# interface IDependency; @@ -42,72 +43,7 @@ stringService.Dependencies[0].ShouldBeOfType>(); stringService.Dependencies[1].ShouldBeOfType>(); ``` -
-Class Diagram - -```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ᐳ -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -295,5 +231,64 @@ partial class Composition } ``` -
+Class diagram: + +```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ᐳ +``` diff --git a/readme/enumerable.md b/readme/enumerable.md index 776c1c0c0..d2edc3a95 100644 --- a/readme/enumerable.md +++ b/readme/enumerable.md @@ -4,6 +4,7 @@ Specifying `IEnumerable` as the injection type allows you to inject instances of all bindings that implement type `T` in a lazy fashion - the instances will be provided one by one, in order corresponding to the sequence of bindings. + ```c# interface IDependency; @@ -37,48 +38,7 @@ service.Dependencies[0].ShouldBeOfType(); service.Dependencies[1].ShouldBeOfType(); ``` -
-Class Diagram - -```mermaid -classDiagram - class Composition { - <> - +IService Root - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - 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 -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -227,5 +187,40 @@ partial class Composition } ``` -
+Class diagram: + +```mermaid +classDiagram + class Composition { + <> + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + 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 +``` diff --git a/readme/factory.md b/readme/factory.md index a21e1f1fb..a2dc1f9d3 100644 --- a/readme/factory.md +++ b/readme/factory.md @@ -4,6 +4,7 @@ This example demonstrates how to create and initialize an instance manually. This approach is more expensive to maintain, but allows you to create objects more flexibly by passing them some state and introducing dependencies. As in the case of automatic dependency embedding, objects give up control on embedding, and the whole process takes place when the object graph is created. + ```c# interface IDependency { @@ -56,39 +57,7 @@ var service = composition.Root; service.Dependency.IsInitialized.ShouldBeTrue(); ``` -
-Class Diagram - -```mermaid -classDiagram - class Composition { - <> - +IService Root - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - class 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 -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -237,5 +206,31 @@ partial class Composition } ``` -
+Class diagram: + +```mermaid +classDiagram + class Composition { + <> + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + class 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 +``` diff --git a/readme/field-injection.md b/readme/field-injection.md index 3d7750a95..618f10445 100644 --- a/readme/field-injection.md +++ b/readme/field-injection.md @@ -4,6 +4,7 @@ To use dependency injection for a field, make sure the field is writable and simply add the _Ordinal_ attribute to that field, specifying an ordinal that will be used to determine the injection order: + ```c# interface IDependency; @@ -37,42 +38,7 @@ var service = composition.Root; service.Dependency.ShouldBeOfType(); ``` -
-Class Diagram - -```mermaid -classDiagram - class Composition { - <> - +IService Root - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - Dependency --|> IDependency : - class Dependency { - +Dependency() - } - Service --|> IService : - class Service { - +Service() - ~IDependency DependencyVal - } - class IDependency { - <> - } - class IService { - <> - } - Service *-- Dependency : IDependency - Composition ..> Service : IService Root -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -216,5 +182,34 @@ partial class Composition } ``` -
+Class diagram: + +```mermaid +classDiagram + class Composition { + <> + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + Dependency --|> IDependency : + class Dependency { + +Dependency() + } + Service --|> IService : + class Service { + +Service() + ~IDependency DependencyVal + } + class IDependency { + <> + } + class IService { + <> + } + Service *-- Dependency : IDependency + Composition ..> Service : IService Root +``` diff --git a/readme/func-with-arguments.md b/readme/func-with-arguments.md index b265dca0f..466d4c849 100644 --- a/readme/func-with-arguments.md +++ b/readme/func-with-arguments.md @@ -2,6 +2,7 @@ [![CSharp](https://img.shields.io/badge/C%23-code-blue.svg)](../tests/Pure.DI.UsageTests/BaseClassLibrary/FuncWithArgumentsScenario.cs) + ```c# interface IClock { @@ -65,49 +66,7 @@ service.Dependencies.Length.ShouldBe(10); service.Dependencies[3].Id.ShouldBe(3); ``` -
-Class Diagram - -```mermaid -classDiagram - class Composition { - <> - +IService Root - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - class 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 -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -269,5 +228,41 @@ partial class Composition } ``` -
+Class diagram: + +```mermaid +classDiagram + class Composition { + <> + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + class 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 +``` diff --git a/readme/func-with-tag.md b/readme/func-with-tag.md index 2e704265e..045eb0d18 100644 --- a/readme/func-with-tag.md +++ b/readme/func-with-tag.md @@ -2,6 +2,7 @@ [![CSharp](https://img.shields.io/badge/C%23-code-blue.svg)](../tests/Pure.DI.UsageTests/BaseClassLibrary/FuncWithTagScenario.cs) + ```c# interface IDependency; @@ -35,43 +36,7 @@ var service = composition.Root; service.Dependencies.Length.ShouldBe(10); ``` -
-Class Diagram - -```mermaid -classDiagram - class Composition { - <> - +IService Root - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - Dependency --|> IDependency : "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 -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -224,5 +189,35 @@ partial class Composition } ``` -
+Class diagram: + +```mermaid +classDiagram + class Composition { + <> + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + Dependency --|> IDependency : "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 +``` diff --git a/readme/func.md b/readme/func.md index 0614cfd93..e8f523bad 100644 --- a/readme/func.md +++ b/readme/func.md @@ -4,6 +4,7 @@ _Func_ helps when the logic must enter instances of some type on demand or more than once. This is a very handy mechanism for instance replication. For example it is used when implementing the `Lazy` injection. + ```c# interface IDependency; @@ -38,43 +39,7 @@ service.Dependencies.Length.ShouldBe(10); Be careful, replication takes into account the lifetime of the object. -
-Class Diagram - -```mermaid -classDiagram - class Composition { - <> - +IService Root - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - Dependency --|> IDependency : - 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 -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -227,5 +192,35 @@ partial class Composition } ``` -
+Class diagram: + +```mermaid +classDiagram + class Composition { + <> + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + Dependency --|> IDependency : + 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 +``` diff --git a/readme/generic-composition-roots-with-constraints.md b/readme/generic-composition-roots-with-constraints.md index 6eaaac863..58b272cc2 100644 --- a/readme/generic-composition-roots-with-constraints.md +++ b/readme/generic-composition-roots-with-constraints.md @@ -2,6 +2,7 @@ [![CSharp](https://img.shields.io/badge/C%23-code-blue.svg)](../tests/Pure.DI.UsageTests/Generics/GenericCompositionRootsWithConstraintsScenario.cs) + ```c# interface IDependency where T: IDisposable; @@ -53,45 +54,7 @@ var service = composition.GetMyRoot(); var someOtherService = composition.GetOtherService(); ``` -
-Class Diagram - -```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ᐳ -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -130,5 +93,37 @@ partial class Composition } ``` -
+Class diagram: + +```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ᐳ +``` diff --git a/readme/generic-composition-roots.md b/readme/generic-composition-roots.md index f35b766ee..6f117c394 100644 --- a/readme/generic-composition-roots.md +++ b/readme/generic-composition-roots.md @@ -4,6 +4,7 @@ A generic composition root is represented by a method. + ```c# interface IDependency; @@ -50,42 +51,7 @@ var someOtherService = composition.GetOtherService(); When a generic composition root is used, `Resolve` methods cannot be used to resolve them. -
-Class Diagram - -```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ᐳ -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -121,5 +87,34 @@ partial class Composition } ``` -
+Class diagram: + +```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ᐳ +``` diff --git a/readme/generics.md b/readme/generics.md index 8842aacd5..a53e11bcf 100644 --- a/readme/generics.md +++ b/readme/generics.md @@ -4,6 +4,7 @@ Generic types are also supported, this is easy to do by binding generic types and specifying generic markers like `TT`, `TT1` etc. as generic type parameters: + ```c# interface IDependency; @@ -50,49 +51,7 @@ public IService Root } ``` -
-Class Diagram - -```mermaid -classDiagram - class Composition { - <> - +IService Root - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - 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 -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -234,5 +193,41 @@ partial class Composition } ``` -
+Class diagram: + +```mermaid +classDiagram + class Composition { + <> + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + Service --|> IService : + class Service { + +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 +``` diff --git a/readme/global-compositions.md b/readme/global-compositions.md index 5bd98fab2..00215f666 100644 --- a/readme/global-compositions.md +++ b/readme/global-compositions.md @@ -4,6 +4,7 @@ When the `Setup(name, kind)` method is called, the second optional parameter specifies the composition kind. If you set it as `CompositionKind.Global`, no composition class will be created, but this setup will be the base setup for all others in the current project, and `DependsOn(...)` is not required. The setups will be applied in the sort order of their names. + ```c# class MyGlobalComposition { @@ -20,3 +21,6 @@ class MyGlobalComposition2 .Hint(Hint.FormatCode, "On"); } ``` + + + diff --git a/readme/injections-of-abstractions.md b/readme/injections-of-abstractions.md index f707efe9b..392f78402 100644 --- a/readme/injections-of-abstractions.md +++ b/readme/injections-of-abstractions.md @@ -4,6 +4,7 @@ This example demonstrates the recommended approach of using abstractions instead of implementations when injecting dependencies. + ```c# interface IDependency; @@ -41,8 +42,35 @@ var root = composition.Root; root.Run(); ``` -
-Class Diagram +The following partial class will be generated: + +```c# +partial class Composition +{ + private readonly Composition _root; + + public Composition() + { + _root = this; + } + + internal Composition(Composition parentScope) + { + _root = (parentScope ?? throw new ArgumentNullException(nameof(parentScope)))._root; + } + + public Program Root + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get + { + return new Program(new Service(new Dependency())); + } + } +} +``` + +Class diagram: ```mermaid classDiagram @@ -72,36 +100,3 @@ classDiagram Composition ..> Program : Program Root ``` -
- -
-Pure.DI-generated partial class Composition
- -```c# -partial class Composition -{ - private readonly Composition _root; - - public Composition() - { - _root = this; - } - - internal Composition(Composition parentScope) - { - _root = (parentScope ?? throw new ArgumentNullException(nameof(parentScope)))._root; - } - - public Program Root - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - return new Program(new Service(new Dependency())); - } - } -} -``` - -
- diff --git a/readme/interception.md b/readme/interception.md index f865f4aac..67ee197d8 100644 --- a/readme/interception.md +++ b/readme/interception.md @@ -4,6 +4,7 @@ Interception allows you to enrich or change the behavior of a certain set of objects from the object graph being created without changing the code of the corresponding types. + ```c# public interface IService { string GetMessage(); } @@ -53,33 +54,7 @@ var service = composition.Root; service.GetMessage().ShouldBe("Hello World !!!"); ``` -
-Class Diagram - -```mermaid -classDiagram - class Composition { - <> - +IService Root - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - Service --|> IService : - class Service { - +Service() - } - class IService { - <> - } - Composition ..> Service : IService Root -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -223,5 +198,25 @@ partial class Composition } ``` -
+Class diagram: + +```mermaid +classDiagram + class Composition { + <> + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + Service --|> IService : + class Service { + +Service() + } + class IService { + <> + } + Composition ..> Service : IService Root +``` diff --git a/readme/keyed-service-provider.md b/readme/keyed-service-provider.md index 5acd17b05..4d7dd63f0 100644 --- a/readme/keyed-service-provider.md +++ b/readme/keyed-service-provider.md @@ -2,6 +2,7 @@ [![CSharp](https://img.shields.io/badge/C%23-code-blue.svg)](../tests/Pure.DI.UsageTests/BaseClassLibrary/KeyedServiceProviderScenario.cs) + ```c# interface IDependency; @@ -44,43 +45,7 @@ var dependency = serviceProvider.GetRequiredKeyedService("Dependenc service.Dependency.ShouldBe(dependency); ``` -
-Class Diagram - -```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 _ -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -278,5 +243,35 @@ partial class Composition } ``` -
+Class diagram: + +```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 _ +``` diff --git a/readme/lazy.md b/readme/lazy.md index 00256b063..a0a88f7b7 100644 --- a/readme/lazy.md +++ b/readme/lazy.md @@ -2,6 +2,7 @@ [![CSharp](https://img.shields.io/badge/C%23-code-blue.svg)](../tests/Pure.DI.UsageTests/BaseClassLibrary/LazyScenario.cs) + ```c# interface IDependency; @@ -29,45 +30,7 @@ var service = composition.Root; service.Dependency.ShouldBe(service.Dependency); ``` -
-Class Diagram - -```mermaid -classDiagram - class Composition { - <> - +IService Root - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - Dependency --|> IDependency : - 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 -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -225,5 +188,37 @@ partial class Composition } ``` -
+Class diagram: + +```mermaid +classDiagram + class Composition { + <> + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + Dependency --|> IDependency : + 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 +``` diff --git a/readme/manually-started-tasks.md b/readme/manually-started-tasks.md index 7152930cd..acbd8a321 100644 --- a/readme/manually-started-tasks.md +++ b/readme/manually-started-tasks.md @@ -4,6 +4,7 @@ By default, tasks are started automatically when they are injected. But you can override this behavior as shown in the example below. It is also recommended to add a binding for CancellationToken to be able to cancel the execution of a task. + ```c# interface IDependency { @@ -66,48 +67,7 @@ var service = composition.GetRoot(cancellationTokenSource.Token); await service.RunAsync(cancellationTokenSource.Token); ``` -
-Class Diagram - -```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 -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -149,5 +109,40 @@ partial class Composition } ``` -
+Class diagram: + +```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 +``` diff --git a/readme/member-ordinal-attribute.md b/readme/member-ordinal-attribute.md index b1af7412b..b65a5327b 100644 --- a/readme/member-ordinal-attribute.md +++ b/readme/member-ordinal-attribute.md @@ -4,6 +4,7 @@ When applied to a property or field, these type members will also participate in dependency injection in the appropriate order from smallest value to largest. + ```c# interface IPerson { @@ -64,42 +65,7 @@ person.Name.ShouldBe("123 Nik 1977-11-16"); The attribute `Ordinal` is part of the API, but you can use your own attribute at any time, and this allows you to define them in the assembly and namespace you want. -
-Class Diagram - -```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 -``` - -
- -
-Pure.DI-generated partial class PersonComposition
+The following partial class will be generated: ```c# partial class PersonComposition @@ -255,5 +221,34 @@ partial class PersonComposition } ``` -
+Class diagram: + +```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 +``` diff --git a/readme/method-injection.md b/readme/method-injection.md index c341865f6..393471702 100644 --- a/readme/method-injection.md +++ b/readme/method-injection.md @@ -4,6 +4,7 @@ To use dependency implementation for a method, simply add the _Ordinal_ attribute to that method, specifying the sequence number that will be used to define the call to that method: + ```c# interface IDependency; @@ -38,42 +39,7 @@ var service = composition.Root; service.Dependency.ShouldBeOfType(); ``` -
-Class Diagram - -```mermaid -classDiagram - class Composition { - <> - +IService Root - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - Dependency --|> IDependency : - class Dependency { - +Dependency() - } - Service --|> IService : - class Service { - +Service() - +SetDependency(IDependency dependency) : Void - } - class IDependency { - <> - } - class IService { - <> - } - Service *-- Dependency : IDependency - Composition ..> Service : IService Root -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -217,5 +183,34 @@ partial class Composition } ``` -
+Class diagram: + +```mermaid +classDiagram + class Composition { + <> + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + Dependency --|> IDependency : + class Dependency { + +Dependency() + } + Service --|> IService : + class Service { + +Service() + +SetDependency(IDependency dependency) : Void + } + class IDependency { + <> + } + class IService { + <> + } + Service *-- Dependency : IDependency + Composition ..> Service : IService Root +``` diff --git a/readme/oncannotresolve-hint.md b/readme/oncannotresolve-hint.md index dab8ba3e2..0856a1724 100644 --- a/readme/oncannotresolve-hint.md +++ b/readme/oncannotresolve-hint.md @@ -5,6 +5,7 @@ Hints are used to fine-tune code generation. The _OnCannotResolve_ hint determines whether to generate a partial `OnCannotResolve(...)` method to handle a scenario where an instance which cannot be resolved. In addition, setup hints can be comments before the _Setup_ method in the form ```hint = value```, for example: `// OnCannotResolveContractTypeNameRegularExpression = string`. + ```c# using static Hint; @@ -56,43 +57,7 @@ service.Dependency.ToString().ShouldBe("Dependency with name"); The `OnCannotResolveContractTypeNameRegularExpression` hint helps define the set of types that require manual dependency resolution. You can use it to specify a regular expression to filter the full type name. For more hints, see [this](https://github.com/DevTeam/Pure.DI/blob/master/README.md#setup-hints) page. -
-Class Diagram - -```mermaid -classDiagram - class Composition { - <> - +IService Root - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - class 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 -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -237,5 +202,35 @@ partial class Composition } ``` -
+Class diagram: + +```mermaid +classDiagram + class Composition { + <> + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + class 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 +``` diff --git a/readme/ondependencyinjection-hint.md b/readme/ondependencyinjection-hint.md index ebca04569..3602b0226 100644 --- a/readme/ondependencyinjection-hint.md +++ b/readme/ondependencyinjection-hint.md @@ -5,6 +5,7 @@ Hints are used to fine-tune code generation. The _OnDependencyInjection_ hint determines whether to generate partial _OnDependencyInjection_ method to control of dependency injection. In addition, setup hints can be comments before the _Setup_ method in the form ```hint = value```, for example: `// OnDependencyInjection = On`. + ```c# using static Hint; @@ -55,41 +56,7 @@ log.ShouldBe(ImmutableArray.Create("Dependency injected")); The `OnDependencyInjectionContractTypeNameRegularExpression` hint helps identify the set of types that require injection control. You can use it to specify a regular expression to filter the full name of a type. For more hints, see [this](https://github.com/DevTeam/Pure.DI/blob/master/README.md#setup-hints) page. -
-Class Diagram - -```mermaid -classDiagram - class Composition { - <> - +IService Root - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - Dependency --|> IDependency : - class Dependency { - +Dependency() - } - Service --|> IService : - class Service { - +Service(IDependency dependency) - } - class IDependency { - <> - } - class IService { - <> - } - Service *-- Dependency : IDependency - Composition ..> Service : IService Root -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -233,5 +200,33 @@ partial class Composition } ``` -
+Class diagram: + +```mermaid +classDiagram + class Composition { + <> + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + Dependency --|> IDependency : + class Dependency { + +Dependency() + } + Service --|> IService : + class Service { + +Service(IDependency dependency) + } + class IDependency { + <> + } + class IService { + <> + } + Service *-- Dependency : IDependency + Composition ..> Service : IService Root +``` diff --git a/readme/onnewinstance-hint.md b/readme/onnewinstance-hint.md index 50404b11d..d3c54fefb 100644 --- a/readme/onnewinstance-hint.md +++ b/readme/onnewinstance-hint.md @@ -5,6 +5,7 @@ Hints are used to fine-tune code generation. The _OnNewInstance_ hint determines whether to generate partial _OnNewInstance_ method. In addition, setup hints can be comments before the _Setup_ method in the form ```hint = value```, for example: `// OnNewInstance = On`. + ```c# using static Hint; @@ -57,41 +58,7 @@ log.ShouldBe(ImmutableArray.Create("Dependency", "Service", "Service")); The `OnNewInstanceLifetimeRegularExpression` hint helps you define a set of lifetimes that require instance creation control. You can use it to specify a regular expression to filter bindings by lifetime name. For more hints, see [this](https://github.com/DevTeam/Pure.DI/blob/master/README.md#setup-hints) page. -
-Class Diagram - -```mermaid -classDiagram - class Composition { - <> - +IService Root - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - Dependency --|> IDependency : - class Dependency { - +Dependency() - } - Service --|> IService : - class Service { - +Service(IDependency dependency) - } - class IDependency { - <> - } - class IService { - <> - } - Service o-- "Singleton" Dependency : IDependency - Composition ..> Service : IService Root -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -255,5 +222,33 @@ partial class Composition } ``` -
+Class diagram: + +```mermaid +classDiagram + class Composition { + <> + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + Dependency --|> IDependency : + class Dependency { + +Dependency() + } + Service --|> IService : + class Service { + +Service(IDependency dependency) + } + class IDependency { + <> + } + class IService { + <> + } + Service o-- "Singleton" Dependency : IDependency + Composition ..> Service : IService Root +``` diff --git a/readme/overriding-the-bcl-binding.md b/readme/overriding-the-bcl-binding.md index e551ca0d1..3a94ce645 100644 --- a/readme/overriding-the-bcl-binding.md +++ b/readme/overriding-the-bcl-binding.md @@ -4,6 +4,7 @@ At any time, the default binding to the BCL type can be changed to your own: + ```c# interface IDependency; @@ -41,35 +42,7 @@ service.Dependencies[1].ShouldBeOfType(); service.Dependencies[2].ShouldBeOfType(); ``` -
-Class Diagram - -```mermaid -classDiagram - class Composition { - <> - +IService Root - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - class ArrayᐸIDependencyᐳ - Service --|> IService : - class Service { - +Service(ArrayᐸIDependencyᐳ dependencies) - } - class IService { - <> - } - Service *-- ArrayᐸIDependencyᐳ : ArrayᐸIDependencyᐳ - Composition ..> Service : IService Root -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -217,5 +190,27 @@ partial class Composition } ``` -
+Class diagram: + +```mermaid +classDiagram + class Composition { + <> + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + class ArrayᐸIDependencyᐳ + Service --|> IService : + class Service { + +Service(ArrayᐸIDependencyᐳ dependencies) + } + class IService { + <> + } + Service *-- ArrayᐸIDependencyᐳ : ArrayᐸIDependencyᐳ + Composition ..> Service : IService Root +``` diff --git a/readme/partial-class.md b/readme/partial-class.md index 292469033..07a3653b6 100644 --- a/readme/partial-class.md +++ b/readme/partial-class.md @@ -4,6 +4,7 @@ A partial class can contain setup code. + ```c# interface IDependency { @@ -65,41 +66,7 @@ service.Name.ShouldBe("Abc_3"); The partial class is also useful for specifying access modifiers to the generated class. -
-Class Diagram - -```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 *-- "2 " Dependency : IDependency - Dependency *-- Int64 : Int64 - Composition ..> Service : Service Root -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -244,5 +211,33 @@ partial class Composition } ``` -
+Class diagram: + +```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 *-- "2 " Dependency : IDependency + Dependency *-- Int64 : Int64 + Composition ..> Service : Service Root +``` diff --git a/readme/perblock.md b/readme/perblock.md index 6db98eb6c..b8b6c8215 100644 --- a/readme/perblock.md +++ b/readme/perblock.md @@ -4,6 +4,7 @@ The _PreBlock_ lifetime does not guarantee that there will be a single instance of the dependency for each root of the composition, but is useful to reduce the number of instances of type. + ```c# interface IDependency; @@ -40,46 +41,7 @@ var service2 = composition.Root; service2.Dep1.ShouldNotBe(service1.Dep1); ``` -
-Class Diagram - -```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-- "2 PerBlock" Dependency : IDependency - Service o-- "2 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ᐳ -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -239,5 +201,38 @@ partial class Composition } ``` -
+Class diagram: + +```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-- "2 PerBlock" Dependency : IDependency + Service o-- "2 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ᐳ +``` diff --git a/readme/perresolve.md b/readme/perresolve.md index f1592713e..abc5986ef 100644 --- a/readme/perresolve.md +++ b/readme/perresolve.md @@ -4,6 +4,7 @@ The _PerResolve_ lifetime guarantees that there will be a single instance of the dependency for each root of the composition. + ```c# interface IDependency; @@ -40,46 +41,7 @@ var service2 = composition.Root; service2.Dep1.ShouldNotBe(service1.Dep1); ``` -
-Class Diagram - -```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-- "2 PerResolve" Dependency : IDependency - Service o-- "2 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ᐳ -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -258,5 +220,38 @@ partial class Composition } ``` -
+Class diagram: + +```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-- "2 PerResolve" Dependency : IDependency + Service o-- "2 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ᐳ +``` diff --git a/readme/property-injection.md b/readme/property-injection.md index 119a6c052..d2fdae950 100644 --- a/readme/property-injection.md +++ b/readme/property-injection.md @@ -4,6 +4,7 @@ To use dependency injection on a property, make sure the property is writable and simply add the _Ordinal_ attribute to that property, specifying the ordinal that will be used to determine the injection order: + ```c# interface IDependency; @@ -35,42 +36,7 @@ var service = composition.Root; service.Dependency.ShouldBeOfType(); ``` -
-Class Diagram - -```mermaid -classDiagram - class Composition { - <> - +IService Root - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - Dependency --|> IDependency : - class Dependency { - +Dependency() - } - Service --|> IService : - class Service { - +Service() - +IDependency Dependency - } - class IDependency { - <> - } - class IService { - <> - } - Service *-- Dependency : IDependency - Composition ..> Service : IService Root -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -214,5 +180,34 @@ partial class Composition } ``` -
+Class diagram: + +```mermaid +classDiagram + class Composition { + <> + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + Dependency --|> IDependency : + class Dependency { + +Dependency() + } + Service --|> IService : + class Service { + +Service() + +IDependency Dependency + } + class IDependency { + <> + } + class IService { + <> + } + Service *-- Dependency : IDependency + Composition ..> Service : IService Root +``` diff --git a/readme/required-properties-or-fields.md b/readme/required-properties-or-fields.md index ad3f1c7ef..a19a84947 100644 --- a/readme/required-properties-or-fields.md +++ b/readme/required-properties-or-fields.md @@ -4,6 +4,7 @@ All properties or fields marked with the _required_ keyword automatically become injected dependencies. + ```c# interface IDependency; @@ -41,45 +42,7 @@ service.Dependency.ShouldBeOfType(); service.Name.ShouldBe("My Service"); ``` -
-Class Diagram - -```mermaid -classDiagram - class Composition { - <> - +IService Root - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - class 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 -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -229,5 +192,37 @@ partial class Composition } ``` -
+Class diagram: + +```mermaid +classDiagram + class Composition { + <> + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + class 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 +``` diff --git a/readme/resolve-hint.md b/readme/resolve-hint.md index c615d793d..4f1576f8a 100644 --- a/readme/resolve-hint.md +++ b/readme/resolve-hint.md @@ -5,6 +5,7 @@ Hints are used to fine-tune code generation. The _Resolve_ hint determines whether to generate _Resolve_ methods. By default a set of four _Resolve_ methods are generated. Set this hint to _Off_ to disable the generation of resolve methods. This will reduce class composition generation time and no private composition roots will be generated in this case. When the _Resolve_ hint is disabled, only the public root properties are available, so be sure to define them explicitly with the `Root(...)` method. In addition, setup hints can be comments before the _Setup_ method in the form ```hint = value```, for example: `// Resolve = Off`. + ```c# using static Hint; @@ -28,39 +29,7 @@ var dependencyRoot = composition.DependencyRoot; For more hints, see [this](https://github.com/DevTeam/Pure.DI/blob/master/README.md#setup-hints) page. -
-Class Diagram - -```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 -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -97,5 +66,31 @@ partial class Composition } ``` -
+Class diagram: + +```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 +``` diff --git a/readme/resolve-methods.md b/readme/resolve-methods.md index eec8189d9..115c22217 100644 --- a/readme/resolve-methods.md +++ b/readme/resolve-methods.md @@ -4,6 +4,7 @@ This example shows how to resolve the composition roots using the _Resolve_ methods by _Service Locator_ approach. `Resolve` methods are generated automatically for each registered root. + ```c# interface IDependency; @@ -42,49 +43,7 @@ var otherService1 = composition.Resolve("Other"); var otherService2 = composition.Resolve(typeof(IService),"Other"); ``` -
-Class Diagram - -```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 -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -270,5 +229,41 @@ partial class Composition } ``` -
+Class diagram: + +```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 +``` diff --git a/readme/root-arguments.md b/readme/root-arguments.md index 1d6d2eaf0..8e111bae8 100644 --- a/readme/root-arguments.md +++ b/readme/root-arguments.md @@ -4,6 +4,7 @@ Sometimes it is necessary to pass some state to the composition root to use it when resolving dependencies. To do this, just use the `RootArg(string argName)` method, specify the type of argument and its name. You can also specify a tag for each argument. You can then use them as dependencies when building the object graph. If you have multiple arguments of the same type, just use tags to distinguish them. The root of a composition that uses at least one root argument is prepended as a method, not a property. It is important to remember that the method will only display arguments that are used in the object graph of that composition root. Arguments that are not involved will not be added to the method arguments. It is best to use unique argument names so that there are no collisions. + ```c# interface IDependency { @@ -65,8 +66,32 @@ service.Dependency.DependencyName.ShouldBe("dependency 123"); When using composition root arguments, compilation warnings are shown if `Resolve` methods are generated, since these methods will not be able to create these roots. You can disable the creation of `Resolve` methods using the `Hint(Hint.Resolve, "Off")` hint, or ignore them but remember the risks of using `Resolve` methods. -
-Class Diagram +The following partial class will be generated: + +```c# +partial class Composition +{ + private readonly Composition _root; + + public Composition() + { + _root = this; + } + + internal Composition(Composition parentScope) + { + _root = (parentScope ?? throw new ArgumentNullException(nameof(parentScope)))._root; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public IService CreateService(int id, string dependencyName, string serviceName) + { + return new Service(serviceName, new Dependency(id, dependencyName)); + } +} +``` + +Class diagram: ```mermaid classDiagram @@ -97,33 +122,3 @@ classDiagram Composition ..> Service : IService CreateService(int id, string dependencyName, string serviceName) ``` -
- -
-Pure.DI-generated partial class Composition
- -```c# -partial class Composition -{ - private readonly Composition _root; - - public Composition() - { - _root = this; - } - - internal Composition(Composition parentScope) - { - _root = (parentScope ?? throw new ArgumentNullException(nameof(parentScope)))._root; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IService CreateService(int id, string dependencyName, string serviceName) - { - return new Service(serviceName, new Dependency(id, dependencyName)); - } -} -``` - -
- diff --git a/readme/root-binding.md b/readme/root-binding.md index 6624d2632..1998bd540 100644 --- a/readme/root-binding.md +++ b/readme/root-binding.md @@ -4,6 +4,7 @@ You might want to register some services as roots. You can use `RootBind()` method in order to reduce repetitions. The registration `composition.RootBind().To()` is an equivalent to `composition.Bind().To().Root()`. + ```c# interface IService; @@ -16,33 +17,7 @@ var composition = new Composition(); composition.Root.ShouldBeOfType(); ``` -
-Class Diagram - -```mermaid -classDiagram - class Composition { - <> - +IService Root - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - Service --|> IService : - class Service { - +Service() - } - class IService { - <> - } - Composition ..> Service : IService Root -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -184,5 +159,25 @@ partial class Composition } ``` -
+Class diagram: + +```mermaid +classDiagram + class Composition { + <> + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + Service --|> IService : + class Service { + +Service() + } + class IService { + <> + } + Composition ..> Service : IService Root +``` diff --git a/readme/scope.md b/readme/scope.md index 4e58cc177..72aaeb6ec 100644 --- a/readme/scope.md +++ b/readme/scope.md @@ -4,6 +4,7 @@ The _Scoped_ lifetime ensures that there will be a single instance of the dependency for each scope. + ```c# interface IDependency { @@ -77,55 +78,7 @@ session2.Dispose(); dependency2.IsDisposed.ShouldBeTrue(); ``` -
-Class Diagram - -```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 -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition: IDisposable @@ -360,5 +313,47 @@ partial class Composition: IDisposable } ``` -
+Class diagram: + +```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 +``` diff --git a/readme/service-collection.md b/readme/service-collection.md index 9d3f058fb..edb7c6daf 100644 --- a/readme/service-collection.md +++ b/readme/service-collection.md @@ -4,6 +4,7 @@ The `// OnNewRoot = On` hint specifies to create a static method that will be called for each registered composition root. This method can be used, for example, to create an _IServiceCollection_ object: + ```c# interface IDependency; @@ -41,43 +42,7 @@ var dependency = serviceProvider.GetRequiredKeyedService("Dependenc service.Dependency.ShouldBe(dependency); ``` -
-Class Diagram - -```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 _ -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -277,5 +242,35 @@ partial class Composition } ``` -
+Class diagram: + +```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 _ +``` diff --git a/readme/service-provider-with-scope.md b/readme/service-provider-with-scope.md index 9e4c519c5..cad9ace7d 100644 --- a/readme/service-provider-with-scope.md +++ b/readme/service-provider-with-scope.md @@ -2,6 +2,7 @@ [![CSharp](https://img.shields.io/badge/C%23-code-blue.svg)](../tests/Pure.DI.UsageTests/BaseClassLibrary/ServiceProviderWithScopeScenario.cs) + ```c# interface IDependency; @@ -69,44 +70,7 @@ service1.ShouldNotBe(service2); dependency1.ShouldBe(dependency2); ``` -
-Class Diagram - -```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 _ -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition: IDisposable @@ -348,5 +312,36 @@ partial class Composition: IDisposable } ``` -
+Class diagram: + +```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 _ +``` diff --git a/readme/service-provider.md b/readme/service-provider.md index 332585d79..e327a8d21 100644 --- a/readme/service-provider.md +++ b/readme/service-provider.md @@ -4,6 +4,7 @@ The `// ObjectResolveMethodName = GetService` hint overrides the _object Resolve(Type type)_ method name in _GetService_, allowing the _IServiceProvider_ interface to be implemented in a partial class. + ```c# interface IDependency; @@ -39,43 +40,7 @@ var dependency = serviceProvider.GetRequiredService(); service.Dependency.ShouldBe(dependency); ``` -
-Class Diagram - -```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 _ -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -273,5 +238,35 @@ partial class Composition } ``` -
+Class diagram: + +```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 _ +``` diff --git a/readme/simplified-binding.md b/readme/simplified-binding.md index e12e7a565..0bba08a47 100644 --- a/readme/simplified-binding.md +++ b/readme/simplified-binding.md @@ -4,6 +4,7 @@ You can use the `Bind(...)` method without type parameters. In this case binding will be performed for the implementation type itself, and if the implementation is not an abstract type or structure, for all abstract but NOT special types that are directly implemented. + ```c# interface IDependency; @@ -52,39 +53,7 @@ Special types from the list above will not be added to bindings: - `System.IAsyncResult` - `System.AsyncCallback` -
-Class Diagram - -```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 -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -113,5 +82,31 @@ partial class Composition } ``` -
+Class diagram: + +```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 +``` diff --git a/readme/singleton.md b/readme/singleton.md index c87fb353c..775aebfeb 100644 --- a/readme/singleton.md +++ b/readme/singleton.md @@ -4,6 +4,7 @@ The _Singleton_ lifetime ensures that there will be a single instance of the dependency for each composition. + ```c# interface IDependency; @@ -37,41 +38,7 @@ service1.Dependency1.ShouldBe(service1.Dependency2); service2.Dependency1.ShouldBe(service1.Dependency1); ``` -
-Class Diagram - -```mermaid -classDiagram - class Composition { - <> - +IService Root - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - Dependency --|> IDependency : - class Dependency { - +Dependency() - } - Service --|> IService : - class Service { - +Service(IDependency dependency1, IDependency dependency2) - } - class IDependency { - <> - } - class IService { - <> - } - Service o-- "2 Singleton" Dependency : IDependency - Composition ..> Service : IService Root -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -227,5 +194,33 @@ partial class Composition } ``` -
+Class diagram: + +```mermaid +classDiagram + class Composition { + <> + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + Dependency --|> IDependency : + class Dependency { + +Dependency() + } + Service --|> IService : + class Service { + +Service(IDependency dependency1, IDependency dependency2) + } + class IDependency { + <> + } + class IService { + <> + } + Service o-- "2 Singleton" Dependency : IDependency + Composition ..> Service : IService Root +``` diff --git a/readme/span-and-readonlyspan.md b/readme/span-and-readonlyspan.md index e3536b34e..17e7a7404 100644 --- a/readme/span-and-readonlyspan.md +++ b/readme/span-and-readonlyspan.md @@ -4,6 +4,7 @@ Specifying `Span` and `ReadOnlySpan` work the same as with the array `T[]`. + ```c# struct Dependency; @@ -43,41 +44,7 @@ public IService Root } ``` -
-Class Diagram - -```mermaid -classDiagram - class Composition { - <> - +IService Root - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - 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 -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -225,5 +192,33 @@ partial class Composition } ``` -
+Class diagram: + +```mermaid +classDiagram + class Composition { + <> + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + class 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 +``` diff --git a/readme/tag-attribute.md b/readme/tag-attribute.md index d06960295..262a2c3fe 100644 --- a/readme/tag-attribute.md +++ b/readme/tag-attribute.md @@ -4,6 +4,7 @@ Sometimes it's important to take control of building a dependency graph. For example, when there are multiple implementations of the same contract. In this case, _tags_ will help: + ```c# interface IDependency; @@ -46,46 +47,7 @@ service.Dependency2.ShouldBeOfType(); The tag can be a constant, a type, or a value of an enumerated type. This attribute is part of the API, but you can use your own attribute at any time, and this allows you to define them in the assembly and namespace you want. -
-Class Diagram - -```mermaid -classDiagram - class Composition { - <> - +IService Root - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - 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 -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -227,5 +189,38 @@ partial class Composition } ``` -
+Class diagram: + +```mermaid +classDiagram + class Composition { + <> + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + 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 +``` diff --git a/readme/tag-type.md b/readme/tag-type.md index 4acc4273a..362ab477e 100644 --- a/readme/tag-type.md +++ b/readme/tag-type.md @@ -4,6 +4,7 @@ `Tag.Type` in bindings replaces the expression `typeof(T)`, where `T` is the type of the implementation in a binding. + ```c# interface IDependency; @@ -54,50 +55,7 @@ service.Dependency2.ShouldBe(composition.XyzRoot); service.Dependency3.ShouldBeOfType(); ``` -
-Class Diagram - -```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 -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -294,5 +252,42 @@ partial class Composition } ``` -
+Class diagram: + +```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 +``` diff --git a/readme/tag-unique.md b/readme/tag-unique.md index 83778cadb..5b995b95c 100644 --- a/readme/tag-unique.md +++ b/readme/tag-unique.md @@ -4,6 +4,7 @@ `Tag.Unique` is useful to register a binding with a unique tag. It will not be available through the composition root or `Resolve` methods directly, but can be embedded in compositions as some kind of enumeration. + ```c# interface IDependency; @@ -35,48 +36,7 @@ var stringService = composition.Root; stringService.Dependencies.Length.ShouldBe(2); ``` -
-Class Diagram - -```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ᐳ -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -225,5 +185,40 @@ partial class Composition } ``` -
+Class diagram: + +```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ᐳ +``` diff --git a/readme/tags.md b/readme/tags.md index 27a74e037..0b820e6c0 100644 --- a/readme/tags.md +++ b/readme/tags.md @@ -4,6 +4,7 @@ Sometimes it's important to take control of building a dependency graph. For example, when there are multiple implementations of the same contract. In this case, _tags_ will help: + ```c# interface IDependency; @@ -58,50 +59,7 @@ service.Dependency3.ShouldBeOfType(); The tag can be a constant, a type, or a value of an enumerated type. The _default_ and _null_ tags are also supported. -
-Class Diagram - -```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 -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -299,5 +257,42 @@ partial class Composition } ``` -
+Class diagram: + +```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 +``` diff --git a/readme/task.md b/readme/task.md index b962b779b..0d29d1fde 100644 --- a/readme/task.md +++ b/readme/task.md @@ -11,6 +11,7 @@ By default, tasks are started automatically when they are injected. It is recomm But you can always override them, as in the example below for TaskScheduler.Current. + ```c# interface IDependency { @@ -57,56 +58,7 @@ var service = composition.GetRoot(cancellationTokenSource.Token); await service.RunAsync(cancellationTokenSource.Token); ``` -
-Class Diagram - -```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 -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -159,5 +111,48 @@ partial class Composition } ``` -
+Class diagram: + +```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 +``` diff --git a/readme/threadsafe-hint.md b/readme/threadsafe-hint.md index c7ca37baa..8637aceeb 100644 --- a/readme/threadsafe-hint.md +++ b/readme/threadsafe-hint.md @@ -5,6 +5,7 @@ Hints are used to fine-tune code generation. The _ThreadSafe_ hint determines whether object composition will be created in a thread-safe manner. This hint is _On_ by default. It is good practice not to use threads when creating an object graph, in which case this hint can be turned off, which will lead to a slight increase in performance. In addition, setup hints can be comments before the _Setup_ method in the form ```hint = value```, for example: `// ThreadSafe = Off`. + ```c# using static Hint; @@ -27,41 +28,7 @@ var service = composition.Root; For more hints, see [this](https://github.com/DevTeam/Pure.DI/blob/master/README.md#setup-hints) page. -
-Class Diagram - -```mermaid -classDiagram - class Composition { - <> - +IService Root - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - Dependency --|> IDependency : - class Dependency { - +Dependency() - } - Service --|> IService : - class Service { - +Service(IDependency dependency) - } - class IDependency { - <> - } - class IService { - <> - } - Service *-- Dependency : IDependency - Composition ..> Service : IService Root -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -203,5 +170,33 @@ partial class Composition } ``` -
+Class diagram: + +```mermaid +classDiagram + class Composition { + <> + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + Dependency --|> IDependency : + class Dependency { + +Dependency() + } + Service --|> IService : + class Service { + +Service(IDependency dependency) + } + class IDependency { + <> + } + class IService { + <> + } + Service *-- Dependency : IDependency + Composition ..> Service : IService Root +``` diff --git a/readme/tostring-hint.md b/readme/tostring-hint.md index a7e84a8e6..4ed1400a4 100644 --- a/readme/tostring-hint.md +++ b/readme/tostring-hint.md @@ -5,6 +5,7 @@ Hints are used to fine-tune code generation. The _ToString_ hint determines if the _ToString()_ method should be generated. This method provides a text-based class diagram in the format [mermaid](https://mermaid.js.org/). To see this diagram, just call the ToString method and copy the text to [this site](https://mermaid.live/). An example class diagram can be seen below. In addition, setup hints can be comments before the _Setup_ method in the form ```hint = value```, for example: `// ToString = On`. + ```c# interface IDependency; @@ -25,41 +26,7 @@ string classDiagram = composition.ToString(); For more hints, see [this](https://github.com/DevTeam/Pure.DI/blob/master/README.md#setup-hints) page. -
-Class Diagram - -```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 -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -201,5 +168,33 @@ partial class Composition } ``` -
+Class diagram: + +```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 +``` diff --git a/readme/tracking-async-disposable-instances-in-delegates.md b/readme/tracking-async-disposable-instances-in-delegates.md index 74eecc97c..edf07c1fa 100644 --- a/readme/tracking-async-disposable-instances-in-delegates.md +++ b/readme/tracking-async-disposable-instances-in-delegates.md @@ -2,6 +2,7 @@ [![CSharp](https://img.shields.io/badge/C%23-code-blue.svg)](../tests/Pure.DI.UsageTests/Advanced/TrackingAsyncDisposableInDelegatesScenario.cs) + ```c# interface IDependency { @@ -69,51 +70,7 @@ await root1.DisposeAsync(); root1.Dependency.IsDisposed.ShouldBeTrue(); ``` -
-Class Diagram - -```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 -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -282,5 +239,43 @@ partial class Composition } ``` -
+Class diagram: + +```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 +``` 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 d8db8ca88..4e488c34e 100644 --- a/readme/tracking-async-disposable-instances-per-a-composition-root.md +++ b/readme/tracking-async-disposable-instances-per-a-composition-root.md @@ -2,6 +2,7 @@ [![CSharp](https://img.shields.io/badge/C%23-code-blue.svg)](../tests/Pure.DI.UsageTests/Advanced/TrackingAsyncDisposableScenario.cs) + ```c# interface IDependency { @@ -62,48 +63,7 @@ await root1.DisposeAsync(); root1.Value.Dependency.IsDisposed.ShouldBeTrue(); ``` -
-Class Diagram - -```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 -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -192,5 +152,40 @@ partial class Composition } ``` -
+Class diagram: + +```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 +``` diff --git a/readme/tracking-disposable-instances-in-delegates.md b/readme/tracking-disposable-instances-in-delegates.md index c4984f9b4..37b0ba59d 100644 --- a/readme/tracking-disposable-instances-in-delegates.md +++ b/readme/tracking-disposable-instances-in-delegates.md @@ -2,6 +2,7 @@ [![CSharp](https://img.shields.io/badge/C%23-code-blue.svg)](../tests/Pure.DI.UsageTests/Advanced/TrackingDisposableInDelegatesScenario.cs) + ```c# interface IDependency { @@ -62,47 +63,7 @@ root1.Dispose(); root1.Dependency.IsDisposed.ShouldBeTrue(); ``` -
-Class Diagram - -```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 -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -271,5 +232,39 @@ partial class Composition } ``` -
+Class diagram: + +```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 +``` diff --git a/readme/tracking-disposable-instances-per-a-composition-root.md b/readme/tracking-disposable-instances-per-a-composition-root.md index ab980538f..ea849f7a1 100644 --- a/readme/tracking-disposable-instances-per-a-composition-root.md +++ b/readme/tracking-disposable-instances-per-a-composition-root.md @@ -2,6 +2,7 @@ [![CSharp](https://img.shields.io/badge/C%23-code-blue.svg)](../tests/Pure.DI.UsageTests/Advanced/TrackingDisposableScenario.cs) + ```c# interface IDependency { @@ -58,44 +59,7 @@ root1.Dispose(); root1.Value.Dependency.IsDisposed.ShouldBeTrue(); ``` -
-Class Diagram - -```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 -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -184,5 +148,36 @@ partial class Composition } ``` -
+Class diagram: + +```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 +``` diff --git a/readme/transient.md b/readme/transient.md index 176366484..1866efa99 100644 --- a/readme/transient.md +++ b/readme/transient.md @@ -4,6 +4,7 @@ The _Transient _ lifetime specifies to create a new dependency instance each time. It is the default lifetime and can be omitted. + ```c# interface IDependency; @@ -37,41 +38,7 @@ service1.Dependency1.ShouldNotBe(service1.Dependency2); service2.Dependency1.ShouldNotBe(service1.Dependency1); ``` -
-Class Diagram - -```mermaid -classDiagram - class Composition { - <> - +IService Root - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - Dependency --|> IDependency : - class Dependency { - +Dependency() - } - Service --|> IService : - class Service { - +Service(IDependency dependency1, IDependency dependency2) - } - class IDependency { - <> - } - class IService { - <> - } - Service *-- "2 " Dependency : IDependency - Composition ..> Service : IService Root -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -213,5 +180,33 @@ partial class Composition } ``` -
+Class diagram: + +```mermaid +classDiagram + class Composition { + <> + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + Dependency --|> IDependency : + class Dependency { + +Dependency() + } + Service --|> IService : + class Service { + +Service(IDependency dependency1, IDependency dependency2) + } + class IDependency { + <> + } + class IService { + <> + } + Service *-- "2 " Dependency : IDependency + Composition ..> Service : IService Root +``` diff --git a/readme/tuple.md b/readme/tuple.md index d554290ec..657ec8575 100644 --- a/readme/tuple.md +++ b/readme/tuple.md @@ -4,6 +4,7 @@ The tuples feature provides concise syntax to group multiple data elements in a lightweight data structure. The following example shows how a type can ask to inject a tuple argument into it: + ```c# interface IDependency; @@ -33,47 +34,7 @@ var composition = new Composition(); var root = composition.Root; ``` -
-Class Diagram - -```mermaid -classDiagram - class Composition { - <> - +IService Root - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - 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 -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -216,5 +177,39 @@ partial class Composition } ``` -
+Class diagram: + +```mermaid +classDiagram + class Composition { + <> + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + class 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 +``` diff --git a/readme/type-attribute.md b/readme/type-attribute.md index 6bfb8de4c..9df0e1ff8 100644 --- a/readme/type-attribute.md +++ b/readme/type-attribute.md @@ -4,6 +4,7 @@ The injection type can be defined manually using the `Type` attribute. This attribute explicitly overrides an injected type, otherwise it would be determined automatically based on the type of the constructor/method, property, or field parameter. + ```c# interface IDependency; @@ -42,41 +43,7 @@ service.Dependency2.ShouldBeOfType(); This attribute is part of the API, but you can use your own attribute at any time, and this allows you to define them in the assembly and namespace you want. -
-Class Diagram - -```mermaid -classDiagram - class Composition { - <> - +IService Root - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - class 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 -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -218,5 +185,33 @@ partial class Composition } ``` -
+Class diagram: + +```mermaid +classDiagram + class Composition { + <> + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + class 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 +``` diff --git a/readme/valuetask.md b/readme/valuetask.md index b6e0ff5d1..aca9aed45 100644 --- a/readme/valuetask.md +++ b/readme/valuetask.md @@ -2,6 +2,7 @@ [![CSharp](https://img.shields.io/badge/C%23-code-blue.svg)](../tests/Pure.DI.UsageTests/BaseClassLibrary/ValueTaskScenario.cs) + ```c# interface IDependency { @@ -39,43 +40,7 @@ var service = composition.Root; await service.RunAsync(); ``` -
-Class Diagram - -```mermaid -classDiagram - class Composition { - <> - +IService Root - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - Dependency --|> IDependency : - 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 -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -222,5 +187,35 @@ partial class Composition } ``` -
+Class diagram: + +```mermaid +classDiagram + class Composition { + <> + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + Dependency --|> IDependency : + 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 +``` diff --git a/readme/weak-reference.md b/readme/weak-reference.md index a79bc913d..016c4e15c 100644 --- a/readme/weak-reference.md +++ b/readme/weak-reference.md @@ -2,6 +2,7 @@ [![CSharp](https://img.shields.io/badge/C%23-code-blue.svg)](../tests/Pure.DI.UsageTests/BaseClassLibrary/WeakReferenceScenario.cs) + ```c# interface IDependency; @@ -28,45 +29,7 @@ var composition = new Composition(); var service = composition.Root; ``` -
-Class Diagram - -```mermaid -classDiagram - class Composition { - <> - +IService Root - + T ResolveᐸTᐳ() - + T ResolveᐸTᐳ(object? tag) - + object Resolve(Type type) - + object Resolve(Type type, object? tag) - } - 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 -``` - -
- -
-Pure.DI-generated partial class Composition
+The following partial class will be generated: ```c# partial class Composition @@ -208,5 +171,37 @@ partial class Composition } ``` -
+Class diagram: + +```mermaid +classDiagram + class Composition { + <> + +IService Root + + T ResolveᐸTᐳ() + + T ResolveᐸTᐳ(object? tag) + + object Resolve(Type type) + + object Resolve(Type type, object? tag) + } + class 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 +```