You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|`DI.Setup("Composition")`| A partial class named `Composition`, unless the setup kind prevents class generation. |
571
+
|`.Root<T>("Name")`| A public property named `Name`, or a method named `Name` when the root uses root arguments or generic type arguments. |
572
+
|`.Root<T>()`| An anonymous private root. It is available only through generated `Resolve`/`ResolveByTag` methods when those methods can resolve it. |
573
+
|`.Arg<T>("name")`| A composition constructor parameter when the argument is used by at least one root graph. |
574
+
|`.RootArg<T>("name")`| A parameter on root methods that use this value. Roots with root arguments cannot be resolved by `Resolve`/`ResolveByTag`. |
575
+
|`Lifetime.Transient`| A new instance is created at each injection site. |
576
+
|`Lifetime.Singleton`| A private cached field is generated and reused by the composition. |
577
+
|`Lifetime.Scoped`| Scope-related constructors/members are generated and the instance is reused inside a scope. |
578
+
|`Lifetime.PerResolve`| A local value is reused during one root or `Resolve` call. |
579
+
|`Lifetime.PerBlock`| A local value is reused inside a generated code block. |
580
+
| Disposable singleton/scoped dependency |`Dispose` and/or `DisposeAsync` are generated on the composition. |
581
+
|`Hint.Resolve = Off`|`Resolve`/`ResolveByTag` methods and anonymous roots are not generated. Use named roots directly. |
582
+
|`Hint.ToString = On`|`ToString()` returns a Mermaid class diagram of the composition. |
583
+
|`Hint.Comments = Off`| XML documentation comments are not generated for the composition API. |
584
+
|`Hint.FormatCode = On`| Generated code is formatted for easier reading. |
585
+
586
+
</details>
587
+
516
588
<details>
517
589
<summary>Setup arguments</summary>
518
590
@@ -1978,6 +2050,17 @@ See also:
1978
2050
<summary>Comments</summary>
1979
2051
1980
2052
Pure.DI can copy comments from setup calls into generated documentation comments for the composition class, composition arguments, and composition roots.
2053
+
When no user comment is provided, Pure.DI generates documentation for the generated API so the composition can be inspected from IntelliSense.
2054
+
2055
+
Generated comments describe:
2056
+
2057
+
- The composition roots exposed by the generated composition class.
2058
+
- The root contract, implementation type, tag, and lifetime.
2059
+
- Whether a root is a property or a method.
2060
+
- Composition constructor parameters created from used `Arg<T>(...)` values.
2061
+
- Root method parameters created from used `RootArg<T>(...)` values.
2062
+
-`Resolve`/`ResolveByTag` limitations for roots that require root arguments.
2063
+
-`Dispose`/`DisposeAsync` behavior for tracked singleton and scoped disposable instances.
1981
2064
1982
2065
Use regular `//` comments before API calls when you want Pure.DI to include the text in the generated documentation:
1983
2066
@@ -2016,6 +2099,15 @@ public IService Service
2016
2099
2017
2100
For other setup calls, such as `Arg<T>(...)`, comments are used as documentation text in the generated constructor documentation. Use regular `//` comments there unless you want XML markup to be shown as text.
2018
2101
2102
+
To suppress generated documentation comments, turn comments off for the setup:
2103
+
2104
+
```c#
2105
+
DI.Setup("Composition")
2106
+
.Hint(Hint.Comments, "Off")
2107
+
.Bind<IService>().To<Service>()
2108
+
.Root<IService>("Service");
2109
+
```
2110
+
2019
2111
</details>
2020
2112
2021
2113
<details>
@@ -2054,6 +2146,65 @@ flowchart TD
2054
2146
2055
2147
</details>
2056
2148
2149
+
<details>
2150
+
<summary>Debugging generated code</summary>
2151
+
2152
+
Use this workflow when you need to inspect or debug the generated composition:
3. Rebuild the project and open the generated `Composition.g.cs` file under the configured generated files folder.
2173
+
2174
+
4. Start with the generated public API:
2175
+
2176
+
- composition constructors;
2177
+
- root properties and root methods;
2178
+
-`Resolve`/`ResolveByTag` methods;
2179
+
- scope factory methods;
2180
+
-`Dispose`/`DisposeAsync`.
2181
+
2182
+
5. Then inspect the root body that creates the graph. Constructor calls show the exact dependency path, private fields show cached singleton/scoped values, and local variables show per-resolve/per-block reuse.
2183
+
2184
+
6. For a structural view, enable `Hint.ToString` and render the Mermaid diagram:
2185
+
2186
+
```c#
2187
+
DI.Setup("Composition")
2188
+
.Hint(Hint.ToString, "On")
2189
+
.Bind<IService>().To<Service>()
2190
+
.Root<IService>("Service");
2191
+
2192
+
vardiagram=newComposition().ToString();
2193
+
```
2194
+
2195
+
7. If an anonymous root is hard to step through, disable lightweight anonymous roots for debugging:
2196
+
2197
+
```c#
2198
+
DI.Setup("Composition")
2199
+
.Hint(Hint.LightweightAnonymousRoot, "Off")
2200
+
.Bind<IService>().To<Service>()
2201
+
.Root<IService>();
2202
+
```
2203
+
2204
+
Turn `FormatCode`, `ToString`, and extra debugging hints off again when they are no longer needed.
2205
+
2206
+
</details>
2207
+
2057
2208
## Project template
2058
2209
2059
2210
Install the DI template [Pure.DI.Templates](https://www.nuget.org/packages/Pure.DI.Templates)
@@ -2131,6 +2282,62 @@ You can set project properties to save generated files and control their storage
2131
2282
2132
2283
</details>
2133
2284
2285
+
<details>
2286
+
<summary>Generated code troubleshooting</summary>
2287
+
2288
+
### Generated files are not visible
2289
+
2290
+
Set `EmitCompilerGeneratedFiles` to `true`, rebuild the project, and check the generated files folder configured by `CompilerGeneratedFilesOutputPath`. If the folder is empty, run `dotnet build-server shutdown`, rebuild, and check that the project references the `Pure.DI` package.
2291
+
2292
+
### The root was generated as a method, not a property
2293
+
2294
+
A root becomes a method when it needs runtime data, such as `RootArg<T>(...)`, or when the root itself is generic. Call it directly and pass the required arguments:
2295
+
2296
+
```c#
2297
+
varservice=composition.CreateService(userId);
2298
+
```
2299
+
2300
+
### Resolve methods were not generated
2301
+
2302
+
Check `Hint.Resolve`. When it is `Off`, `Resolve`/`ResolveByTag` methods are intentionally omitted and anonymous roots are not generated. Use named roots instead:
2303
+
2304
+
```c#
2305
+
varservice=composition.Service;
2306
+
```
2307
+
2308
+
### Resolve cannot create a root with root arguments
2309
+
2310
+
`Resolve`/`ResolveByTag` methods do not have a place to pass root arguments. Use the generated root method directly, or disable `Resolve` with `Hint.Resolve = Off` to avoid warnings and keep the generated API explicit.
2311
+
2312
+
### A lock appears in generated code
2313
+
2314
+
Pure.DI generates synchronization for thread-safe access to cached instances when needed. To remove it only when composition access is known to be single-threaded, use:
2315
+
2316
+
```c#
2317
+
DI.Setup("Composition")
2318
+
.Hint(Hint.ThreadSafe, "Off");
2319
+
```
2320
+
2321
+
### Dispose or DisposeAsync was generated
2322
+
2323
+
The composition tracks singleton and scoped instances that implement `IDisposable` or `IAsyncDisposable`. Dispose the composition when it owns such instances:
2324
+
2325
+
```c#
2326
+
usingvarcomposition=newComposition();
2327
+
```
2328
+
2329
+
or:
2330
+
2331
+
```c#
2332
+
awaitusingvarcomposition=newComposition();
2333
+
```
2334
+
2335
+
### Generated code is hard to read
2336
+
2337
+
Temporarily enable `Hint.FormatCode` and save generated files with `EmitCompilerGeneratedFiles`. For graph-level inspection, enable `Hint.ToString` and use the Mermaid diagram.
0 commit comments