Skip to content

Commit

Permalink
Supports the arguments of the root of the composition.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikolay Pyanikov committed Aug 8, 2023
1 parent 09f95c9 commit ecef2d4
Show file tree
Hide file tree
Showing 85 changed files with 2,321 additions and 1,828 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ dotnet run
- [Injection](readme/injection.md)
- [Generics](readme/generics.md)
- [Arguments](readme/arguments.md)
- [Root arguments](readme/root-arguments.md)
- [Tags](readme/tags.md)
- [Auto-bindings](readme/auto-bindings.md)
- [Child composition](readme/child-composition.md)
Expand Down Expand Up @@ -391,7 +392,7 @@ The child composition inherits the state of the parent composition in the form o

### Public Composition Roots

To create an object graph quickly and conveniently, a set of properties is formed. These properties are here called roots of compositions. The type of a property is the type of the root object created by the composition. Accordingly, each invocation of a property leads to the creation of a composition with a root element of this type.
To create an object graph quickly and conveniently, a set of properties (or a methods) is formed. These properties are here called roots of compositions. The type of a property/method is the type of the root object created by the composition. Accordingly, each invocation of a property/method leads to the creation of a composition with a root element of this type.

```c#
DI.Setup("Composition")
Expand Down Expand Up @@ -454,7 +455,7 @@ public object Resolve(Type type) { ... }
public object Resolve(Type type, object? tag) { ... }
```

These methods can resolve both public and private composition roots, and are useful when using the [Service Locator](https://martinfowler.com/articles/injection.html) approach, where the code resolves composition roots in place:
These methods can resolve both public and private composition roots that do not depend on any arguments of the composition roots. They are useful when using the [Service Locator](https://martinfowler.com/articles/injection.html) approach, where the code resolves composition roots in place:

```c#
var composition = new Composition();
Expand Down
8 changes: 5 additions & 3 deletions build/PackTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,16 @@ private string CreatePackage(NuGetVersion packageVersion, CodeAnalysis codeAnaly

var props = new[]
{
("configuration", _settings.Configuration),
("version", packageVersion.ToString()),
("AnalyzerRoslynVersion", analyzerRoslynVersion.ToString()),
("AnalyzerRoslynPackageVersion", analyzerRoslynPackageVersion.ToString())
};

var build = new DotNetBuild()
.WithProps(props)
.WithConfiguration(_settings.Configuration);
var build = new MSBuild()
.WithTarget("clean;rebuild")
.WithRestore(true)
.WithProps(props);

var buildResult = build.Build();
Assertion.Succeed(buildResult);
Expand Down
1 change: 1 addition & 0 deletions build/ReadmeTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ private static async Task AddContent(string sourceFile, TextWriter readmeWriter,
.GroupBy(i => i[TitleKey])
.OrderBy(i => groups.TryGetValue(i.Key, out var index) ? index : int.MaxValue)
.Select(i => (GroupName: i.Key, SampleItems: i.OrderBy(j => int.Parse(j[PriorityKey])).ThenBy(j => j[DescriptionKey]).ToArray()));

return examples;
}

Expand Down
168 changes: 84 additions & 84 deletions readme/ArrayDetails.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@ classDiagram
class IService3 {
<<abstract>>
}
ArrayᐸIService3ᐳ *-- Service3 :
ArrayᐸIService3ᐳ *-- Service3v2 : 2
ArrayᐸIService3ᐳ *-- Service3v3 : 3
ArrayᐸIService3ᐳ *-- Service3v4 : 4
CompositionRoot *-- Service1 : IService1 service1
CompositionRoot *-- Service2Array : IService2 service21
CompositionRoot *-- Service2Array : IService2 service22
CompositionRoot *-- Service2Array : IService2 service23
CompositionRoot *-- Service3 : IService3 service3
Service1 *-- Service2Array : IService2 service2
Service2Array *-- ArrayᐸIService3ᐳ : ArrayᐸIService3ᐳ services
ArrayᐸIService3ᐳ *-- Service3 : IService3
ArrayᐸIService3ᐳ *-- Service3v2 : 2 IService3
ArrayᐸIService3ᐳ *-- Service3v3 : 3 IService3
ArrayᐸIService3ᐳ *-- Service3v4 : 4 IService3
CompositionRoot *-- Service1 : IService1
CompositionRoot *-- Service2Array : IService2
CompositionRoot *-- Service2Array : IService2
CompositionRoot *-- Service2Array : IService2
CompositionRoot *-- Service3 : IService3
Service1 *-- Service2Array : IService2
Service2Array *-- ArrayᐸIService3ᐳ : ArrayᐸIService3ᐳ
Array ..> CompositionRoot : ICompositionRoot Root
```

Expand All @@ -89,58 +89,58 @@ partial class Array
[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x300)]
get
{
var transientM08D05di23 = new Pure.DI.Benchmarks.Model.Service3();
var transientM08D05di24 = new Pure.DI.Benchmarks.Model.Service3v2();
var transientM08D05di25 = new Pure.DI.Benchmarks.Model.Service3v3();
var transientM08D05di26 = new Pure.DI.Benchmarks.Model.Service3v4();
var transientM08D05di22 = new Pure.DI.Benchmarks.Model.IService3[4]
var transientM08D08di23 = new Pure.DI.Benchmarks.Model.Service3();
var transientM08D08di24 = new Pure.DI.Benchmarks.Model.Service3v2();
var transientM08D08di25 = new Pure.DI.Benchmarks.Model.Service3v3();
var transientM08D08di26 = new Pure.DI.Benchmarks.Model.Service3v4();
var transientM08D08di22 = new Pure.DI.Benchmarks.Model.IService3[4]
{
transientM08D05di23,
transientM08D05di24,
transientM08D05di25,
transientM08D05di26
transientM08D08di23,
transientM08D08di24,
transientM08D08di25,
transientM08D08di26
};
var transientM08D05di21 = new Pure.DI.Benchmarks.Model.Service2Array(transientM08D05di22);
var transientM08D05di1 = new Pure.DI.Benchmarks.Model.Service1(transientM08D05di21);
var transientM08D05di17 = new Pure.DI.Benchmarks.Model.Service3();
var transientM08D05di18 = new Pure.DI.Benchmarks.Model.Service3v2();
var transientM08D05di19 = new Pure.DI.Benchmarks.Model.Service3v3();
var transientM08D05di20 = new Pure.DI.Benchmarks.Model.Service3v4();
var transientM08D05di16 = new Pure.DI.Benchmarks.Model.IService3[4]
var transientM08D08di21 = new Pure.DI.Benchmarks.Model.Service2Array(transientM08D08di22);
var transientM08D08di1 = new Pure.DI.Benchmarks.Model.Service1(transientM08D08di21);
var transientM08D08di17 = new Pure.DI.Benchmarks.Model.Service3();
var transientM08D08di18 = new Pure.DI.Benchmarks.Model.Service3v2();
var transientM08D08di19 = new Pure.DI.Benchmarks.Model.Service3v3();
var transientM08D08di20 = new Pure.DI.Benchmarks.Model.Service3v4();
var transientM08D08di16 = new Pure.DI.Benchmarks.Model.IService3[4]
{
transientM08D05di17,
transientM08D05di18,
transientM08D05di19,
transientM08D05di20
transientM08D08di17,
transientM08D08di18,
transientM08D08di19,
transientM08D08di20
};
var transientM08D05di2 = new Pure.DI.Benchmarks.Model.Service2Array(transientM08D05di16);
var transientM08D05di12 = new Pure.DI.Benchmarks.Model.Service3();
var transientM08D05di13 = new Pure.DI.Benchmarks.Model.Service3v2();
var transientM08D05di14 = new Pure.DI.Benchmarks.Model.Service3v3();
var transientM08D05di15 = new Pure.DI.Benchmarks.Model.Service3v4();
var transientM08D05di11 = new Pure.DI.Benchmarks.Model.IService3[4]
var transientM08D08di2 = new Pure.DI.Benchmarks.Model.Service2Array(transientM08D08di16);
var transientM08D08di12 = new Pure.DI.Benchmarks.Model.Service3();
var transientM08D08di13 = new Pure.DI.Benchmarks.Model.Service3v2();
var transientM08D08di14 = new Pure.DI.Benchmarks.Model.Service3v3();
var transientM08D08di15 = new Pure.DI.Benchmarks.Model.Service3v4();
var transientM08D08di11 = new Pure.DI.Benchmarks.Model.IService3[4]
{
transientM08D05di12,
transientM08D05di13,
transientM08D05di14,
transientM08D05di15
transientM08D08di12,
transientM08D08di13,
transientM08D08di14,
transientM08D08di15
};
var transientM08D05di3 = new Pure.DI.Benchmarks.Model.Service2Array(transientM08D05di11);
var transientM08D05di7 = new Pure.DI.Benchmarks.Model.Service3();
var transientM08D05di8 = new Pure.DI.Benchmarks.Model.Service3v2();
var transientM08D05di9 = new Pure.DI.Benchmarks.Model.Service3v3();
var transientM08D05di10 = new Pure.DI.Benchmarks.Model.Service3v4();
var transientM08D05di6 = new Pure.DI.Benchmarks.Model.IService3[4]
var transientM08D08di3 = new Pure.DI.Benchmarks.Model.Service2Array(transientM08D08di11);
var transientM08D08di7 = new Pure.DI.Benchmarks.Model.Service3();
var transientM08D08di8 = new Pure.DI.Benchmarks.Model.Service3v2();
var transientM08D08di9 = new Pure.DI.Benchmarks.Model.Service3v3();
var transientM08D08di10 = new Pure.DI.Benchmarks.Model.Service3v4();
var transientM08D08di6 = new Pure.DI.Benchmarks.Model.IService3[4]
{
transientM08D05di7,
transientM08D05di8,
transientM08D05di9,
transientM08D05di10
transientM08D08di7,
transientM08D08di8,
transientM08D08di9,
transientM08D08di10
};
var transientM08D05di4 = new Pure.DI.Benchmarks.Model.Service2Array(transientM08D05di6);
var transientM08D05di5 = new Pure.DI.Benchmarks.Model.Service3();
var transientM08D05di0 = new Pure.DI.Benchmarks.Model.CompositionRoot(transientM08D05di1, transientM08D05di4, transientM08D05di3, transientM08D05di2, transientM08D05di5);
return transientM08D05di0;
var transientM08D08di4 = new Pure.DI.Benchmarks.Model.Service2Array(transientM08D08di6);
var transientM08D08di5 = new Pure.DI.Benchmarks.Model.Service3();
var transientM08D08di0 = new Pure.DI.Benchmarks.Model.CompositionRoot(transientM08D08di1, transientM08D08di4, transientM08D08di3, transientM08D08di2, transientM08D08di5);
return transientM08D08di0;
}
}
#endregion
Expand All @@ -152,7 +152,7 @@ partial class Array
[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x300)]
public T Resolve<T>()
{
return ResolverM08D05di<T>.Value.Resolve(this);
return ResolverM08D08di<T>.Value.Resolve(this);
}

#if NETSTANDARD2_0_OR_GREATER || NETCOREAPP || NET40_OR_GREATER
Expand All @@ -161,7 +161,7 @@ partial class Array
[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x300)]
public T Resolve<T>(object? tag)
{
return ResolverM08D05di<T>.Value.ResolveByTag(this, tag);
return ResolverM08D08di<T>.Value.ResolveByTag(this, tag);
}

#if NETSTANDARD2_0_OR_GREATER || NETCOREAPP || NET40_OR_GREATER
Expand All @@ -170,10 +170,10 @@ partial class Array
[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x300)]
public object Resolve(global::System.Type type)
{
var index = (int)(_bucketSizeM08D05di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1));
var finish = index + _bucketSizeM08D05di;
var index = (int)(_bucketSizeM08D08di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1));
var finish = index + _bucketSizeM08D08di;
do {
ref var pair = ref _bucketsM08D05di[index];
ref var pair = ref _bucketsM08D08di[index];
if (ReferenceEquals(pair.Key, type))
{
return pair.Value.Resolve(this);
Expand All @@ -189,10 +189,10 @@ partial class Array
[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x300)]
public object Resolve(global::System.Type type, object? tag)
{
var index = (int)(_bucketSizeM08D05di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1));
var finish = index + _bucketSizeM08D05di;
var index = (int)(_bucketSizeM08D08di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1));
var finish = index + _bucketSizeM08D08di;
do {
ref var pair = ref _bucketsM08D05di[index];
ref var pair = ref _bucketsM08D08di[index];
if (ReferenceEquals(pair.Key, type))
{
return pair.Value.ResolveByTag(this, tag);
Expand Down Expand Up @@ -255,40 +255,40 @@ partial class Array
" class IService3 {\n" +
" <<abstract>>\n" +
" }\n" +
" ArrayᐸIService3ᐳ *-- Service3 : \n" +
" ArrayᐸIService3ᐳ *-- Service3v2 : 2 \n" +
" ArrayᐸIService3ᐳ *-- Service3v3 : 3 \n" +
" ArrayᐸIService3ᐳ *-- Service3v4 : 4 \n" +
" CompositionRoot *-- Service1 : IService1 service1\n" +
" CompositionRoot *-- Service2Array : IService2 service21\n" +
" CompositionRoot *-- Service2Array : IService2 service22\n" +
" CompositionRoot *-- Service2Array : IService2 service23\n" +
" CompositionRoot *-- Service3 : IService3 service3\n" +
" Service1 *-- Service2Array : IService2 service2\n" +
" Service2Array *-- ArrayᐸIService3ᐳ : ArrayᐸIService3ᐳ services\n" +
" ArrayᐸIService3ᐳ *-- Service3 : IService3\n" +
" ArrayᐸIService3ᐳ *-- Service3v2 : 2 IService3\n" +
" ArrayᐸIService3ᐳ *-- Service3v3 : 3 IService3\n" +
" ArrayᐸIService3ᐳ *-- Service3v4 : 4 IService3\n" +
" CompositionRoot *-- Service1 : IService1\n" +
" CompositionRoot *-- Service2Array : IService2\n" +
" CompositionRoot *-- Service2Array : IService2\n" +
" CompositionRoot *-- Service2Array : IService2\n" +
" CompositionRoot *-- Service3 : IService3\n" +
" Service1 *-- Service2Array : IService2\n" +
" Service2Array *-- ArrayᐸIService3ᐳ : ArrayᐸIService3ᐳ\n" +
" Array ..> CompositionRoot : ICompositionRoot Root";
}

private readonly static int _bucketSizeM08D05di;
private readonly static global::Pure.DI.Pair<global::System.Type, global::Pure.DI.IResolver<Array, object>>[] _bucketsM08D05di;
private readonly static int _bucketSizeM08D08di;
private readonly static global::Pure.DI.Pair<global::System.Type, global::Pure.DI.IResolver<Array, object>>[] _bucketsM08D08di;

static Array()
{
var valResolverM08D05di_0000 = new ResolverM08D05di_0000();
ResolverM08D05di<Pure.DI.Benchmarks.Model.ICompositionRoot>.Value = valResolverM08D05di_0000;
_bucketsM08D05di = global::Pure.DI.Buckets<global::System.Type, global::Pure.DI.IResolver<Array, object>>.Create(
var valResolverM08D08di_0000 = new ResolverM08D08di_0000();
ResolverM08D08di<Pure.DI.Benchmarks.Model.ICompositionRoot>.Value = valResolverM08D08di_0000;
_bucketsM08D08di = global::Pure.DI.Buckets<global::System.Type, global::Pure.DI.IResolver<Array, object>>.Create(
1,
out _bucketSizeM08D05di,
out _bucketSizeM08D08di,
new global::Pure.DI.Pair<global::System.Type, global::Pure.DI.IResolver<Array, object>>[1]
{
new global::Pure.DI.Pair<global::System.Type, global::Pure.DI.IResolver<Array, object>>(typeof(Pure.DI.Benchmarks.Model.ICompositionRoot), valResolverM08D05di_0000)
new global::Pure.DI.Pair<global::System.Type, global::Pure.DI.IResolver<Array, object>>(typeof(Pure.DI.Benchmarks.Model.ICompositionRoot), valResolverM08D08di_0000)
});
}

#region Resolvers
private sealed class ResolverM08D05di<T>: global::Pure.DI.IResolver<Array, T>
private sealed class ResolverM08D08di<T>: global::Pure.DI.IResolver<Array, T>
{
public static global::Pure.DI.IResolver<Array, T> Value = new ResolverM08D05di<T>();
public static global::Pure.DI.IResolver<Array, T> Value = new ResolverM08D08di<T>();

public T Resolve(Array composite)
{
Expand All @@ -301,7 +301,7 @@ partial class Array
}
}

private sealed class ResolverM08D05di_0000: global::Pure.DI.IResolver<Array, Pure.DI.Benchmarks.Model.ICompositionRoot>
private sealed class ResolverM08D08di_0000: global::Pure.DI.IResolver<Array, Pure.DI.Benchmarks.Model.ICompositionRoot>
{
[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x300)]
public Pure.DI.Benchmarks.Model.ICompositionRoot Resolve(Array composition)
Expand Down
2 changes: 1 addition & 1 deletion readme/Console.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ The [project file](/samples/ShroedingersCat/ShroedingersCat.csproj) looks like t
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Pure.DI" Version="2.0.9">
<PackageReference Include="Pure.DI" Version="2.0.11">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion readme/ConsoleTopLevelStatements.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ The [project file](/samples/ShroedingersCatTopLevelStatements/ShroedingersCatTop
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Pure.DI" Version="2.0.9">
<PackageReference Include="Pure.DI" Version="2.0.11">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Loading

0 comments on commit ecef2d4

Please sign in to comment.