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: AI_CONTEXT_LARGE.md
+42-21Lines changed: 42 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -470,6 +470,8 @@ To run the above code, the following NuGet packages must be added:
470
470
471
471
## Injections as required
472
472
473
+
This example demonstrates using dependency injection with Pure.DI to dynamically create dependencies as needed via a factory function. The code defines a service (`Service`) that requires multiple instances of a dependency (`Dependency`). Instead of injecting pre-created instances, the service receives a `Func<IDependency>` factory delegate, allowing it to generate dependencies on demand.
474
+
473
475
```c#
474
476
usingShouldly;
475
477
usingPure.DI;
@@ -509,9 +511,17 @@ To run the above code, the following NuGet packages must be added:
-`Dependency` is bound to the `IDependency` interface, and `Service` is bound to `IService`.
516
+
- The `Service` constructor accepts `Func<IDependency>`, enabling deferred creation of dependencies.
517
+
- The `Service` calls the factory twice, resulting in two distinct `Dependency` instances stored in its `Dependencies` collection.
518
+
519
+
This approach showcases how factories can control dependency lifetime and instance creation timing in a DI container. The Pure.DI configuration ensures the factory resolves new `IDependency` instances each time it's invoked, achieving "injections as required" functionality.
512
520
513
521
## Injections as required with arguments
514
522
523
+
This example illustrates dependency injection with parameterized factory functions using Pure.DI, where dependencies are created with runtime-provided arguments. The scenario features a service that generates dependencies with specific IDs passed during instantiation.
524
+
515
525
```c#
516
526
usingShouldly;
517
527
usingPure.DI;
@@ -560,6 +570,15 @@ To run the above code, the following NuGet packages must be added:
-`Dependency` class accepts an int id constructor argument, stored in its `Id` property.
575
+
-`Service` receives `Func<int, IDependency>` delegate, enabling creation of dependencies with dynamic values.
576
+
-`Service` creates two dependencies using the factory – one with ID `33`, another with ID `99`.
577
+
578
+
Delayed dependency instantiation:
579
+
- Injection of dependencies requiring runtime parameters
580
+
- Creation of distinct instances with different configurations
581
+
- Type-safe resolution of dependencies with constructor arguments
563
582
564
583
## Class arguments
565
584
@@ -1377,6 +1396,8 @@ To run the above code, the following NuGet packages must be added:
1377
1396
1378
1397
## Overrides
1379
1398
1399
+
This example demonstrates advanced dependency injection techniques using Pure.DI's override mechanism to customize dependency instantiation with runtime arguments and tagged parameters. The implementation creates multiple `IDependency` instances with values manipulated through explicit overrides.
Copy file name to clipboardExpand all lines: AI_CONTEXT_MEDIUM.md
+19-53Lines changed: 19 additions & 53 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -470,6 +470,8 @@ To run the above code, the following NuGet packages must be added:
470
470
471
471
## Injections as required
472
472
473
+
This example demonstrates using dependency injection with Pure.DI to dynamically create dependencies as needed via a factory function. The code defines a service (`Service`) that requires multiple instances of a dependency (`Dependency`). Instead of injecting pre-created instances, the service receives a `Func<IDependency>` factory delegate, allowing it to generate dependencies on demand.
474
+
473
475
```c#
474
476
usingShouldly;
475
477
usingPure.DI;
@@ -509,9 +511,17 @@ To run the above code, the following NuGet packages must be added:
-`Dependency` is bound to the `IDependency` interface, and `Service` is bound to `IService`.
516
+
- The `Service` constructor accepts `Func<IDependency>`, enabling deferred creation of dependencies.
517
+
- The `Service` calls the factory twice, resulting in two distinct `Dependency` instances stored in its `Dependencies` collection.
518
+
519
+
This approach showcases how factories can control dependency lifetime and instance creation timing in a DI container. The Pure.DI configuration ensures the factory resolves new `IDependency` instances each time it's invoked, achieving "injections as required" functionality.
512
520
513
521
## Injections as required with arguments
514
522
523
+
This example illustrates dependency injection with parameterized factory functions using Pure.DI, where dependencies are created with runtime-provided arguments. The scenario features a service that generates dependencies with specific IDs passed during instantiation.
524
+
515
525
```c#
516
526
usingShouldly;
517
527
usingPure.DI;
@@ -560,6 +570,15 @@ To run the above code, the following NuGet packages must be added:
Interception is the ability to intercept calls between objects in order to enrich or change their behavior, but without having to change their code. A prerequisite for interception is weak binding. That is, if programming is abstraction-based, the underlying implementation can be transformed or improved by "packaging" it into other implementations of the same abstraction. At its core, intercept is an application of the Decorator design pattern. This pattern provides a flexible alternative to inheritance by dynamically "attaching" additional responsibility to an object. Decorator "packs" one implementation of an abstraction into another implementation of the same abstraction like a "matryoshka doll".
Copy file name to clipboardExpand all lines: AI_CONTEXT_SMALL.md
+19Lines changed: 19 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -470,6 +470,8 @@ To run the above code, the following NuGet packages must be added:
470
470
471
471
## Injections as required
472
472
473
+
This example demonstrates using dependency injection with Pure.DI to dynamically create dependencies as needed via a factory function. The code defines a service (`Service`) that requires multiple instances of a dependency (`Dependency`). Instead of injecting pre-created instances, the service receives a `Func<IDependency>` factory delegate, allowing it to generate dependencies on demand.
474
+
473
475
```c#
474
476
usingShouldly;
475
477
usingPure.DI;
@@ -509,9 +511,17 @@ To run the above code, the following NuGet packages must be added:
-`Dependency` is bound to the `IDependency` interface, and `Service` is bound to `IService`.
516
+
- The `Service` constructor accepts `Func<IDependency>`, enabling deferred creation of dependencies.
517
+
- The `Service` calls the factory twice, resulting in two distinct `Dependency` instances stored in its `Dependencies` collection.
518
+
519
+
This approach showcases how factories can control dependency lifetime and instance creation timing in a DI container. The Pure.DI configuration ensures the factory resolves new `IDependency` instances each time it's invoked, achieving "injections as required" functionality.
512
520
513
521
## Injections as required with arguments
514
522
523
+
This example illustrates dependency injection with parameterized factory functions using Pure.DI, where dependencies are created with runtime-provided arguments. The scenario features a service that generates dependencies with specific IDs passed during instantiation.
524
+
515
525
```c#
516
526
usingShouldly;
517
527
usingPure.DI;
@@ -560,6 +570,15 @@ To run the above code, the following NuGet packages must be added:
Thank you for your interest in contributing to the Pure.DI project! First of all, if you are going to make a big change or feature, please open a problem first. That way, we can coordinate and understand if the change you're going to work on fits with current priorities and if we can commit to reviewing and merging it within a reasonable timeframe. We don't want you to waste a lot of your valuable time on something that may not align with what we want for Pure.DI.
0 commit comments