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
Copy file name to clipboardExpand all lines: AGENTS.md
+79Lines changed: 79 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1642,6 +1642,85 @@ The key points are:
1642
1642
- The `Dependency` (or `Ordinal`) attribute is used to mark the property for injection
1643
1643
- The DI automatically injects the dependency when resolving the object graph
1644
1644
1645
+
## Nullable reference types
1646
+
1647
+
Pure.DI preserves nullable reference type annotations when it reads dependency contracts, builds the graph, and generates composition members.
1648
+
Use nullable dependencies for values that are allowed to be absent. A nullable root or composition argument does not get a generated null check, while a non-null reference argument still does.
1649
+
A non-null binding can satisfy a nullable dependency request. This is useful for optional constructor parameters, nullable factory results, and nullable collection elements.
1650
+
>[!TIP]
1651
+
>`T?` means that the consumer can handle `null`; it does not mean that a missing binding is ignored. If no binding or auto-binding can provide the type, Pure.DI still reports the graph error.
1652
+
1653
+
```c#
1654
+
usingShouldly;
1655
+
usingPure.DI;
1656
+
usingSystem.Collections.Generic;
1657
+
usingSystem.Linq;
1658
+
1659
+
DI.Setup(nameof(Composition))
1660
+
.Hint(Hint.Resolve, "Off")
1661
+
.Bind<IDatabase>().To<Database>()
1662
+
.Bind<IReportService>().To<ReportService>()
1663
+
1664
+
// Nullable composition argument: no generated null check
1665
+
.Arg<string?>("defaultTitle", "title")
1666
+
1667
+
// Nullable root argument: no generated null check
Limitations: nullable annotations describe compile-time contracts. They are not runtime validation rules and do not replace explicit domain validation.
1718
+
Common pitfalls:
1719
+
- Using `T?` to hide a missing binding instead of modelling an optional value.
1720
+
- Forgetting tags for nullable primitive values when several values of the same type exist.
1721
+
- Assuming `IEnumerable<T?>` changes the lifetime of elements; lifetime still comes from the matched bindings.
1722
+
See also: [Composition arguments](composition-arguments.md), [Root arguments](root-arguments.md), [Injection on demand](injection-on-demand.md).
1723
+
1645
1724
## Default values
1646
1725
1647
1726
This example shows how to use default values in dependency injection when explicit injection is not possible.
Copy file name to clipboardExpand all lines: AGENTS_MEDIUM.md
+79Lines changed: 79 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1642,6 +1642,85 @@ The key points are:
1642
1642
- The `Dependency` (or `Ordinal`) attribute is used to mark the property for injection
1643
1643
- The DI automatically injects the dependency when resolving the object graph
1644
1644
1645
+
## Nullable reference types
1646
+
1647
+
Pure.DI preserves nullable reference type annotations when it reads dependency contracts, builds the graph, and generates composition members.
1648
+
Use nullable dependencies for values that are allowed to be absent. A nullable root or composition argument does not get a generated null check, while a non-null reference argument still does.
1649
+
A non-null binding can satisfy a nullable dependency request. This is useful for optional constructor parameters, nullable factory results, and nullable collection elements.
1650
+
>[!TIP]
1651
+
>`T?` means that the consumer can handle `null`; it does not mean that a missing binding is ignored. If no binding or auto-binding can provide the type, Pure.DI still reports the graph error.
1652
+
1653
+
```c#
1654
+
usingShouldly;
1655
+
usingPure.DI;
1656
+
usingSystem.Collections.Generic;
1657
+
usingSystem.Linq;
1658
+
1659
+
DI.Setup(nameof(Composition))
1660
+
.Hint(Hint.Resolve, "Off")
1661
+
.Bind<IDatabase>().To<Database>()
1662
+
.Bind<IReportService>().To<ReportService>()
1663
+
1664
+
// Nullable composition argument: no generated null check
1665
+
.Arg<string?>("defaultTitle", "title")
1666
+
1667
+
// Nullable root argument: no generated null check
Limitations: nullable annotations describe compile-time contracts. They are not runtime validation rules and do not replace explicit domain validation.
1718
+
Common pitfalls:
1719
+
- Using `T?` to hide a missing binding instead of modelling an optional value.
1720
+
- Forgetting tags for nullable primitive values when several values of the same type exist.
1721
+
- Assuming `IEnumerable<T?>` changes the lifetime of elements; lifetime still comes from the matched bindings.
1722
+
See also: [Composition arguments](composition-arguments.md), [Root arguments](root-arguments.md), [Injection on demand](injection-on-demand.md).
1723
+
1645
1724
## Default values
1646
1725
1647
1726
This example shows how to use default values in dependency injection when explicit injection is not possible.
-[Required properties or fields](readme/required-properties-or-fields.md)
311
312
-[Overrides](readme/overrides.md)
@@ -2146,8 +2147,8 @@ AI needs to understand the situation it’s in (context). This means knowing det
2146
2147
| AI context file | Size | Tokens |
2147
2148
| --------------- | ---- | ------ |
2148
2149
|[AGENTS_SMALL.md](AGENTS_SMALL.md)| 62KB | 16K |
2149
-
|[AGENTS_MEDIUM.md](AGENTS_MEDIUM.md)|108KB|27K|
2150
-
|[AGENTS.md](AGENTS.md)|406KB| 104K |
2150
+
|[AGENTS_MEDIUM.md](AGENTS_MEDIUM.md)|111KB|28K|
2151
+
|[AGENTS.md](AGENTS.md)|409KB| 104K |
2151
2152
2152
2153
For different IDEs, you can use the _AGENTS.md_ file as is by simply copying it to the root directory. For use with _JetBrains Rider_ and _Junie_, please refer to [these instructions](https://www.jetbrains.com/help/junie/customize-guidelines.html). For example, you can copy any _AGENTS.md_ file into your project (using _Pure.DI_) as _.junie/guidelines.md._
0 commit comments