Skip to content

Commit

Permalink
final
Browse files Browse the repository at this point in the history
  • Loading branch information
sungam3r committed Jan 4, 2024
1 parent 3e1f32d commit f3bbba7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
21 changes: 12 additions & 9 deletions src/SteroidsDI.Tests/Cases/FactoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,17 @@ public void Named_Binding_Should_Throw_On_Unknown_Lifetime()
[Test]
public void Named_Binding_Should_Allow_The_Same_Type_With_Different_Names()
{
// not specific to this test - just add some additional registration for other type to increase code coverage
var services = new ServiceCollection()
.For<IComparable>()
.Named<string>("xxx", ServiceLifetime.Singleton)
.Services;

services.AddTransient<IBuilder, Builder>()
.AddTransient<IBuilder, Builder>()
.For<IBuilder>()
.Named<SpecialBuilder>("aaa")
.Named<SpecialBuilder>("bbb")
.Named<SpecialBuilder>("ccc")
.Named<SpecialBuilder>("ddd")
.Named<SpecialBuilder>("eee");
.Named<SpecialBuilder>("eee")
.Services;

services.Count.ShouldBe(9);
services.Count.ShouldBe(7);
}

[Test]
Expand Down Expand Up @@ -76,7 +72,14 @@ public void Default_Binding_Should_Allow_Replace()
[TestCase(false)]
public void Factory_And_Named_Bindings_Should_Work(bool useDefault)
{
using var provider = ServicesBuilder.BuildDefault(addDefalt: useDefault).BuildServiceProvider(validateScopes: true);
var services = ServicesBuilder.BuildDefault(addDefalt: useDefault);

// not specific to this test - just add some additional registration for another type and place it in front of other registrations to increase code coverage
services.For<IComparable>().Named<string>("some", ServiceLifetime.Singleton);
services.Insert(0, services.Last());
services.RemoveAt(services.Count - 1);

using var provider = services.BuildServiceProvider(validateScopes: true);
using var scope = provider.CreateScope();

GenericScope<ServicesBuilder>.CurrentScope = scope;
Expand Down
2 changes: 1 addition & 1 deletion src/SteroidsDI/Factory/NamedBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace SteroidsDI;
internal sealed class NamedBinding
{
/// <summary> Name for default bindings. </summary>
internal static object DefaultName = new();
internal static readonly object DefaultName = new();

public NamedBinding(object name, Type serviceType, Type implementationType)
{
Expand Down

0 comments on commit f3bbba7

Please sign in to comment.