Skip to content

Commit 37d7b01

Browse files
Update README
1 parent e9b84b7 commit 37d7b01

7 files changed

Lines changed: 209 additions & 47 deletions

AI_CONTEXT_LARGE.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12600,57 +12600,57 @@ Atomically generated smart tag with value "Cleaner".
1260012600
</blockquote></details>
1260112601

1260212602

12603-
<details><summary>Field CompositionClass</summary><blockquote>
12603+
<details><summary>Field UsingDeclarations</summary><blockquote>
1260412604

12605-
Atomically generated smart tag with value "CompositionClass".
12605+
Atomically generated smart tag with value "UsingDeclarations".
1260612606
It's used for:
1260712607

12608-
class _Generator__CodeBuilder_ <-- _IBuilder{TData, T}_(CompositionClass) -- _CompositionClassBuilder_ as _PerBlock_
12608+
class _Generator__CompositionClassBuilder_ <-- _IBuilder{TData, T}_(UsingDeclarations) -- _UsingDeclarationsBuilder_ as _PerBlock_
1260912609
</blockquote></details>
1261012610

1261112611

12612-
<details><summary>Field UniqueTag</summary><blockquote>
12612+
<details><summary>Field CompositionClass</summary><blockquote>
1261312613

12614-
Atomically generated smart tag with value "UniqueTag".
12614+
Atomically generated smart tag with value "CompositionClass".
1261512615
It's used for:
1261612616

12617-
class _Generator__ApiInvocationProcessor_ <-- (UniqueTag) -- _IdGenerator_ as _PerResolve__BindingBuilder_ <-- _IIdGenerator_(UniqueTag) -- _IdGenerator_ as _PerResolve_
12617+
class _Generator__CodeBuilder_ <-- _IBuilder{TData, T}_(CompositionClass) -- _CompositionClassBuilder_ as _PerBlock_
1261812618
</blockquote></details>
1261912619

1262012620

12621-
<details><summary>Field UsingDeclarations</summary><blockquote>
12621+
<details><summary>Field Overrider</summary><blockquote>
1262212622

12623-
Atomically generated smart tag with value "UsingDeclarations".
12623+
Atomically generated smart tag with value "Overrider".
1262412624
It's used for:
1262512625

12626-
class _Generator__CompositionClassBuilder_ <-- _IBuilder{TData, T}_(UsingDeclarations) -- _UsingDeclarationsBuilder_ as _PerBlock_
12626+
class _Generator__DependencyGraphBuilder_ <-- _IGraphRewriter_(Overrider) -- _GraphOverrider_ as _PerBlock_
1262712627
</blockquote></details>
1262812628

1262912629

12630-
<details><summary>Field Override</summary><blockquote>
12630+
<details><summary>Field VarName</summary><blockquote>
1263112631

12632-
Atomically generated smart tag with value "Override".
12632+
Atomically generated smart tag with value "VarName".
1263312633
It's used for:
1263412634

12635-
class _Generator__OverrideIdProvider_ <-- _IIdGenerator_(Override) -- _IdGenerator_ as _PerResolve_
12635+
class _Generator__VarsMap_ <-- _IIdGenerator_(VarName) -- _IdGenerator_ as _Transient_
1263612636
</blockquote></details>
1263712637

1263812638

12639-
<details><summary>Field VarName</summary><blockquote>
12639+
<details><summary>Field Override</summary><blockquote>
1264012640

12641-
Atomically generated smart tag with value "VarName".
12641+
Atomically generated smart tag with value "Override".
1264212642
It's used for:
1264312643

12644-
class _Generator__VarsMap_ <-- _IIdGenerator_(VarName) -- _IdGenerator_ as _Transient_
12644+
class _Generator__OverrideIdProvider_ <-- _IIdGenerator_(Override) -- _IdGenerator_ as _PerResolve_
1264512645
</blockquote></details>
1264612646

1264712647

12648-
<details><summary>Field Overrider</summary><blockquote>
12648+
<details><summary>Field UniqueTag</summary><blockquote>
1264912649

12650-
Atomically generated smart tag with value "Overrider".
12650+
Atomically generated smart tag with value "UniqueTag".
1265112651
It's used for:
1265212652

12653-
class _Generator__DependencyGraphBuilder_ <-- _IGraphRewriter_(Overrider) -- _GraphOverrider_ as _PerBlock_
12653+
class _Generator__ApiInvocationProcessor_ <-- (UniqueTag) -- _IdGenerator_ as _PerResolve__BindingBuilder_ <-- _IIdGenerator_(UniqueTag) -- _IdGenerator_ as _PerResolve_
1265412654
</blockquote></details>
1265512655

1265612656

README.md

Lines changed: 101 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ The above code specifies the generation of a partial class named *__Composition_
122122
```c#
123123
partial class Composition
124124
{
125-
private Lock _lock = new Lock();
125+
private readonly Lock _lock = new Lock();
126126
private Random? _random;
127127

128128
public Program Root
@@ -132,7 +132,7 @@ partial class Composition
132132
{
133133
var stateFunc = new Func<State>(() => {
134134
if (_random is null)
135-
using (_lock.EnterScope())
135+
lock (_lock)
136136
if (_random is null)
137137
_random = new Random();
138138

@@ -148,11 +148,92 @@ partial class Composition
148148
}
149149

150150
public T Resolve<T>() { ... }
151+
public T Resolve<T>(object? tag) { ... }
151152

152153
public object Resolve(Type type) { ... }
154+
public object Resolve(Type type, object? tag)) { ... }
153155
}
154156
```
155157

158+
<details>
159+
<summary>Class diagram</summary>
160+
161+
```mermaid
162+
classDiagram
163+
ShroedingersCat --|> ICat
164+
CardboardBoxᐸICatᐳ --|> IBoxᐸICatᐳ
165+
CardboardBoxᐸICatᐳ --|> IEquatableᐸCardboardBoxᐸICatᐳᐳ
166+
Composition ..> Program : Program Root
167+
State o-- "Singleton" Random : Random
168+
ShroedingersCat *-- LazyᐸStateᐳ : LazyᐸStateᐳ
169+
Program *-- CardboardBoxᐸICatᐳ : IBoxᐸICatᐳ
170+
CardboardBoxᐸICatᐳ *-- ShroedingersCat : ICat
171+
LazyᐸStateᐳ o-- "PerBlock" FuncᐸStateᐳ : FuncᐸStateᐳ
172+
FuncᐸStateᐳ *-- State : State
173+
174+
namespace Sample {
175+
class CardboardBoxᐸICatᐳ {
176+
<<record>>
177+
+CardboardBox(ICat Content)
178+
}
179+
180+
class Composition {
181+
<<partial>>
182+
+Program Root
183+
+ T ResolveᐸTᐳ()
184+
+ T ResolveᐸTᐳ(object? tag)
185+
+ object Resolve(Type type)
186+
+ object Resolve(Type type, object? tag)
187+
}
188+
189+
class IBoxᐸICatᐳ {
190+
<<interface>>
191+
}
192+
193+
class ICat {
194+
<<interface>>
195+
}
196+
197+
class Program {
198+
<<class>>
199+
+Program(IBoxᐸICatᐳ box)
200+
}
201+
202+
class ShroedingersCat {
203+
<<class>>
204+
+ShroedingersCat(LazyᐸStateᐳ superposition)
205+
}
206+
207+
class State {
208+
<<enum>>
209+
}
210+
}
211+
212+
namespace System {
213+
class FuncᐸStateᐳ {
214+
<<delegate>>
215+
}
216+
217+
class IEquatableᐸCardboardBoxᐸICatᐳᐳ {
218+
<<interface>>
219+
}
220+
221+
class LazyᐸStateᐳ {
222+
<<class>>
223+
}
224+
225+
class Random {
226+
<<class>>
227+
+Random()
228+
}
229+
}
230+
```
231+
232+
You can see the class diagram at any time by following the link in the comment of the generated class:
233+
![](readme/class_digram_link.png)
234+
235+
</details>
236+
156237
Obviously, this code does not depend on other libraries, does not use type reflection or any other tricks that can negatively affect performance and memory consumption. It looks like an efficient code written by hand. At any given time, you can study it and understand how it works.
157238

158239
The `public Program Root { get; }` property here is a [*__Composition Root__*](https://blog.ploeh.dk/2011/07/28/CompositionRoot/), the only place in the application where the composition of the object graph for the application takes place. Each instance is created by only basic language constructs, which compiles with all optimizations with minimal impact on performance and memory consumption. In general, applications may have multiple composition roots and thus such properties. Each composition root must have its own unique name, which is defined when the `Root<T>(string name)` method is called, as shown in the above code.
@@ -3791,57 +3872,57 @@ Atomically generated smart tag with value "Cleaner".
37913872
</blockquote></details>
37923873

37933874

3794-
<details><summary>Field CompositionClass</summary><blockquote>
3875+
<details><summary>Field UsingDeclarations</summary><blockquote>
37953876

3796-
Atomically generated smart tag with value "CompositionClass".
3877+
Atomically generated smart tag with value "UsingDeclarations".
37973878
It's used for:
37983879

3799-
class _Generator__CodeBuilder_ <-- _IBuilder{TData, T}_(CompositionClass) -- _CompositionClassBuilder_ as _PerBlock_
3880+
class _Generator__CompositionClassBuilder_ <-- _IBuilder{TData, T}_(UsingDeclarations) -- _UsingDeclarationsBuilder_ as _PerBlock_
38003881
</blockquote></details>
38013882

38023883

3803-
<details><summary>Field UniqueTag</summary><blockquote>
3884+
<details><summary>Field CompositionClass</summary><blockquote>
38043885

3805-
Atomically generated smart tag with value "UniqueTag".
3886+
Atomically generated smart tag with value "CompositionClass".
38063887
It's used for:
38073888

3808-
class _Generator__ApiInvocationProcessor_ <-- (UniqueTag) -- _IdGenerator_ as _PerResolve__BindingBuilder_ <-- _IIdGenerator_(UniqueTag) -- _IdGenerator_ as _PerResolve_
3889+
class _Generator__CodeBuilder_ <-- _IBuilder{TData, T}_(CompositionClass) -- _CompositionClassBuilder_ as _PerBlock_
38093890
</blockquote></details>
38103891

38113892

3812-
<details><summary>Field UsingDeclarations</summary><blockquote>
3893+
<details><summary>Field Overrider</summary><blockquote>
38133894

3814-
Atomically generated smart tag with value "UsingDeclarations".
3895+
Atomically generated smart tag with value "Overrider".
38153896
It's used for:
38163897

3817-
class _Generator__CompositionClassBuilder_ <-- _IBuilder{TData, T}_(UsingDeclarations) -- _UsingDeclarationsBuilder_ as _PerBlock_
3898+
class _Generator__DependencyGraphBuilder_ <-- _IGraphRewriter_(Overrider) -- _GraphOverrider_ as _PerBlock_
38183899
</blockquote></details>
38193900

38203901

3821-
<details><summary>Field Override</summary><blockquote>
3902+
<details><summary>Field VarName</summary><blockquote>
38223903

3823-
Atomically generated smart tag with value "Override".
3904+
Atomically generated smart tag with value "VarName".
38243905
It's used for:
38253906

3826-
class _Generator__OverrideIdProvider_ <-- _IIdGenerator_(Override) -- _IdGenerator_ as _PerResolve_
3907+
class _Generator__VarsMap_ <-- _IIdGenerator_(VarName) -- _IdGenerator_ as _Transient_
38273908
</blockquote></details>
38283909

38293910

3830-
<details><summary>Field VarName</summary><blockquote>
3911+
<details><summary>Field Override</summary><blockquote>
38313912

3832-
Atomically generated smart tag with value "VarName".
3913+
Atomically generated smart tag with value "Override".
38333914
It's used for:
38343915

3835-
class _Generator__VarsMap_ <-- _IIdGenerator_(VarName) -- _IdGenerator_ as _Transient_
3916+
class _Generator__OverrideIdProvider_ <-- _IIdGenerator_(Override) -- _IdGenerator_ as _PerResolve_
38363917
</blockquote></details>
38373918

38383919

3839-
<details><summary>Field Overrider</summary><blockquote>
3920+
<details><summary>Field UniqueTag</summary><blockquote>
38403921

3841-
Atomically generated smart tag with value "Overrider".
3922+
Atomically generated smart tag with value "UniqueTag".
38423923
It's used for:
38433924

3844-
class _Generator__DependencyGraphBuilder_ <-- _IGraphRewriter_(Overrider) -- _GraphOverrider_ as _PerBlock_
3925+
class _Generator__ApiInvocationProcessor_ <-- (UniqueTag) -- _IdGenerator_ as _PerResolve__BindingBuilder_ <-- _IIdGenerator_(UniqueTag) -- _IdGenerator_ as _PerResolve_
38453926
</blockquote></details>
38463927

38473928

readme/ReadmeTemplate.md

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ The above code specifies the generation of a partial class named *__Composition_
6767
```c#
6868
partial class Composition
6969
{
70-
private Lock _lock = new Lock();
70+
private readonly Lock _lock = new Lock();
7171
private Random? _random;
7272

7373
public Program Root
@@ -77,7 +77,7 @@ partial class Composition
7777
{
7878
var stateFunc = new Func<State>(() => {
7979
if (_random is null)
80-
using (_lock.EnterScope())
80+
lock (_lock)
8181
if (_random is null)
8282
_random = new Random();
8383

@@ -93,11 +93,92 @@ partial class Composition
9393
}
9494

9595
public T Resolve<T>() { ... }
96+
public T Resolve<T>(object? tag) { ... }
9697

9798
public object Resolve(Type type) { ... }
99+
public object Resolve(Type type, object? tag)) { ... }
98100
}
99101
```
100102

103+
<details>
104+
<summary>Class diagram</summary>
105+
106+
```mermaid
107+
classDiagram
108+
ShroedingersCat --|> ICat
109+
CardboardBoxᐸICatᐳ --|> IBoxᐸICatᐳ
110+
CardboardBoxᐸICatᐳ --|> IEquatableᐸCardboardBoxᐸICatᐳᐳ
111+
Composition ..> Program : Program Root
112+
State o-- "Singleton" Random : Random
113+
ShroedingersCat *-- LazyᐸStateᐳ : LazyᐸStateᐳ
114+
Program *-- CardboardBoxᐸICatᐳ : IBoxᐸICatᐳ
115+
CardboardBoxᐸICatᐳ *-- ShroedingersCat : ICat
116+
LazyᐸStateᐳ o-- "PerBlock" FuncᐸStateᐳ : FuncᐸStateᐳ
117+
FuncᐸStateᐳ *-- State : State
118+
119+
namespace Sample {
120+
class CardboardBoxᐸICatᐳ {
121+
<<record>>
122+
+CardboardBox(ICat Content)
123+
}
124+
125+
class Composition {
126+
<<partial>>
127+
+Program Root
128+
+ T ResolveᐸTᐳ()
129+
+ T ResolveᐸTᐳ(object? tag)
130+
+ object Resolve(Type type)
131+
+ object Resolve(Type type, object? tag)
132+
}
133+
134+
class IBoxᐸICatᐳ {
135+
<<interface>>
136+
}
137+
138+
class ICat {
139+
<<interface>>
140+
}
141+
142+
class Program {
143+
<<class>>
144+
+Program(IBoxᐸICatᐳ box)
145+
}
146+
147+
class ShroedingersCat {
148+
<<class>>
149+
+ShroedingersCat(LazyᐸStateᐳ superposition)
150+
}
151+
152+
class State {
153+
<<enum>>
154+
}
155+
}
156+
157+
namespace System {
158+
class FuncᐸStateᐳ {
159+
<<delegate>>
160+
}
161+
162+
class IEquatableᐸCardboardBoxᐸICatᐳᐳ {
163+
<<interface>>
164+
}
165+
166+
class LazyᐸStateᐳ {
167+
<<class>>
168+
}
169+
170+
class Random {
171+
<<class>>
172+
+Random()
173+
}
174+
}
175+
```
176+
177+
You can see the class diagram at any time by following the link in the comment of the generated class:
178+
![](readme/class_digram_link.png)
179+
180+
</details>
181+
101182
Obviously, this code does not depend on other libraries, does not use type reflection or any other tricks that can negatively affect performance and memory consumption. It looks like an efficient code written by hand. At any given time, you can study it and understand how it works.
102183

103184
The `public Program Root { get; }` property here is a [*__Composition Root__*](https://blog.ploeh.dk/2011/07/28/CompositionRoot/), the only place in the application where the composition of the object graph for the application takes place. Each instance is created by only basic language constructs, which compiles with all optimizations with minimal impact on performance and memory consumption. In general, applications may have multiple composition roots and thus such properties. Each composition root must have its own unique name, which is defined when the `Root<T>(string name)` method is called, as shown in the above code.

readme/class_digram_link.png

80.9 KB
Loading

readme/func-with-arguments.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,14 @@ partial class Composition
130130
get
131131
{
132132
Func<int, string, IDependency> blockFunc1;
133-
Func<int, string, IDependency> localFactory2 = new Func<int, string, IDependency>((int localArg1, string localArg22) =>
133+
Func<int, string, IDependency> localFactory2 = new Func<int, string, IDependency>((int localArg11, string localArg2) =>
134134
{
135135
Lock transLock2 = _lock;
136136
Lock localLockObject2 = transLock2;
137137
lock (localLockObject2)
138138
{
139-
int overrInt32 = localArg1;
140-
string overrString2 = localArg22;
139+
int overrInt32 = localArg11;
140+
string overrString2 = localArg2;
141141
if (_root._singleClock52 is null)
142142
lock (_lock)
143143
if (_root._singleClock52 is null)

0 commit comments

Comments
 (0)