Skip to content

Commit 1713ff3

Browse files
Support for multiple hints
1 parent 7e51e70 commit 1713ff3

File tree

11 files changed

+21
-16
lines changed

11 files changed

+21
-16
lines changed

readme/global-compositions.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ class MyGlobalComposition2
2323
{
2424
static void Setup() =>
2525
DI.Setup("Some name", kind: Global)
26-
.Hint(Hint.OnCannotResolve, "Off")
27-
.Hint(Hint.OnCannotResolvePartial, "On")
28-
.Hint(Hint.OnNewRoot, "Off")
29-
.Hint(Hint.OnNewRootPartial, "On")
3026
.Hint(Hint.ToString, "On");
3127
}
3228
```

readme/service-collection.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ partial class Composition : ServiceProviderFactory<Composition>
3838
CreateServiceCollection(this);
3939

4040
static void Setup() =>
41-
4241
DI.Setup()
42+
.DependsOn(Base)
4343
.Bind<IDependency>("Dependency Key").As(Lifetime.Singleton).To<Dependency>()
4444
.Bind<IService>().To<Service>()
4545
.Root<IDependency>(tag: "Dependency Key")

samples/BlazorServerApp/Composition.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ namespace BlazorServerApp;
1414
internal partial class Composition : ServiceProviderFactory<Composition>
1515
{
1616
void Setup() => DI.Setup()
17+
.DependsOn(Base)
1718
// View Models
1819
.Bind().To<ClockViewModel>()
1920
// Provides the composition root for Clock view model

samples/BlazorWebAssemblyApp/Composition.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace BlazorWebAssemblyApp;
1313
internal partial class Composition : ServiceProviderFactory<Composition>
1414
{
1515
void Setup() => DI.Setup()
16+
.DependsOn(Base)
1617
// View Models
1718
.Bind().As(Singleton).To<ClockViewModel>()
1819
// Provides the composition root for Clock view model

samples/GrpcService/Composition.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace GrpcService;
1010
internal partial class Composition : ServiceProviderFactory<Composition>
1111
{
1212
static void Setup() => DI.Setup()
13+
.DependsOn(Base)
1314
// Provides the composition root for Greeter service
1415
.Root<GreeterService>();
1516
}

samples/MinimalWebAPI/Composition.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace MinimalWebAPI;
1111
internal partial class Composition : ServiceProviderFactory<Composition>
1212
{
1313
void Setup() => DI.Setup()
14+
.DependsOn(Base)
1415
.Bind().As(Singleton).To<WeatherForecastService>()
1516
.Root<IWeatherForecastService>()
1617

samples/WebAPI/Composition.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ namespace WebAPI;
1212
internal partial class Composition : ServiceProviderFactory<Composition>
1313
{
1414
static void Setup() => DI.Setup()
15+
.DependsOn(Base)
1516
.Bind().As(Singleton).To<WeatherForecastService>()
1617
// Provides the composition root for Weather Forecast controller
1718
.Root<WeatherForecastController>();

samples/WebApp/Composition.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ namespace WebApp;
1212
internal partial class Composition : ServiceProviderFactory<Composition>
1313
{
1414
static void Setup() => DI.Setup()
15+
.DependsOn(Base)
1516
.Bind().As(Singleton).To<WeatherForecastService>()
1617
// Provides the composition root for Home controller
1718
.Root<HomeController>();

src/Pure.DI.MS/any/Pure.DI/MS/ServiceProviderFactory.g.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@ public class ServiceProviderFactory<TComposition>: IServiceProviderFactory<IServ
3636
private static readonly ParameterExpression TypeParameter = Expression.Parameter(typeof(Type));
3737
private static readonly ParameterExpression TagParameter = Expression.Parameter(typeof(object));
3838

39+
/// <summary>
40+
/// The name of the Pure.DI setup to use as a dependency in other setups.
41+
/// <example>
42+
/// For example:
43+
/// <code>
44+
/// void Setup() =&amp;gt;
45+
/// DI.Setup(nameof(Composition)).DependsOn(Base);
46+
/// </code>
47+
/// </example>
48+
/// </summary>
49+
protected const string Base = "Pure.DI.MS.ServiceProviderFactory";
50+
3951
/// <summary>
4052
/// An instance of <see cref="Pure.DI.MS.ServiceCollectionFactory"/>.
4153
/// </summary>
@@ -51,7 +63,7 @@ public class ServiceProviderFactory<TComposition>: IServiceProviderFactory<IServ
5163
/// </summary>
5264
[global::System.Diagnostics.Conditional("A2768DE22DE3E430C9653990D516CC9B")]
5365
private static void HintsSetup() =>
54-
global::Pure.DI.DI.Setup("", global::Pure.DI.CompositionKind.Global)
66+
global::Pure.DI.DI.Setup(Base, global::Pure.DI.CompositionKind.Internal)
5567
.Hint(global::Pure.DI.Hint.OnCannotResolve, "On")
5668
.Hint(global::Pure.DI.Hint.OnCannotResolvePartial, "Off")
5769
.Hint(global::Pure.DI.Hint.OnNewRoot, "On")

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ class MyGlobalComposition2
3535
{
3636
static void Setup() =>
3737
DI.Setup("Some name", kind: Global)
38-
.Hint(Hint.OnCannotResolve, "Off")
39-
.Hint(Hint.OnCannotResolvePartial, "On")
40-
.Hint(Hint.OnNewRoot, "Off")
41-
.Hint(Hint.OnNewRootPartial, "On")
4238
.Hint(Hint.ToString, "On");
4339
}
4440
// }

0 commit comments

Comments
 (0)