Skip to content

Commit eada12e

Browse files
Update README
1 parent 4d1cded commit eada12e

18 files changed

Lines changed: 100 additions & 282 deletions

AGENTS.md

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2471,14 +2471,12 @@ To run the above code, the following NuGet packages must be added:
24712471
24722472
## Scope
24732473

2474-
Demonstrates scoped lifetime with `Hint(Hint.ScopeFactory, "on")` where scopes are represented by generated `Scope` objects created via `CreateScope()`.
2475-
24762474
```c#
24772475
using Shouldly;
24782476
using Pure.DI;
24792477
using static Pure.DI.Lifetime;
24802478

2481-
var composition = new Composition(desc: "Checkout");
2479+
var composition = new Composition();
24822480
IRequestContext ctx1;
24832481
IRequestContext ctx2;
24842482

@@ -2545,9 +2543,7 @@ interface ICheckoutService
25452543

25462544
// "Controller/service" that participates in request processing.
25472545
// It depends on a scoped context (per-request resource).
2548-
sealed class CheckoutService(
2549-
string description,
2550-
IRequestContext context)
2546+
sealed class CheckoutService(IRequestContext context)
25512547
: ICheckoutService
25522548
{
25532549
public IRequestContext Context => context;
@@ -2556,7 +2552,7 @@ sealed class CheckoutService(
25562552
// Represents a scope
25572553
class Scope(Composition composition): IDisposable
25582554
{
2559-
private readonly Composition _scope = composition.CreateScope();
2555+
private readonly Composition _scope = Composition.SetupScope(composition, new Composition());
25602556

25612557
public ICheckoutService Checkout => _scope.RequestRoot;
25622558

@@ -2568,8 +2564,7 @@ partial class Composition
25682564
static void Setup() =>
25692565

25702566
DI.Setup()
2571-
.Hint(Hint.ScopeFactoryName, "CreateScope")
2572-
.Arg<string>("desc")
2567+
.Hint(Hint.ScopeMethodName, "SetupScope")
25732568
// Per-request lifetime
25742569
.Bind().As(Scoped).To<RequestContext>()
25752570

@@ -2588,12 +2583,8 @@ To run the above code, the following NuGet packages must be added:
25882583
- [Pure.DI](https://www.nuget.org/packages/Pure.DI)
25892584
- [Shouldly](https://www.nuget.org/packages/Shouldly)
25902585

2591-
>[!NOTE]
2592-
>This approach is useful when you need runtime scope creation without deriving a child composition type.
2593-
2594-
## Scope factory
25952586

2596-
Demonstrates scoped lifetime with `Hint(Hint.ScopeFactory, "on")` where scopes are represented by generated `Scope` objects created via `CreateScope()`.
2587+
## Scope setup method
25972588

25982589
```c#
25992590
using Shouldly;
@@ -2605,7 +2596,7 @@ IRequestContext ctx1;
26052596
IRequestContext ctx2;
26062597

26072598
// Request #1
2608-
using (var request1 = composition.CreateScope())
2599+
using (var request1 = Composition.SetupScope(composition, new Composition()))
26092600
{
26102601
var checkout11 = request1.RequestRoot;
26112602
var checkout12 = request1.RequestRoot;
@@ -2620,7 +2611,7 @@ using (var request1 = composition.CreateScope())
26202611
ctx1.IsDisposed.ShouldBeTrue();
26212612

26222613
// Request #2
2623-
using (var request2 = composition.CreateScope())
2614+
using (var request2 = Composition.SetupScope(composition, new Composition()))
26242615
{
26252616
var checkout2 = request2.RequestRoot;
26262617
ctx2 = checkout2.Context;
@@ -2678,7 +2669,7 @@ partial class Composition
26782669
static void Setup() =>
26792670

26802671
DI.Setup()
2681-
.Hint(Hint.ScopeFactoryName, "CreateScope")
2672+
.Hint(Hint.ScopeMethodName, "SetupScope")
26822673
// Per-request lifetime
26832674
.Bind().As(Scoped).To<RequestContext>()
26842675

@@ -2696,8 +2687,6 @@ To run the above code, the following NuGet packages must be added:
26962687
- [Pure.DI](https://www.nuget.org/packages/Pure.DI)
26972688
- [Shouldly](https://www.nuget.org/packages/Shouldly)
26982689

2699-
>[!NOTE]
2700-
>This approach is useful when you need runtime scope creation without deriving a child composition type.
27012690

27022691
## Scoped
27032692

AGENTS_SMALL.md

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,14 +1185,12 @@ To run the above code, the following NuGet packages must be added:
11851185
11861186
## Scope
11871187

1188-
Demonstrates scoped lifetime with `Hint(Hint.ScopeFactory, "on")` where scopes are represented by generated `Scope` objects created via `CreateScope()`.
1189-
11901188
```c#
11911189
using Shouldly;
11921190
using Pure.DI;
11931191
using static Pure.DI.Lifetime;
11941192

1195-
var composition = new Composition(desc: "Checkout");
1193+
var composition = new Composition();
11961194
IRequestContext ctx1;
11971195
IRequestContext ctx2;
11981196

@@ -1259,9 +1257,7 @@ interface ICheckoutService
12591257

12601258
// "Controller/service" that participates in request processing.
12611259
// It depends on a scoped context (per-request resource).
1262-
sealed class CheckoutService(
1263-
string description,
1264-
IRequestContext context)
1260+
sealed class CheckoutService(IRequestContext context)
12651261
: ICheckoutService
12661262
{
12671263
public IRequestContext Context => context;
@@ -1270,7 +1266,7 @@ sealed class CheckoutService(
12701266
// Represents a scope
12711267
class Scope(Composition composition): IDisposable
12721268
{
1273-
private readonly Composition _scope = composition.CreateScope();
1269+
private readonly Composition _scope = Composition.SetupScope(composition, new Composition());
12741270

12751271
public ICheckoutService Checkout => _scope.RequestRoot;
12761272

@@ -1282,8 +1278,7 @@ partial class Composition
12821278
static void Setup() =>
12831279

12841280
DI.Setup()
1285-
.Hint(Hint.ScopeFactoryName, "CreateScope")
1286-
.Arg<string>("desc")
1281+
.Hint(Hint.ScopeMethodName, "SetupScope")
12871282
// Per-request lifetime
12881283
.Bind().As(Scoped).To<RequestContext>()
12891284

@@ -1302,12 +1297,8 @@ To run the above code, the following NuGet packages must be added:
13021297
- [Pure.DI](https://www.nuget.org/packages/Pure.DI)
13031298
- [Shouldly](https://www.nuget.org/packages/Shouldly)
13041299

1305-
>[!NOTE]
1306-
>This approach is useful when you need runtime scope creation without deriving a child composition type.
1307-
1308-
## Scope factory
13091300

1310-
Demonstrates scoped lifetime with `Hint(Hint.ScopeFactory, "on")` where scopes are represented by generated `Scope` objects created via `CreateScope()`.
1301+
## Scope setup method
13111302

13121303
```c#
13131304
using Shouldly;
@@ -1319,7 +1310,7 @@ IRequestContext ctx1;
13191310
IRequestContext ctx2;
13201311

13211312
// Request #1
1322-
using (var request1 = composition.CreateScope())
1313+
using (var request1 = Composition.SetupScope(composition, new Composition()))
13231314
{
13241315
var checkout11 = request1.RequestRoot;
13251316
var checkout12 = request1.RequestRoot;
@@ -1334,7 +1325,7 @@ using (var request1 = composition.CreateScope())
13341325
ctx1.IsDisposed.ShouldBeTrue();
13351326

13361327
// Request #2
1337-
using (var request2 = composition.CreateScope())
1328+
using (var request2 = Composition.SetupScope(composition, new Composition()))
13381329
{
13391330
var checkout2 = request2.RequestRoot;
13401331
ctx2 = checkout2.Context;
@@ -1392,7 +1383,7 @@ partial class Composition
13921383
static void Setup() =>
13931384

13941385
DI.Setup()
1395-
.Hint(Hint.ScopeFactoryName, "CreateScope")
1386+
.Hint(Hint.ScopeMethodName, "SetupScope")
13961387
// Per-request lifetime
13971388
.Bind().As(Scoped).To<RequestContext>()
13981389

@@ -1410,8 +1401,6 @@ To run the above code, the following NuGet packages must be added:
14101401
- [Pure.DI](https://www.nuget.org/packages/Pure.DI)
14111402
- [Shouldly](https://www.nuget.org/packages/Shouldly)
14121403

1413-
>[!NOTE]
1414-
>This approach is useful when you need runtime scope creation without deriving a child composition type.
14151404

14161405
## Scoped
14171406

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ dotnet run
322322
- [PerResolve](readme/perresolve.md)
323323
- [PerBlock](readme/perblock.md)
324324
- [Scope](readme/scope.md)
325-
- [Scope factory](readme/scope-factory.md)
325+
- [Scope setup method](readme/scope-setup-method.md)
326326
- [Scoped](readme/scoped.md)
327327
- [Auto scoped](readme/auto-scoped.md)
328328
- [Default lifetime](readme/default-lifetime.md)
@@ -1175,7 +1175,7 @@ DI.Setup("Composition")
11751175
| [DisableAutoBindingLifetimeRegularExpression](#disableautobindinglifetimeregularexpression-hint) | Regular expression | | .+ |
11761176
| [DisableAutoBindingLifetimeWildcard](#disableautobindinglifetimewildcard-hint) | Wildcard | | * |
11771177
| [LightweightAnonymousRoot](#lightweightanonymousroot-hint) | _On_ or _Off_ | | _On_ |
1178-
| [ScopeFactoryName](#scopefactoryname-hint) | Method name | | |
1178+
| [ScopeMethodName](#ScopeMethodName-hint) | Method name | | |
11791179

11801180
The list of hints will be gradually expanded to meet the needs and desires for fine-tuning code generation. Please feel free to add your ideas.
11811181

@@ -1843,14 +1843,14 @@ DI.Setup("Composition")
18431843
.Bind<IService>().To<Service>();
18441844
```
18451845

1846-
### ScopeFactoryName Hint
1846+
### ScopeMethodName Hint
18471847

18481848
Sets the scope factory name to be used for creating scopes.
18491849

18501850
```c#
1851-
// ScopeFactoryName = CreateScope
1851+
// ScopeMethodName = CreateScope
18521852
DI.Setup("Composition")
1853-
.Hint(Hint.ScopeFactoryName, "CreateScope")
1853+
.Hint(Hint.ScopeMethodName, "CreateScope")
18541854
.Bind<IDependency>().As(Lifetime.Scoped).To<Dependency>();
18551855
```
18561856

@@ -2036,7 +2036,7 @@ AI needs to understand the situation it’s in (context). This means knowing det
20362036

20372037
| AI context file | Size | Tokens |
20382038
| --------------- | ---- | ------ |
2039-
| [AGENTS_SMALL.md](AGENTS_SMALL.md) | 63KB | 16K |
2039+
| [AGENTS_SMALL.md](AGENTS_SMALL.md) | 62KB | 16K |
20402040
| [AGENTS_MEDIUM.md](AGENTS_MEDIUM.md) | 106KB | 27K |
20412041
| [AGENTS.md](AGENTS.md) | 387KB | 99K |
20422042

@@ -2129,9 +2129,9 @@ Thanks!
21292129

21302130
## Benchmarks
21312131

2132-
BenchmarkDotNet v0.14.0, Windows 10 (10.0.19045.4894/22H2/2022Update)
2133-
AMD Ryzen 9 5900X, 1 CPU, 24 logical and 12 physical cores
2134-
.NET SDK 9.0.100
2132+
BenchmarkDotNet v0.15.8, Windows 10 (10.0.19045.6456/22H2/2022Update)
2133+
AMD Ryzen 9 5900X 4.20GHz, 1 CPU, 24 logical and 12 physical cores
2134+
.NET SDK 10.0.102
21352135

21362136
<details>
21372137
<summary>Transient</summary>

readme/bind-attribute-with-lifetime-and-tag.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,28 +89,28 @@ partial class Composition
8989
private readonly Object _lock = new Object();
9090
#endif
9191

92-
private IGpu? _singletonIGpu2147483136;
92+
private IGpu? _singletonIGpu2147483137;
9393
private GraphicsAdapter? _singletonGraphicsAdapter62;
9494

9595
public IRenderer Renderer
9696
{
9797
[MethodImpl(MethodImplOptions.AggressiveInlining)]
9898
get
9999
{
100-
if (_singletonIGpu2147483136 is null)
100+
if (_singletonIGpu2147483137 is null)
101101
lock (_lock)
102-
if (_singletonIGpu2147483136 is null)
102+
if (_singletonIGpu2147483137 is null)
103103
{
104104
if (_singletonGraphicsAdapter62 is null)
105105
{
106106
_singletonGraphicsAdapter62 = new GraphicsAdapter();
107107
}
108108

109109
GraphicsAdapter localInstance_1182D1279 = _singletonGraphicsAdapter62;
110-
_singletonIGpu2147483136 = localInstance_1182D1279.HighPerfGpu;
110+
_singletonIGpu2147483137 = localInstance_1182D1279.HighPerfGpu;
111111
}
112112

113-
return new RayTracer(_singletonIGpu2147483136);
113+
return new RayTracer(_singletonIGpu2147483137);
114114
}
115115
}
116116
}

readme/check-for-a-root.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ Class diagram:
313313
classDiagram
314314
SqlUserRepository --|> IUserRepository : "Primary"
315315
UserService --|> IUserService
316-
Composition ..> LightweightRoot : LightweightRoot LightRoot102d
316+
Composition ..> LightweightRoot : LightweightRoot LightRoot104d
317317
Composition ..> UserService : IUserService Root
318318
Composition ..> SqlUserRepository : IUserRepository _
319319
UserService *-- SqlUserRepository : "Primary" IUserRepository
@@ -329,7 +329,7 @@ classDiagram
329329
namespace Pure.DI.UsageTests.Hints.CheckForRootScenario {
330330
class Composition {
331331
<<partial>>
332-
-LightweightRoot LightRoot102d
332+
-LightweightRoot LightRoot104d
333333
+IUserService Root
334334
-IUserRepository _
335335
+ T ResolveᐸTᐳ()

readme/composition-roots.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ classDiagram
333333
PdfInvoiceGenerator --|> IInvoiceGenerator
334334
HtmlInvoiceGenerator --|> IInvoiceGenerator : "Online"
335335
FileLogger --|> ILogger
336-
Composition ..> LightweightRoot : LightweightRoot LightRoot102d
336+
Composition ..> LightweightRoot : LightweightRoot LightRoot104d
337337
Composition ..> HtmlInvoiceGenerator : IInvoiceGenerator OnlineInvoiceGenerator
338338
Composition ..> FileLogger : ILogger _
339339
Composition ..> PdfInvoiceGenerator : IInvoiceGenerator InvoiceGenerator
@@ -351,7 +351,7 @@ classDiagram
351351
class Composition {
352352
<<partial>>
353353
+IInvoiceGenerator InvoiceGenerator
354-
-LightweightRoot LightRoot102d
354+
-LightweightRoot LightRoot104d
355355
+IInvoiceGenerator OnlineInvoiceGenerator
356356
-ILogger _
357357
+ T ResolveᐸTᐳ()

readme/keyed-service-provider.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ Class diagram:
335335
classDiagram
336336
PayPalGateway --|> IPaymentGateway : "PayPal"
337337
OnlineOrderService --|> IOrderService : "Online"
338-
Composition ..> LightweightRoot : LightweightRoot LightRoot102d
338+
Composition ..> LightweightRoot : LightweightRoot LightRoot104d
339339
Composition ..> OnlineOrderService : IOrderService _
340340
Composition ..> PayPalGateway : IPaymentGateway _
341341
OnlineOrderService o-- "Singleton" PayPalGateway : "PayPal" IPaymentGateway
@@ -354,7 +354,7 @@ classDiagram
354354
namespace Pure.DI.UsageTests.BCL.KeyedServiceProviderScenario {
355355
class Composition {
356356
<<partial>>
357-
-LightweightRoot LightRoot102d
357+
-LightweightRoot LightRoot104d
358358
-IPaymentGateway _
359359
-IOrderService _
360360
+ T ResolveᐸTᐳ()

readme/light-roots.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ classDiagram
437437
PrometheusMetrics --|> IMetrics
438438
AppConfiguration --|> IConfiguration
439439
ApplicationService --|> IApplicationService
440-
Composition ..> LightweightRoot : LightweightRoot LightRoot102d
440+
Composition ..> LightweightRoot : LightweightRoot LightRoot104d
441441
Composition ..> PrometheusMetrics : IMetrics _
442442
Composition ..> MemoryCache : ICache _
443443
Composition ..> ConsoleLogger : ILogger _
@@ -478,7 +478,7 @@ classDiagram
478478
<<partial>>
479479
+IApplicationService ApplicationService
480480
+IConfiguration Config
481-
-LightweightRoot LightRoot102d
481+
-LightweightRoot LightRoot104d
482482
-ILogger _
483483
-ICache _
484484
-IMetrics _

readme/request-overrides.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,21 +149,21 @@ partial class Composition
149149
[MethodImpl(MethodImplOptions.AggressiveInlining)]
150150
get
151151
{
152-
Func<Request, Handler> transientFunc658 = request =>
152+
Func<Request, Handler> transientFunc657 = request =>
153153
{
154154
// Outer override applies to the request handler and its main workflow.
155155
IRequestContext overriddenIRequestContext6 = new RequestContext(request.TenantId, request.UserId, false);
156-
Func<IRepository> transientFunc662 =
156+
Func<IRepository> transientFunc661 =
157157
[MethodImpl(MethodImplOptions.AggressiveInlining)]
158158
() =>
159159
{
160160
// Inner override applies to repository dependencies only.
161161
IRequestContext overriddenIRequestContext6 = RequestContext.System;
162162
return new Repository(overriddenIRequestContext6);
163163
};
164-
return new Handler(new Service(overriddenIRequestContext6, transientFunc662, new AuditWriter(overriddenIRequestContext6)));
164+
return new Handler(new Service(overriddenIRequestContext6, transientFunc661, new AuditWriter(overriddenIRequestContext6)));
165165
};
166-
return transientFunc658;
166+
return transientFunc657;
167167
}
168168
}
169169

readme/resolve-methods.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ classDiagram
267267
Device --|> IDevice
268268
TemperatureSensor --|> ISensor
269269
HumiditySensor --|> ISensor : "Humidity"
270-
Composition ..> LightweightRoot : LightweightRoot LightRoot102d
270+
Composition ..> LightweightRoot : LightweightRoot LightRoot104d
271271
Composition ..> HumiditySensor : ISensor HumiditySensor
272272
Composition ..> TemperatureSensor : ISensor _
273273
TemperatureSensor *-- Device : IDevice
@@ -284,7 +284,7 @@ classDiagram
284284
class Composition {
285285
<<partial>>
286286
+ISensor HumiditySensor
287-
-LightweightRoot LightRoot102d
287+
-LightweightRoot LightRoot104d
288288
-ISensor _
289289
+ T ResolveᐸTᐳ()
290290
+ T ResolveᐸTᐳ(object? tag)

0 commit comments

Comments
 (0)