Skip to content

Commit d5a7db9

Browse files
#115 Improve API of using ServiceProviderFactory base class for Microsoft DI integration - get rid of the DependsOn("Base")
1 parent d91b726 commit d5a7db9

10 files changed

Lines changed: 134 additions & 33 deletions

File tree

AI_CONTEXT_LARGE.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12739,21 +12739,21 @@ Atomically generated smart tag with value "VarName".
1273912739
</blockquote></details>
1274012740

1274112741

12742-
<details><summary>Field Cleaner</summary><blockquote>
12742+
<details><summary>Field UsingDeclarations</summary><blockquote>
1274312743

12744-
Atomically generated smart tag with value "Cleaner".
12744+
Atomically generated smart tag with value "UsingDeclarations".
1274512745
It's used for:
1274612746

12747-
class _Generator__DependencyGraphBuilder_ <-- _IGraphRewriter_(Cleaner) -- _GraphCleaner_ as _PerBlock_
12747+
class _Generator__CompositionClassBuilder_ <-- _IBuilder{TData, T}_(UsingDeclarations) -- _UsingDeclarationsBuilder_ as _PerBlock_
1274812748
</blockquote></details>
1274912749

1275012750

12751-
<details><summary>Field UsingDeclarations</summary><blockquote>
12751+
<details><summary>Field Override</summary><blockquote>
1275212752

12753-
Atomically generated smart tag with value "UsingDeclarations".
12753+
Atomically generated smart tag with value "Override".
1275412754
It's used for:
1275512755

12756-
class _Generator__CompositionClassBuilder_ <-- _IBuilder{TData, T}_(UsingDeclarations) -- _UsingDeclarationsBuilder_ as _PerBlock_
12756+
class _Generator__OverrideIdProvider_ <-- _IIdGenerator_(Override) -- _IdGenerator_ as _PerResolve_
1275712757
</blockquote></details>
1275812758

1275912759

@@ -12766,12 +12766,12 @@ Atomically generated smart tag with value "Overrider".
1276612766
</blockquote></details>
1276712767

1276812768

12769-
<details><summary>Field Override</summary><blockquote>
12769+
<details><summary>Field Cleaner</summary><blockquote>
1277012770

12771-
Atomically generated smart tag with value "Override".
12771+
Atomically generated smart tag with value "Cleaner".
1277212772
It's used for:
1277312773

12774-
class _Generator__OverrideIdProvider_ <-- _IIdGenerator_(Override) -- _IdGenerator_ as _PerResolve_
12774+
class _Generator__DependencyGraphBuilder_ <-- _IGraphRewriter_(Cleaner) -- _GraphCleaner_ as _PerBlock_
1277512775
</blockquote></details>
1277612776

1277712777

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3881,21 +3881,21 @@ Atomically generated smart tag with value "VarName".
38813881
</blockquote></details>
38823882

38833883

3884-
<details><summary>Field Cleaner</summary><blockquote>
3884+
<details><summary>Field UsingDeclarations</summary><blockquote>
38853885

3886-
Atomically generated smart tag with value "Cleaner".
3886+
Atomically generated smart tag with value "UsingDeclarations".
38873887
It's used for:
38883888

3889-
class _Generator__DependencyGraphBuilder_ <-- _IGraphRewriter_(Cleaner) -- _GraphCleaner_ as _PerBlock_
3889+
class _Generator__CompositionClassBuilder_ <-- _IBuilder{TData, T}_(UsingDeclarations) -- _UsingDeclarationsBuilder_ as _PerBlock_
38903890
</blockquote></details>
38913891

38923892

3893-
<details><summary>Field UsingDeclarations</summary><blockquote>
3893+
<details><summary>Field Override</summary><blockquote>
38943894

3895-
Atomically generated smart tag with value "UsingDeclarations".
3895+
Atomically generated smart tag with value "Override".
38963896
It's used for:
38973897

3898-
class _Generator__CompositionClassBuilder_ <-- _IBuilder{TData, T}_(UsingDeclarations) -- _UsingDeclarationsBuilder_ as _PerBlock_
3898+
class _Generator__OverrideIdProvider_ <-- _IIdGenerator_(Override) -- _IdGenerator_ as _PerResolve_
38993899
</blockquote></details>
39003900

39013901

@@ -3908,12 +3908,12 @@ Atomically generated smart tag with value "Overrider".
39083908
</blockquote></details>
39093909

39103910

3911-
<details><summary>Field Override</summary><blockquote>
3911+
<details><summary>Field Cleaner</summary><blockquote>
39123912

3913-
Atomically generated smart tag with value "Override".
3913+
Atomically generated smart tag with value "Cleaner".
39143914
It's used for:
39153915

3916-
class _Generator__OverrideIdProvider_ <-- _IIdGenerator_(Override) -- _IdGenerator_ as _PerResolve_
3916+
class _Generator__DependencyGraphBuilder_ <-- _IGraphRewriter_(Cleaner) -- _GraphCleaner_ as _PerBlock_
39173917
</blockquote></details>
39183918

39193919

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 localArg16, string localArg23) =>
133+
Func<int, string, IDependency> localFactory2 = new Func<int, string, IDependency>((int localArg11, string localArg24) =>
134134
{
135135
Lock transLock2 = _lock;
136136
Lock localLockObject2 = transLock2;
137137
lock (localLockObject2)
138138
{
139-
int overrInt32 = localArg16;
140-
string overrString2 = localArg23;
139+
int overrInt32 = localArg11;
140+
string overrString2 = localArg24;
141141
if (_root._singleClock52 is null)
142142
lock (_lock)
143143
if (_root._singleClock52 is null)

readme/generic-injections-as-required-with-arguments.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,13 @@ partial class Composition
104104
get
105105
{
106106
Func<int, IDependency<string>> blockFunc1;
107-
Func<int, IDependency<string>> localFactory8 = new Func<int, IDependency<string>>((int localArg1) =>
107+
Func<int, IDependency<string>> localFactory8 = new Func<int, IDependency<string>>((int localArg14) =>
108108
{
109109
Lock transLock2 = _lock;
110110
Lock localLockObject3 = transLock2;
111111
lock (localLockObject3)
112112
{
113-
int overrInt32 = localArg1;
113+
int overrInt32 = localArg14;
114114
IDependency<string> localValue28 = new Dependency<string>(overrInt32);
115115
return localValue28;
116116
}

readme/injections-on-demand-with-arguments.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,13 @@ partial class Composition
116116
get
117117
{
118118
Func<int, IDependency> blockFunc1;
119-
Func<int, IDependency> localFactory1 = new Func<int, IDependency>((int localArg1) =>
119+
Func<int, IDependency> localFactory1 = new Func<int, IDependency>((int localArg14) =>
120120
{
121121
Lock transLock2 = _lock;
122122
Lock localLockObject1 = transLock2;
123123
lock (localLockObject1)
124124
{
125-
int overrInt32 = localArg1;
125+
int overrInt32 = localArg14;
126126
IDependency localValue17 = new Dependency(overrInt32);
127127
return localValue17;
128128
}

src/Pure.DI.Core/Core/ApiInvocationProcessor.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,10 @@ MemberAccessExpressionSyntax memberAccess when memberAccess.Kind() == SyntaxKind
183183
if (baseType?.BaseList is { Types.Count: > 0 }
184184
&& semanticModel.GetDeclaredSymbol(baseType) is { BaseType: {} derivedTyeSymbol })
185185
{
186-
var compositionName = new CompositionName(derivedTyeSymbol.Name, derivedTyeSymbol.ContainingNamespace.ToString(), baseType);
186+
var compositionName = new CompositionName(
187+
derivedTyeSymbol.Name,
188+
derivedTyeSymbol.ContainingNamespace.IsGlobalNamespace ? "" : derivedTyeSymbol.ContainingNamespace.ToString(),
189+
baseType);
187190
metadataVisitor.VisitDependsOn(
188191
new MdDependsOn(
189192
semanticModel,

src/Pure.DI.Core/Core/Code/ClassDiagramBuilder.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,9 +332,7 @@ private string ResolveTypeName(MdSetup setup, ITypeSymbol typeSymbol)
332332
}
333333

334334
private static string ResolveNamespaceName(INamespaceSymbol? namespaceSymbol) =>
335-
namespaceSymbol == null || namespaceSymbol.IsGlobalNamespace
336-
? ""
337-
: namespaceSymbol.ToDisplayString();
335+
namespaceSymbol == null || namespaceSymbol.IsGlobalNamespace ? "" : namespaceSymbol.ToDisplayString();
338336

339337
private static string Format(Accessibility accessibility) =>
340338
accessibility switch

src/Pure.DI.Core/Core/SetupsBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ where attribute.AttributeClass is {} attributeClass
359359
MdResolver CreateResolver(ITypeConstructor constructor, string name, ITypeSymbol injectedType, object? tag, ref int curPosition)
360360
{
361361
var typeSyntax = SyntaxFactory.ParseTypeName(symbolNames.GetGlobalName(injectedType));
362-
if (semantic.IsValidNamespace(injectedType.ContainingNamespace))
362+
if (!injectedType.ContainingNamespace.IsGlobalNamespace && semantic.IsValidNamespace(injectedType.ContainingNamespace))
363363
{
364364
namespaces.Add(injectedType.ContainingNamespace.ToString());
365365
}

tests/Pure.DI.IntegrationTests/SetupTests.cs

Lines changed: 102 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,7 +1093,7 @@ namespace Sample
10931093
{
10941094
class SetupBase
10951095
{
1096-
private static void SetupBaseComposition1()
1096+
private static void SetupBaseComposition()
10971097
{
10981098
DI.Setup("RootNamespace.Sample.SetupBase", CompositionKind.Internal)
10991099
.Bind<int>().To(_ => 1);
@@ -1140,7 +1140,7 @@ namespace Sample
11401140
{
11411141
class SetupBase
11421142
{
1143-
private static void SetupBaseComposition1()
1143+
private static void SetupBaseComposition()
11441144
{
11451145
DI.Setup(kind: CompositionKind.Internal)
11461146
.Bind<int>().To(_ => 1);
@@ -1172,6 +1172,106 @@ public static void Main()
11721172
result.StdOut.ShouldBe(["1"], result);
11731173
}
11741174

1175+
[Fact]
1176+
public async Task ShouldSupportInheritanceOfCompositions()
1177+
{
1178+
// Given
1179+
1180+
// When
1181+
var result = await """
1182+
using System;
1183+
using Pure.DI;
1184+
1185+
namespace Sample
1186+
{
1187+
class SetupBase
1188+
{
1189+
private static void SetupBaseComposition()
1190+
{
1191+
DI.Setup(kind: CompositionKind.Internal)
1192+
.Bind<int>().To(_ => 1);
1193+
}
1194+
}
1195+
1196+
class SetupBase2: SetupBase
1197+
{
1198+
private static void SetupBaseComposition()
1199+
{
1200+
DI.Setup(kind: CompositionKind.Internal)
1201+
.Bind<string>().To(_ => "Abc");
1202+
}
1203+
}
1204+
1205+
partial class Setup: SetupBase2
1206+
{
1207+
private static void SetupComposition()
1208+
{
1209+
DI.Setup("Composition")
1210+
.Root<int>("Root")
1211+
.Root<string>("Root2");
1212+
}
1213+
}
1214+
1215+
public class Program
1216+
{
1217+
public static void Main()
1218+
{
1219+
var composition = new Composition();
1220+
Console.WriteLine(composition.Root);
1221+
Console.WriteLine(composition.Root2);
1222+
}
1223+
}
1224+
}
1225+
""".RunAsync();
1226+
1227+
// Then
1228+
result.Success.ShouldBeTrue(result);
1229+
result.StdOut.ShouldBe(["1", "Abc"], result);
1230+
}
1231+
1232+
[Fact]
1233+
public async Task ShouldSupportDependsOnBaseClassWhenDefaultNameAndHasNoNamespace()
1234+
{
1235+
// Given
1236+
1237+
// When
1238+
var result = await """
1239+
using System;
1240+
using Pure.DI;
1241+
1242+
class SetupBase
1243+
{
1244+
private static void SetupBaseComposition()
1245+
{
1246+
DI.Setup(kind: CompositionKind.Internal)
1247+
.Bind<int>().To(_ => 1);
1248+
}
1249+
}
1250+
1251+
partial class Setup: SetupBase
1252+
{
1253+
private static void SetupComposition()
1254+
{
1255+
DI.Setup("Composition")
1256+
.Root<int>("Root");
1257+
}
1258+
}
1259+
1260+
public class Program
1261+
{
1262+
public static void Main()
1263+
{
1264+
var composition = new Composition();
1265+
Console.WriteLine(composition.Root);
1266+
}
1267+
}
1268+
""".RunAsync();
1269+
1270+
// Then
1271+
result.Success.ShouldBeTrue(result);
1272+
result.StdOut.ShouldBe(["1"], result);
1273+
}
1274+
11751275
#if ROSLYN4_8_OR_GREATER
11761276
[Fact]
11771277
public async Task ShouldSupportMultipleBaseCompositions()

tests/Pure.DI.UsageTests/Advanced/InheritanceOfCompositionsScenario.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
// ReSharper disable UnusedParameter.Local
1010
// ReSharper disable RedundantAssignment
1111
// ReSharper disable ArrangeTypeModifiers
12-
1312
// ReSharper disable PartialTypeWithSinglePart
13+
// ReSharper disable UnusedMember.Local
1414
#pragma warning disable CS9113 // Parameter is unread.
1515
namespace Pure.DI.UsageTests.Advanced.InheritanceOfCompositionsScenario;
1616

0 commit comments

Comments
 (0)