Skip to content

Commit

Permalink
Editorial changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sungam3r committed Jan 4, 2024
1 parent 71a8553 commit f2f250a
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 42 deletions.
58 changes: 29 additions & 29 deletions src/SteroidsDI.Tests/Cases/FactoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,31 +86,31 @@ public void Factory_And_Named_Bindings_Should_Work(bool useDefault)

var controller = scope.ServiceProvider.GetRequiredService<Controller>();

var builder1 = controller.Factory.AAA();
var builder1 = controller.NonGenericFactory.AAA();
builder1.ShouldBeAssignableTo<Builder>();
builder1.Build();

var notifier = controller.Factory.BBB();
var notifier = controller.NonGenericFactory.BBB();
notifier.ShouldBeAssignableTo<Notifier>();
notifier.Notify();

var builder2 = controller.Factory.CCC("xxx");
var builder2 = controller.NonGenericFactory.CCC("xxx");
builder2.ShouldBeAssignableTo<SpecialBuilder>();
builder2.Build();

var builder3 = controller.Factory.CCC("yyy");
var builder3 = controller.NonGenericFactory.CCC("yyy");
builder3.ShouldBeAssignableTo<SpecialBuilder>();
builder3.Build();

var builder4 = controller.Factory.CCC("oops");
var builder4 = controller.NonGenericFactory.CCC("oops");
builder4.ShouldBeAssignableTo<SpecialBuilderOver9000Level>();
builder4.Build();

var builder5 = controller.Factory.DDD(ManagerType.Good);
var builder5 = controller.NonGenericFactory.DDD(ManagerType.Good);
builder5.ShouldBeAssignableTo<SpecialBuilder>();
builder5.Build();

var builder6 = controller.Factory.DDD(ManagerType.Bad);
var builder6 = controller.NonGenericFactory.DDD(ManagerType.Bad);
builder6.ShouldBeAssignableTo<SpecialBuilderOver9000Level>();
builder6.Build();
}
Expand All @@ -128,31 +128,31 @@ public void Generic_Factory_And_Named_Bindings_Should_Work(bool useDefault)

var controller = scope.ServiceProvider.GetRequiredService<Controller>();

var builder1 = controller.Generic.AAA();
var builder1 = controller.GenericFactory.AAA();
builder1.ShouldBeAssignableTo<Builder>();
builder1.Build();

var notifier = controller.Generic.BBB();
var notifier = controller.GenericFactory.BBB();
notifier.ShouldBeAssignableTo<Notifier>();
notifier.Notify();

var builder2 = controller.Generic.CCC("xxx");
var builder2 = controller.GenericFactory.CCC("xxx");
builder2.ShouldBeAssignableTo<SpecialBuilder>();
builder2.Build();

var builder3 = controller.Generic.CCC("yyy");
var builder3 = controller.GenericFactory.CCC("yyy");
builder3.ShouldBeAssignableTo<SpecialBuilder>();
builder3.Build();

var builder4 = controller.Generic.CCC("oops");
var builder4 = controller.GenericFactory.CCC("oops");
builder4.ShouldBeAssignableTo<SpecialBuilderOver9000Level>();
builder4.Build();

var builder5 = controller.Generic.DDD(ManagerType.Good);
var builder5 = controller.GenericFactory.DDD(ManagerType.Good);
builder5.ShouldBeAssignableTo<SpecialBuilder>();
builder5.Build();

var builder6 = controller.Generic.DDD(ManagerType.Bad);
var builder6 = controller.GenericFactory.DDD(ManagerType.Bad);
builder6.ShouldBeAssignableTo<SpecialBuilderOver9000Level>();
builder6.Build();
}
Expand All @@ -164,9 +164,9 @@ public void Null_Binding_Should_Throw_When_No_Default()
using var provider = ServicesBuilder.BuildDefault().BuildServiceProvider(validateScopes: true);
var controller = provider.GetRequiredService<Controller>();

var msg1 = Should.Throw<InvalidOperationException>(() => controller.Factory.CCC(null!)).Message;
string msg1 = Should.Throw<InvalidOperationException>(() => controller.NonGenericFactory.CCC(null!)).Message;
msg1.ShouldBe("Destination type not found for named binding '' to type 'SteroidsDI.Tests.IBuilder' and no default binding exists. Verify that either a named binding or default binding is specified in the DI container.");
var msg2 = Should.Throw<InvalidOperationException>(() => controller.Generic.CCC(null!)).Message;
string msg2 = Should.Throw<InvalidOperationException>(() => controller.GenericFactory.CCC(null!)).Message;
msg2.ShouldBe("Destination type not found for named binding '' to type 'SteroidsDI.Tests.IBuilder' and no default binding exists. Verify that either a named binding or default binding is specified in the DI container.");
}

Expand All @@ -176,11 +176,11 @@ public void Null_Binding_Should_Work_When_Default()
using var provider = ServicesBuilder.BuildDefault(addDefalt: true).BuildServiceProvider(validateScopes: true);
var controller = provider.GetRequiredService<Controller>();

var builder1 = controller.Factory.CCC(null!);
var builder1 = controller.NonGenericFactory.CCC(null!);
builder1.ShouldBeAssignableTo<DefaultBuilder>();
builder1.Build();

var builder2 = controller.Generic.CCC(null!);
var builder2 = controller.GenericFactory.CCC(null!);
builder2.ShouldBeAssignableTo<DefaultBuilder>();
builder2.Build();
}
Expand All @@ -191,14 +191,14 @@ public void Unknown_Binding_Should_Throw_When_No_Default()
using var provider = ServicesBuilder.BuildDefault().BuildServiceProvider(validateScopes: true);
var controller = provider.GetRequiredService<Controller>();

var msg1 = Should.Throw<InvalidOperationException>(() => controller.Factory.CCC("Zorro")).Message;
string msg1 = Should.Throw<InvalidOperationException>(() => controller.NonGenericFactory.CCC("Zorro")).Message;
msg1.ShouldBe("Destination type not found for named binding 'Zorro' to type 'SteroidsDI.Tests.IBuilder' and no default binding exists. Verify that either a named binding or default binding is specified in the DI container.");
var msg2 = Should.Throw<InvalidOperationException>(() => controller.Generic.CCC("Zorro")).Message;
string msg2 = Should.Throw<InvalidOperationException>(() => controller.GenericFactory.CCC("Zorro")).Message;
msg2.ShouldBe("Destination type not found for named binding 'Zorro' to type 'SteroidsDI.Tests.IBuilder' and no default binding exists. Verify that either a named binding or default binding is specified in the DI container.");

var msg3 = Should.Throw<InvalidOperationException>(() => controller.Factory.DDD(ManagerType.Angry)).Message;
string msg3 = Should.Throw<InvalidOperationException>(() => controller.NonGenericFactory.DDD(ManagerType.Angry)).Message;
msg3.ShouldBe("Destination type not found for named binding 'Angry' to type 'SteroidsDI.Tests.IBuilder' and no default binding exists. Verify that either a named binding or default binding is specified in the DI container.");
var msg4 = Should.Throw<InvalidOperationException>(() => controller.Generic.DDD(ManagerType.Angry)).Message;
string msg4 = Should.Throw<InvalidOperationException>(() => controller.GenericFactory.DDD(ManagerType.Angry)).Message;
msg4.ShouldBe("Destination type not found for named binding 'Angry' to type 'SteroidsDI.Tests.IBuilder' and no default binding exists. Verify that either a named binding or default binding is specified in the DI container.");
}

Expand All @@ -209,19 +209,19 @@ public void Unknown_Binding_Should_Work_When_Default()
using var provider = ServicesBuilder.BuildDefault(addDefalt: true).BuildServiceProvider(validateScopes: true);
var controller = provider.GetRequiredService<Controller>();

var builder1 = controller.Factory.CCC("Zorro");
var builder1 = controller.NonGenericFactory.CCC("Zorro");
builder1.ShouldBeAssignableTo<DefaultBuilder>();
builder1.Build();

var builder2 = controller.Generic.CCC("Zorro");
var builder2 = controller.GenericFactory.CCC("Zorro");
builder2.ShouldBeAssignableTo<DefaultBuilder>();
builder2.Build();

var builder3 = controller.Factory.DDD(ManagerType.Angry);
var builder3 = controller.NonGenericFactory.DDD(ManagerType.Angry);
builder3.ShouldBeAssignableTo<DefaultBuilder>();
builder3.Build();

var builder4 = controller.Generic.DDD(ManagerType.Angry);
var builder4 = controller.GenericFactory.DDD(ManagerType.Angry);
builder4.ShouldBeAssignableTo<DefaultBuilder>();
builder4.Build();
}
Expand All @@ -230,9 +230,9 @@ public void Unknown_Binding_Should_Work_When_Default()
[Category("Throw")]
public void Named_Binding_With_Invalid_Properties_Should_Throw()
{
var msg1 = Should.Throw<ArgumentNullException>(() => ServicesBuilder.BuildDefault().For<IBuilder>().Named<SpecialBuilder>(null!).Services.BuildServiceProvider(validateScopes: true)).Message;
string msg1 = Should.Throw<ArgumentNullException>(() => ServicesBuilder.BuildDefault().For<IBuilder>().Named<SpecialBuilder>(null!).Services.BuildServiceProvider(validateScopes: true)).Message;
msg1.ShouldBe("No binding name specified. (Parameter 'name')");
var msg2 = Should.Throw<InvalidOperationException>(() => ServicesBuilder.BuildDefault().For<IBuilder>().Named<SpecialBuilderOver9000Level>("oops", ServiceLifetime.Transient).Services.BuildServiceProvider(validateScopes: true)).Message;
string msg2 = Should.Throw<InvalidOperationException>(() => ServicesBuilder.BuildDefault().For<IBuilder>().Named<SpecialBuilderOver9000Level>("oops", ServiceLifetime.Transient).Services.BuildServiceProvider(validateScopes: true)).Message;
msg2.ShouldBe(@"It is not possible to add a named binding 'oops' for type SteroidsDI.Tests.IBuilder, because the DI container
already has a binding on type SteroidsDI.Tests.SpecialBuilderOver9000Level with different characteristics. This is a limitation of the current implementation.");
}
Expand All @@ -241,7 +241,7 @@ public void Named_Binding_With_Invalid_Properties_Should_Throw()
[Category("Throw")]
public void Default_Binding_With_Invalid_Properties_Should_Throw()
{
var msg = Should.Throw<InvalidOperationException>(() => ServicesBuilder.BuildDefault(addDefalt: true).For<IBuilder>().Default<DefaultBuilder>(ServiceLifetime.Transient).Services.BuildServiceProvider(validateScopes: true)).Message;
string msg = Should.Throw<InvalidOperationException>(() => ServicesBuilder.BuildDefault(addDefalt: true).For<IBuilder>().Default<DefaultBuilder>(ServiceLifetime.Transient).Services.BuildServiceProvider(validateScopes: true)).Message;
msg.ShouldBe(@"It is not possible to add a default binding for type SteroidsDI.Tests.IBuilder, because the DI container
already has a binding on type SteroidsDI.Tests.DefaultBuilder with different characteristics. This is a limitation of the current implementation.");
}
Expand Down
2 changes: 1 addition & 1 deletion src/SteroidsDI.Tests/Factory/IGenericFactory.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace SteroidsDI.Tests;

/// <summary>An generic factory for which implementation is generated in runtime.</summary>
/// <summary>A generic factory for which implementation is generated in runtime.</summary>
/// <typeparam name="TBuilder">The first generic parameter.</typeparam>
/// <typeparam name="TNotifier">The second generic parameter.</typeparam>
public interface IGenericFactory<TBuilder, TNotifier>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
namespace SteroidsDI.Tests;

/// <summary>This is an example of a generated factory.</summary>
internal sealed class IMegaFactory_Generated : IMegaFactory
internal sealed class INonGenericFactory_Generated : INonGenericFactory
{
private readonly IServiceProvider _provider;
private readonly List<NamedBinding> _bindings; // all bindings
private readonly ServiceProviderAdvancedOptions _options;

public IMegaFactory_Generated(IServiceProvider provider, IEnumerable<NamedBinding> bindings, IOptions<ServiceProviderAdvancedOptions> options)
public INonGenericFactory_Generated(IServiceProvider provider, IEnumerable<NamedBinding> bindings, IOptions<ServiceProviderAdvancedOptions> options)
{
_provider = provider;
_bindings = bindings.ToList();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace SteroidsDI.Tests;

/// <summary>An factory for which implementation is generated in runtime.</summary>
public interface IMegaFactory
/// <summary>A factory for which implementation is generated in runtime.</summary>
public interface INonGenericFactory
{
IBuilder AAA();

Expand Down
12 changes: 6 additions & 6 deletions src/SteroidsDI.Tests/Model/Controller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ internal class Controller : IDisposable
{
public Controller(
IScopeFactory scopeFactory,
IMegaFactory factory,
IGenericFactory<IBuilder, INotifier> generic,
INonGenericFactory nonGenericFactory,
IGenericFactory<IBuilder, INotifier> genericFactory,
Func<ScopedService> scopedFunc,
Func<TransientService> transientFunc,
Defer<ScopedService> scopedDefer,
Defer<TransientService> transientDefer)
{
Factory = factory;
Generic = generic;
NonGenericFactory = nonGenericFactory;
GenericFactory = genericFactory;
ScopedFunc = scopedFunc;
ScopedDefer = scopedDefer;
TransientFunc = transientFunc;
Expand All @@ -27,9 +27,9 @@ public Controller(
}
}

public IMegaFactory Factory { get; }
public INonGenericFactory NonGenericFactory { get; }

public IGenericFactory<IBuilder, INotifier> Generic { get; set; }
public IGenericFactory<IBuilder, INotifier> GenericFactory { get; set; }

public Func<ScopedService> ScopedFunc { get; set; }

Expand Down
2 changes: 1 addition & 1 deletion src/SteroidsDI.Tests/ServicesBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static IServiceCollection BuildDefault(bool addScopeProvider = true, bool
.AddTransient<TransientService>().AddFunc<TransientService>()

.AddSingleton<Controller>()
.AddFactory<IMegaFactory>()
.AddFactory<INonGenericFactory>()
.AddFactory<IGenericFactory<IBuilder, INotifier>>()
.AddTransient<IBuilder, Builder>()
.AddSingleton<INotifier, Notifier>();
Expand Down
2 changes: 1 addition & 1 deletion src/SteroidsDI/Extensions/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ private static IServiceCollection AddAdvancedOptions(this IServiceCollection ser
/// <param name="services">A collection of DI container services.</param>
/// <returns>Binding context.</returns>
public static BindingContext<TService> For<TService>(this IServiceCollection services)
where TService : class => new BindingContext<TService>(services);
where TService : class => new(services);

/// <summary>
/// Adds the specified type <paramref name="factoryType" /> to the DI container
Expand Down

0 comments on commit f2f250a

Please sign in to comment.