Skip to content

Commit

Permalink
Minor
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolayPianikov committed Nov 29, 2024
1 parent 053fddc commit 1dde3ac
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 30 deletions.
48 changes: 38 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,6 @@ DI.Setup(nameof(Composition))
> [!NOTE]
> In fact, the `Bind().As(Singleton).To<Random>()` binding is unnecessary since _Pure.DI_ supports many .NET BCL types out of the box, including [Random](https://github.com/DevTeam/Pure.DI/blob/27a1ccd604b2fdd55f6bfec01c24c86428ddfdcb/src/Pure.DI.Core/Features/Default.g.cs#L289). It was added just for the example of using the _Singleton_ lifetime.
The Pure.DI source code generator works like this:

```mermaid
flowchart TD
setups[DI setups analysis] --> types["`Types analysis
constructors/methods/properties/fields`"] --> deps[Creating a dependency graph] --> verification[Dependency graph verification] --> code[Code generation]
```

The above code specifies the generation of a partial class named *__Composition__*, this name is defined in the `DI.Setup(nameof(Composition))` call. This class contains a *__Root__* property that returns a graph of objects with an object of type *__Program__* as the root. The type and name of the property is defined by calling `Root<Program>("Root")`. The code of the generated class looks as follows:

```c#
Expand Down Expand Up @@ -367,13 +359,13 @@ partial class Composition
}
```

</details>

The _compositionTypeName_ parameter can be omitted

- if the setup is performed inside a partial class, then the composition will be created for this partial class
- for the case of a class with composition kind `CompositionKind.Global`, see [this example](readme/global-compositions.md)

</details>

<details>
<summary>Setup arguments</summary>

Expand Down Expand Up @@ -860,6 +852,42 @@ Then documentation for the composition root:

</details>

<details>
<summary>Code generation workflow</summary>

```mermaid
flowchart TD
start@{ shape: circle, label: "Start" }
setups[fa:fa-search DI setups analysis]
types["`fa:fa-search Types analysis
constructors/methods/properties/fields`"]
subgraph dep[Dependency graph]
option[fa:fa-search Selecting a next dependency set]
creating[fa:fa-cog Creating a dependency graph variant]
verification{fa:fa-check-circle Verification}
end
codeGeneration[fa:fa-code Code generation]
compilation[fa:fa-cog Compilation]
failed@{ shape: dbl-circ, label: "fa:fa-thumbs-down Compilation failed" }
success@{ shape: dbl-circ, label: "fa:fa-thumbs-up Success" }
start ==> setups
setups -.->|Has problems| failed
setups ==> types
types -.-> |Has problems| failed
types ==> option
option ==> creating
option -.-> |There are no other options| failed
creating ==> verification
verification -->|Has problems| option
verification ==>|Correct| codeGeneration
codeGeneration ==> compilation
compilation -.-> |Has problems| failed
compilation ==> success
```

</details>

## NuGet packages

| | | |
Expand Down
40 changes: 38 additions & 2 deletions readme/FooterTemplate.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ partial class Composition
}
```

</details>

The _compositionTypeName_ parameter can be omitted

- if the setup is performed inside a partial class, then the composition will be created for this partial class
- for the case of a class with composition kind `CompositionKind.Global`, see [this example](readme/global-compositions.md)

</details>

<details>
<summary>Setup arguments</summary>

Expand Down Expand Up @@ -555,6 +555,42 @@ Then documentation for the composition root:

</details>

<details>
<summary>Code generation workflow</summary>

```mermaid
flowchart TD
start@{ shape: circle, label: "Start" }
setups[fa:fa-search DI setups analysis]
types["`fa:fa-search Types analysis
constructors/methods/properties/fields`"]
subgraph dep[Dependency graph]
option[fa:fa-search Selecting a next dependency set]
creating[fa:fa-cog Creating a dependency graph variant]
verification{fa:fa-check-circle Verification}
end
codeGeneration[fa:fa-code Code generation]
compilation[fa:fa-cog Compilation]
failed@{ shape: dbl-circ, label: "fa:fa-thumbs-down Compilation failed" }
success@{ shape: dbl-circ, label: "fa:fa-thumbs-up Success" }
start ==> setups
setups -.->|Has problems| failed
setups ==> types
types -.-> |Has problems| failed
types ==> option
option ==> creating
option -.-> |There are no other options| failed
creating ==> verification
verification -->|Has problems| option
verification ==>|Correct| codeGeneration
codeGeneration ==> compilation
compilation -.-> |Has problems| failed
compilation ==> success
```

</details>

## NuGet packages

| | | |
Expand Down
8 changes: 0 additions & 8 deletions readme/ReadmeTemplate.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,6 @@ DI.Setup(nameof(Composition))
> [!NOTE]
> In fact, the `Bind().As(Singleton).To<Random>()` binding is unnecessary since _Pure.DI_ supports many .NET BCL types out of the box, including [Random](https://github.com/DevTeam/Pure.DI/blob/27a1ccd604b2fdd55f6bfec01c24c86428ddfdcb/src/Pure.DI.Core/Features/Default.g.cs#L289). It was added just for the example of using the _Singleton_ lifetime.
The Pure.DI source code generator works like this:

```mermaid
flowchart TD
setups[DI setups analysis] --> types["`Types analysis
constructors/methods/properties/fields`"] --> deps[Creating a dependency graph] --> verification[Dependency graph verification] --> code[Code generation]
```

The above code specifies the generation of a partial class named *__Composition__*, this name is defined in the `DI.Setup(nameof(Composition))` call. This class contains a *__Root__* property that returns a graph of objects with an object of type *__Program__* as the root. The type and name of the property is defined by calling `Root<Program>("Root")`. The code of the generated class looks as follows:

```c#
Expand Down
4 changes: 2 additions & 2 deletions readme/SingletonDetails.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ classDiagram
CompositionRoot o-- "Scoped" Service1 : IService1
CompositionRoot *-- "3 " Service2 : IService2
CompositionRoot *-- Service3 : IService3
CompositionRoot o-- "2 Scoped" Service4 : IService4
CompositionRoot o-- "2 Scoped instances" Service4 : IService4
Service1 *-- Service2 : IService2
Service2 *-- "5 " Service3 : IService3
Service3 o-- "2 Scoped" Service4 : IService4
Service3 o-- "2 Scoped instances" Service4 : IService4
```

### Generated code
Expand Down
2 changes: 1 addition & 1 deletion readme/default-lifetime-for-a-type.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,6 @@ classDiagram
<<interface>>
}
Composition ..> Service : IService Root
Service o-- "2 Singleton" Dependency : IDependency
Service o-- "2 Singleton instances" Dependency : IDependency
```

2 changes: 1 addition & 1 deletion readme/default-lifetime.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,6 @@ classDiagram
<<interface>>
}
Composition ..> Service : IService Root
Service o-- "2 Singleton" Dependency : IDependency
Service o-- "2 Singleton instances" Dependency : IDependency
```

4 changes: 2 additions & 2 deletions readme/perblock.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ classDiagram
<<interface>>
}
Composition ..> Service : Service Root
Service o-- "2 PerBlock" Dependency : IDependency
Service o-- "2 PerBlock instances" Dependency : IDependency
Service o-- "Singleton" ValueTupleᐸIDependencyˏIDependencyᐳ : ValueTupleᐸIDependencyˏIDependencyᐳ
ValueTupleᐸIDependencyˏIDependencyᐳ o-- "2 PerBlock" Dependency : IDependency
ValueTupleᐸIDependencyˏIDependencyᐳ o-- "2 PerBlock instances" Dependency : IDependency
```

4 changes: 2 additions & 2 deletions readme/perresolve.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ classDiagram
<<interface>>
}
Composition ..> Service : Service Root
Service o-- "2 PerResolve" Dependency : IDependency
Service o-- "2 PerResolve instances" Dependency : IDependency
Service o-- "Singleton" ValueTupleᐸIDependencyˏIDependencyᐳ : ValueTupleᐸIDependencyˏIDependencyᐳ
ValueTupleᐸIDependencyˏIDependencyᐳ o-- "2 PerResolve" Dependency : IDependency
ValueTupleᐸIDependencyˏIDependencyᐳ o-- "2 PerResolve instances" Dependency : IDependency
```

2 changes: 1 addition & 1 deletion readme/singleton.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,6 @@ classDiagram
<<interface>>
}
Composition ..> Service : IService Root
Service o-- "2 Singleton" Dependency : IDependency
Service o-- "2 Singleton instances" Dependency : IDependency
```

4 changes: 4 additions & 0 deletions src/Pure.DI.Core/Core/Code/ClassDiagramBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ private static string FormatCardinality(int count, Lifetime lifetime)
if (lifetime != Lifetime.Transient)
{
cardinality.Append(lifetime);
if (count > 1)
{
cardinality.Append(" instances");
}
}

if (cardinality.Length > 0)
Expand Down
2 changes: 1 addition & 1 deletion src/Pure.DI.Core/Features/Default.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ private static void Setup()
.To(_ => global::System.Buffers.ArrayPool<TT>.Shared)
#endif
.Bind<global::System.Collections.Generic.IList<TT>>()
.Bind<global::System.Collections.Generic.ICollection<TT>>()
.Bind<global::System.Collections.Generic.List<TT>>()
.To((TT[] arr) => new global::System.Collections.Generic.List<TT>(arr))
.Bind<global::System.Collections.Generic.ICollection<TT>>()
.Bind<global::System.Collections.ObjectModel.Collection<TT>>()
.To((TT[] arr) => new global::System.Collections.ObjectModel.Collection<TT>(arr))
#if NETSTANDARD || NET || NETCOREAPP || NET45_OR_GREATER
Expand Down

0 comments on commit 1dde3ac

Please sign in to comment.