diff --git a/src/SteroidsDI.Tests/Cases/FactoryTests.cs b/src/SteroidsDI.Tests/Cases/FactoryTests.cs index 6af2b12..4885878 100644 --- a/src/SteroidsDI.Tests/Cases/FactoryTests.cs +++ b/src/SteroidsDI.Tests/Cases/FactoryTests.cs @@ -86,31 +86,31 @@ public void Factory_And_Named_Bindings_Should_Work(bool useDefault) var controller = scope.ServiceProvider.GetRequiredService(); - var builder1 = controller.Factory.AAA(); + var builder1 = controller.NonGenericFactory.AAA(); builder1.ShouldBeAssignableTo(); builder1.Build(); - var notifier = controller.Factory.BBB(); + var notifier = controller.NonGenericFactory.BBB(); notifier.ShouldBeAssignableTo(); notifier.Notify(); - var builder2 = controller.Factory.CCC("xxx"); + var builder2 = controller.NonGenericFactory.CCC("xxx"); builder2.ShouldBeAssignableTo(); builder2.Build(); - var builder3 = controller.Factory.CCC("yyy"); + var builder3 = controller.NonGenericFactory.CCC("yyy"); builder3.ShouldBeAssignableTo(); builder3.Build(); - var builder4 = controller.Factory.CCC("oops"); + var builder4 = controller.NonGenericFactory.CCC("oops"); builder4.ShouldBeAssignableTo(); builder4.Build(); - var builder5 = controller.Factory.DDD(ManagerType.Good); + var builder5 = controller.NonGenericFactory.DDD(ManagerType.Good); builder5.ShouldBeAssignableTo(); builder5.Build(); - var builder6 = controller.Factory.DDD(ManagerType.Bad); + var builder6 = controller.NonGenericFactory.DDD(ManagerType.Bad); builder6.ShouldBeAssignableTo(); builder6.Build(); } @@ -128,31 +128,31 @@ public void Generic_Factory_And_Named_Bindings_Should_Work(bool useDefault) var controller = scope.ServiceProvider.GetRequiredService(); - var builder1 = controller.Generic.AAA(); + var builder1 = controller.GenericFactory.AAA(); builder1.ShouldBeAssignableTo(); builder1.Build(); - var notifier = controller.Generic.BBB(); + var notifier = controller.GenericFactory.BBB(); notifier.ShouldBeAssignableTo(); notifier.Notify(); - var builder2 = controller.Generic.CCC("xxx"); + var builder2 = controller.GenericFactory.CCC("xxx"); builder2.ShouldBeAssignableTo(); builder2.Build(); - var builder3 = controller.Generic.CCC("yyy"); + var builder3 = controller.GenericFactory.CCC("yyy"); builder3.ShouldBeAssignableTo(); builder3.Build(); - var builder4 = controller.Generic.CCC("oops"); + var builder4 = controller.GenericFactory.CCC("oops"); builder4.ShouldBeAssignableTo(); builder4.Build(); - var builder5 = controller.Generic.DDD(ManagerType.Good); + var builder5 = controller.GenericFactory.DDD(ManagerType.Good); builder5.ShouldBeAssignableTo(); builder5.Build(); - var builder6 = controller.Generic.DDD(ManagerType.Bad); + var builder6 = controller.GenericFactory.DDD(ManagerType.Bad); builder6.ShouldBeAssignableTo(); builder6.Build(); } @@ -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(); - var msg1 = Should.Throw(() => controller.Factory.CCC(null!)).Message; + string msg1 = Should.Throw(() => 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(() => controller.Generic.CCC(null!)).Message; + string msg2 = Should.Throw(() => 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."); } @@ -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(); - var builder1 = controller.Factory.CCC(null!); + var builder1 = controller.NonGenericFactory.CCC(null!); builder1.ShouldBeAssignableTo(); builder1.Build(); - var builder2 = controller.Generic.CCC(null!); + var builder2 = controller.GenericFactory.CCC(null!); builder2.ShouldBeAssignableTo(); builder2.Build(); } @@ -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(); - var msg1 = Should.Throw(() => controller.Factory.CCC("Zorro")).Message; + string msg1 = Should.Throw(() => 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(() => controller.Generic.CCC("Zorro")).Message; + string msg2 = Should.Throw(() => 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(() => controller.Factory.DDD(ManagerType.Angry)).Message; + string msg3 = Should.Throw(() => 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(() => controller.Generic.DDD(ManagerType.Angry)).Message; + string msg4 = Should.Throw(() => 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."); } @@ -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(); - var builder1 = controller.Factory.CCC("Zorro"); + var builder1 = controller.NonGenericFactory.CCC("Zorro"); builder1.ShouldBeAssignableTo(); builder1.Build(); - var builder2 = controller.Generic.CCC("Zorro"); + var builder2 = controller.GenericFactory.CCC("Zorro"); builder2.ShouldBeAssignableTo(); builder2.Build(); - var builder3 = controller.Factory.DDD(ManagerType.Angry); + var builder3 = controller.NonGenericFactory.DDD(ManagerType.Angry); builder3.ShouldBeAssignableTo(); builder3.Build(); - var builder4 = controller.Generic.DDD(ManagerType.Angry); + var builder4 = controller.GenericFactory.DDD(ManagerType.Angry); builder4.ShouldBeAssignableTo(); builder4.Build(); } @@ -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(() => ServicesBuilder.BuildDefault().For().Named(null!).Services.BuildServiceProvider(validateScopes: true)).Message; + string msg1 = Should.Throw(() => ServicesBuilder.BuildDefault().For().Named(null!).Services.BuildServiceProvider(validateScopes: true)).Message; msg1.ShouldBe("No binding name specified. (Parameter 'name')"); - var msg2 = Should.Throw(() => ServicesBuilder.BuildDefault().For().Named("oops", ServiceLifetime.Transient).Services.BuildServiceProvider(validateScopes: true)).Message; + string msg2 = Should.Throw(() => ServicesBuilder.BuildDefault().For().Named("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."); } @@ -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(() => ServicesBuilder.BuildDefault(addDefalt: true).For().Default(ServiceLifetime.Transient).Services.BuildServiceProvider(validateScopes: true)).Message; + string msg = Should.Throw(() => ServicesBuilder.BuildDefault(addDefalt: true).For().Default(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."); } diff --git a/src/SteroidsDI.Tests/Factory/IGenericFactory.cs b/src/SteroidsDI.Tests/Factory/IGenericFactory.cs index c7021bd..b38ec48 100644 --- a/src/SteroidsDI.Tests/Factory/IGenericFactory.cs +++ b/src/SteroidsDI.Tests/Factory/IGenericFactory.cs @@ -1,6 +1,6 @@ namespace SteroidsDI.Tests; -/// An generic factory for which implementation is generated in runtime. +/// A generic factory for which implementation is generated in runtime. /// The first generic parameter. /// The second generic parameter. public interface IGenericFactory diff --git a/src/SteroidsDI.Tests/Factory/IMegaFactory.Generated.cs b/src/SteroidsDI.Tests/Factory/INonGenericFactory.Generated.cs similarity index 77% rename from src/SteroidsDI.Tests/Factory/IMegaFactory.Generated.cs rename to src/SteroidsDI.Tests/Factory/INonGenericFactory.Generated.cs index 18adc32..58454a7 100644 --- a/src/SteroidsDI.Tests/Factory/IMegaFactory.Generated.cs +++ b/src/SteroidsDI.Tests/Factory/INonGenericFactory.Generated.cs @@ -3,13 +3,13 @@ namespace SteroidsDI.Tests; /// This is an example of a generated factory. -internal sealed class IMegaFactory_Generated : IMegaFactory +internal sealed class INonGenericFactory_Generated : INonGenericFactory { private readonly IServiceProvider _provider; private readonly List _bindings; // all bindings private readonly ServiceProviderAdvancedOptions _options; - public IMegaFactory_Generated(IServiceProvider provider, IEnumerable bindings, IOptions options) + public INonGenericFactory_Generated(IServiceProvider provider, IEnumerable bindings, IOptions options) { _provider = provider; _bindings = bindings.ToList(); diff --git a/src/SteroidsDI.Tests/Factory/IMegaFactory.cs b/src/SteroidsDI.Tests/Factory/INonGenericFactory.cs similarity index 54% rename from src/SteroidsDI.Tests/Factory/IMegaFactory.cs rename to src/SteroidsDI.Tests/Factory/INonGenericFactory.cs index 3d77b73..0c2a486 100644 --- a/src/SteroidsDI.Tests/Factory/IMegaFactory.cs +++ b/src/SteroidsDI.Tests/Factory/INonGenericFactory.cs @@ -1,7 +1,7 @@ namespace SteroidsDI.Tests; -/// An factory for which implementation is generated in runtime. -public interface IMegaFactory +/// A factory for which implementation is generated in runtime. +public interface INonGenericFactory { IBuilder AAA(); diff --git a/src/SteroidsDI.Tests/Model/Controller.cs b/src/SteroidsDI.Tests/Model/Controller.cs index 070908e..b130e42 100644 --- a/src/SteroidsDI.Tests/Model/Controller.cs +++ b/src/SteroidsDI.Tests/Model/Controller.cs @@ -6,15 +6,15 @@ internal class Controller : IDisposable { public Controller( IScopeFactory scopeFactory, - IMegaFactory factory, - IGenericFactory generic, + INonGenericFactory nonGenericFactory, + IGenericFactory genericFactory, Func scopedFunc, Func transientFunc, Defer scopedDefer, Defer transientDefer) { - Factory = factory; - Generic = generic; + NonGenericFactory = nonGenericFactory; + GenericFactory = genericFactory; ScopedFunc = scopedFunc; ScopedDefer = scopedDefer; TransientFunc = transientFunc; @@ -27,9 +27,9 @@ public Controller( } } - public IMegaFactory Factory { get; } + public INonGenericFactory NonGenericFactory { get; } - public IGenericFactory Generic { get; set; } + public IGenericFactory GenericFactory { get; set; } public Func ScopedFunc { get; set; } diff --git a/src/SteroidsDI.Tests/ServicesBuilder.cs b/src/SteroidsDI.Tests/ServicesBuilder.cs index bf0b9bd..38e901d 100644 --- a/src/SteroidsDI.Tests/ServicesBuilder.cs +++ b/src/SteroidsDI.Tests/ServicesBuilder.cs @@ -16,7 +16,7 @@ public static IServiceCollection BuildDefault(bool addScopeProvider = true, bool .AddTransient().AddFunc() .AddSingleton() - .AddFactory() + .AddFactory() .AddFactory>() .AddTransient() .AddSingleton(); diff --git a/src/SteroidsDI/Extensions/ServiceCollectionExtensions.cs b/src/SteroidsDI/Extensions/ServiceCollectionExtensions.cs index 0852625..00261ea 100644 --- a/src/SteroidsDI/Extensions/ServiceCollectionExtensions.cs +++ b/src/SteroidsDI/Extensions/ServiceCollectionExtensions.cs @@ -16,7 +16,7 @@ private static IServiceCollection AddAdvancedOptions(this IServiceCollection ser /// A collection of DI container services. /// Binding context. public static BindingContext For(this IServiceCollection services) - where TService : class => new BindingContext(services); + where TService : class => new(services); /// /// Adds the specified type to the DI container