Skip to content

Commit

Permalink
Support for multiple hints
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolayPianikov committed Jan 22, 2025
1 parent 7e51e70 commit 1713ff3
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 16 deletions.
4 changes: 0 additions & 4 deletions readme/global-compositions.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ class MyGlobalComposition2
{
static void Setup() =>
DI.Setup("Some name", kind: Global)
.Hint(Hint.OnCannotResolve, "Off")
.Hint(Hint.OnCannotResolvePartial, "On")
.Hint(Hint.OnNewRoot, "Off")
.Hint(Hint.OnNewRootPartial, "On")
.Hint(Hint.ToString, "On");
}
```
Expand Down
2 changes: 1 addition & 1 deletion readme/service-collection.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ partial class Composition : ServiceProviderFactory<Composition>
CreateServiceCollection(this);

static void Setup() =>

DI.Setup()
.DependsOn(Base)
.Bind<IDependency>("Dependency Key").As(Lifetime.Singleton).To<Dependency>()
.Bind<IService>().To<Service>()
.Root<IDependency>(tag: "Dependency Key")
Expand Down
1 change: 1 addition & 0 deletions samples/BlazorServerApp/Composition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace BlazorServerApp;
internal partial class Composition : ServiceProviderFactory<Composition>
{
void Setup() => DI.Setup()
.DependsOn(Base)
// View Models
.Bind().To<ClockViewModel>()
// Provides the composition root for Clock view model
Expand Down
1 change: 1 addition & 0 deletions samples/BlazorWebAssemblyApp/Composition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace BlazorWebAssemblyApp;
internal partial class Composition : ServiceProviderFactory<Composition>
{
void Setup() => DI.Setup()
.DependsOn(Base)
// View Models
.Bind().As(Singleton).To<ClockViewModel>()
// Provides the composition root for Clock view model
Expand Down
1 change: 1 addition & 0 deletions samples/GrpcService/Composition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace GrpcService;
internal partial class Composition : ServiceProviderFactory<Composition>
{
static void Setup() => DI.Setup()
.DependsOn(Base)
// Provides the composition root for Greeter service
.Root<GreeterService>();
}
1 change: 1 addition & 0 deletions samples/MinimalWebAPI/Composition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace MinimalWebAPI;
internal partial class Composition : ServiceProviderFactory<Composition>
{
void Setup() => DI.Setup()
.DependsOn(Base)
.Bind().As(Singleton).To<WeatherForecastService>()
.Root<IWeatherForecastService>()

Expand Down
1 change: 1 addition & 0 deletions samples/WebAPI/Composition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace WebAPI;
internal partial class Composition : ServiceProviderFactory<Composition>
{
static void Setup() => DI.Setup()
.DependsOn(Base)
.Bind().As(Singleton).To<WeatherForecastService>()
// Provides the composition root for Weather Forecast controller
.Root<WeatherForecastController>();
Expand Down
1 change: 1 addition & 0 deletions samples/WebApp/Composition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace WebApp;
internal partial class Composition : ServiceProviderFactory<Composition>
{
static void Setup() => DI.Setup()
.DependsOn(Base)
.Bind().As(Singleton).To<WeatherForecastService>()
// Provides the composition root for Home controller
.Root<HomeController>();
Expand Down
14 changes: 13 additions & 1 deletion src/Pure.DI.MS/any/Pure.DI/MS/ServiceProviderFactory.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ public class ServiceProviderFactory<TComposition>: IServiceProviderFactory<IServ
private static readonly ParameterExpression TypeParameter = Expression.Parameter(typeof(Type));
private static readonly ParameterExpression TagParameter = Expression.Parameter(typeof(object));

/// <summary>
/// The name of the Pure.DI setup to use as a dependency in other setups.
/// <example>
/// For example:
/// <code>
/// void Setup() =&amp;gt;
/// DI.Setup(nameof(Composition)).DependsOn(Base);
/// </code>
/// </example>
/// </summary>
protected const string Base = "Pure.DI.MS.ServiceProviderFactory";

/// <summary>
/// An instance of <see cref="Pure.DI.MS.ServiceCollectionFactory"/>.
/// </summary>
Expand All @@ -51,7 +63,7 @@ public class ServiceProviderFactory<TComposition>: IServiceProviderFactory<IServ
/// </summary>
[global::System.Diagnostics.Conditional("A2768DE22DE3E430C9653990D516CC9B")]
private static void HintsSetup() =>
global::Pure.DI.DI.Setup("", global::Pure.DI.CompositionKind.Global)
global::Pure.DI.DI.Setup(Base, global::Pure.DI.CompositionKind.Internal)
.Hint(global::Pure.DI.Hint.OnCannotResolve, "On")
.Hint(global::Pure.DI.Hint.OnCannotResolvePartial, "Off")
.Hint(global::Pure.DI.Hint.OnNewRoot, "On")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ class MyGlobalComposition2
{
static void Setup() =>
DI.Setup("Some name", kind: Global)
.Hint(Hint.OnCannotResolve, "Off")
.Hint(Hint.OnCannotResolvePartial, "On")
.Hint(Hint.OnNewRoot, "Off")
.Hint(Hint.OnNewRootPartial, "On")
.Hint(Hint.ToString, "On");
}
// }
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,8 @@ partial class Composition : ServiceProviderFactory<Composition>
CreateServiceCollection(this);

static void Setup() =>
// }
// OnCannotResolve = On
// OnCannotResolvePartial = Off
// OnNewRoot = On
// OnNewRootPartial = Off
// {
DI.Setup()
.DependsOn(Base)
.Bind<IDependency>("Dependency Key").As(Lifetime.Singleton).To<Dependency>()
.Bind<IService>().To<Service>()
.Root<IDependency>(tag: "Dependency Key")
Expand Down

0 comments on commit 1713ff3

Please sign in to comment.