Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolayPianikov committed Dec 15, 2024
1 parent d71234b commit bcc6aef
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion readme/check-for-a-root.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ partial class Composition
private static readonly HashSet<(Type type, object? tag)> Roots = [];

// Check that the root can be resolved by Resolve methods
internal static bool HasRoot(Type type, object? key = default) =>
internal static bool HasRoot(Type type, object? key = null) =>
Roots.Contains((type, key));

static void Setup() =>
Expand Down
2 changes: 1 addition & 1 deletion readme/generic-root-arguments.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ DI.Setup(nameof(Composition))
.Root<IService<TT>>("GetMyService");

var composition = new Composition();
var service = composition.GetMyService<int>(someArg: 33);
IService<int> service = composition.GetMyService<int>(someArg: 33);
```

The following partial class will be generated:
Expand Down
2 changes: 2 additions & 0 deletions readme/tag-type.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class Service(

DI.Setup(nameof(Composition))
// Tag.Type here is the same as typeof(AbcDependency)
// The `default` tag is used to resolve dependencies
// when the tag was not specified by the consumer
.Bind<IDependency>(Tag.Type, default).To<AbcDependency>()
// Tag.Type here is the same as typeof(XyzDependency)
.Bind<IDependency>(Tag.Type).As(Lifetime.Singleton).To<XyzDependency>()
Expand Down
2 changes: 2 additions & 0 deletions readme/tags.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class Service(
}

DI.Setup(nameof(Composition))
// The `default` tag is used to resolve dependencies
// when the tag was not specified by the consumer
.Bind<IDependency>("AbcTag", default).To<AbcDependency>()
.Bind<IDependency>("XyzTag")
.As(Lifetime.Singleton)
Expand Down
2 changes: 1 addition & 1 deletion readme/weak-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Service(WeakReference<IDependency> dependency) : IService
public IDependency? Dependency =>
dependency.TryGetTarget(out var value)
? value
: default;
: null;
}

DI.Setup(nameof(Composition))
Expand Down
7 changes: 5 additions & 2 deletions tests/Pure.DI.UsageTests/Advanced/TagTypeScenario.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// ReSharper disable ArrangeTypeModifiers
// ReSharper disable ClassNeverInstantiated.Global

// ReSharper disable PreferConcreteValueOverDefault
namespace Pure.DI.UsageTests.Advanced.TagTypeScenario;

using Shouldly;
Expand Down Expand Up @@ -53,8 +54,10 @@ public void Run()
{
// {
DI.Setup(nameof(Composition))
// Tag.Type here is the same as typeof(AbcDependency)
.Bind<IDependency>(Tag.Type, null).To<AbcDependency>()
// Tag.Type here is the same as typeof(AbcDependency)
// The `default` tag is used to resolve dependencies
// when the tag was not specified by the consumer
.Bind<IDependency>(Tag.Type, default).To<AbcDependency>()
// Tag.Type here is the same as typeof(XyzDependency)
.Bind<IDependency>(Tag.Type).As(Lifetime.Singleton).To<XyzDependency>()
.Bind<IService>().To<Service>()
Expand Down
5 changes: 4 additions & 1 deletion tests/Pure.DI.UsageTests/Basics/TagsScenario.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// ReSharper disable ArrangeTypeModifiers
// ReSharper disable ClassNeverInstantiated.Global

// ReSharper disable PreferConcreteValueOverDefault
namespace Pure.DI.UsageTests.Basics.TagsScenario;

using Shouldly;
Expand Down Expand Up @@ -57,7 +58,9 @@ public void Run()
// Resolve = Off
// {
DI.Setup(nameof(Composition))
.Bind<IDependency>("AbcTag", null).To<AbcDependency>()
// The `default` tag is used to resolve dependencies
// when the tag was not specified by the consumer
.Bind<IDependency>("AbcTag", default).To<AbcDependency>()
.Bind<IDependency>("XyzTag")
.As(Lifetime.Singleton)
.To<XyzDependency>()
Expand Down

0 comments on commit bcc6aef

Please sign in to comment.