- refactoring and adapt to new language features

master
Simon G. 1 year ago
parent 93428ee797
commit 45125eb926
Signed by: SimonG
GPG Key ID: 0B82B964BA536523
  1. 23
      LightweightIocContainer.Validation/IocValidator.cs
  2. 1
      LightweightIocContainer/Exceptions/CircularDependencyException.cs
  3. 6
      LightweightIocContainer/Exceptions/IocContainerException.cs
  4. 2
      LightweightIocContainer/Exceptions/NoMatchingConstructorFoundException.cs
  5. 5
      LightweightIocContainer/Factories/CustomTypedFactory.cs
  6. 2
      LightweightIocContainer/Installers/AssemblyInstaller.cs
  7. 33
      LightweightIocContainer/IocContainer.cs
  8. 6
      LightweightIocContainer/Registrations/MultipleMultitonRegistration.cs
  9. 32
      LightweightIocContainer/Registrations/MultipleRegistration.cs
  10. 8
      LightweightIocContainer/Registrations/RegistrationCollector.cs
  11. 14
      LightweightIocContainer/ResolvePlaceholders/InternalFactoryMethodPlaceholder.cs
  12. 5
      LightweightIocContainer/ResolvePlaceholders/InternalResolvePlaceholder.cs
  13. 19
      LightweightIocContainer/ResolvePlaceholders/InternalToBeResolvedPlaceholder.cs
  14. 20
      Test.LightweightIocContainer.Validation/IocValidatorTest.cs
  15. 23
      Test.LightweightIocContainer/AssemblyInstallerTest.cs
  16. 34
      Test.LightweightIocContainer/EnumerableExtensionTest.cs
  17. 15
      Test.LightweightIocContainer/FluentFactoryRegistrationTest.cs
  18. 15
      Test.LightweightIocContainer/IgnoreConstructorAttributeTest.cs
  19. 20
      Test.LightweightIocContainer/IocContainerInterfaceSegregationTest.cs
  20. 17
      Test.LightweightIocContainer/IocContainerParameterRegistrationTest.cs
  21. 30
      Test.LightweightIocContainer/IocContainerRecursionTest.cs
  22. 32
      Test.LightweightIocContainer/IocContainerTest.cs
  23. 11
      Test.LightweightIocContainer/MultipleMultitonRegistrationTest.cs
  24. 1
      Test.LightweightIocContainer/OnCreateTest.cs
  25. 20
      Test.LightweightIocContainer/OpenGenericRegistrationTest.cs
  26. 26
      Test.LightweightIocContainer/RegistrationBaseTest.cs
  27. 10
      Test.LightweightIocContainer/SingleTypeRegistrationTest.cs

@ -11,20 +11,9 @@ namespace LightweightIocContainer.Validation;
/// <summary>
/// Validator for your <see cref="IocContainer"/> to check if everything can be resolved with your current setup
/// </summary>
public class IocValidator
public class IocValidator(IocContainer iocContainer)
{
private readonly IocContainer _iocContainer;
private readonly List<(Type type, object? parameter)> _parameters;
/// <summary>
/// Validator for your <see cref="IocContainer"/> to check if everything can be resolved with your current setup
/// </summary>
/// <param name="iocContainer">The <see cref="IocContainer"/></param>
public IocValidator(IocContainer iocContainer)
{
_iocContainer = iocContainer;
_parameters = new List<(Type, object?)>();
}
private readonly List<(Type type, object? parameter)> _parameters = [];
/// <summary>
/// Add parameters that can't be default for your type to be created successfully
@ -40,13 +29,13 @@ public class IocValidator
/// </summary>
public void Validate()
{
List<Exception> validationExceptions = new();
List<Exception> validationExceptions = [];
foreach (IRegistration registration in _iocContainer.Registrations)
foreach (IRegistration registration in iocContainer.Registrations)
{
var definedParameters = _parameters.Where(p => p.type == registration.InterfaceType);
if (registration is IWithFactoryInternal { Factory: { } } withFactoryRegistration)
if (registration is IWithFactoryInternal { Factory: not null } withFactoryRegistration)
{
(from createMethod in withFactoryRegistration.Factory.CreateMethods.Where(m => m.ReturnType == registration.InterfaceType)
select createMethod.GetParameters().Select(p => p.ParameterType)
@ -71,7 +60,7 @@ public class IocValidator
private void TryResolve(Type type, object?[]? arguments, List<Exception> validationExceptions, bool isFactoryResolve = false)
{
(bool success, object _, Exception? exception) = _iocContainer.TryResolveNonGeneric(type, arguments, null, isFactoryResolve);
(bool success, object _, Exception? exception) = iocContainer.TryResolveNonGeneric(type, arguments, null, isFactoryResolve);
if (success)
return;

@ -22,7 +22,6 @@ internal class CircularDependencyException : IocContainerException
ResolveStack = resolveStack;
}
/// <summary>
/// The currently resolving <see cref="Type"/>
/// </summary>

@ -12,7 +12,7 @@ public abstract class IocContainerException : Exception
/// <summary>
/// A base <see cref="Exception"/> for the <see cref="LightweightIocContainer"/>
/// </summary>
protected IocContainerException() => InnerExceptions = new List<Exception>();
protected IocContainerException() => InnerExceptions = [];
/// <summary>
/// A base <see cref="Exception"/> for the <see cref="LightweightIocContainer"/>
@ -20,7 +20,7 @@ public abstract class IocContainerException : Exception
/// <param name="message">The message of the <see cref="Exception"/></param>
protected IocContainerException(string message)
: base(message) =>
InnerExceptions = new List<Exception>();
InnerExceptions = [];
/// <summary>
/// A base <see cref="Exception"/> for the <see cref="LightweightIocContainer"/>
@ -29,7 +29,7 @@ public abstract class IocContainerException : Exception
/// <param name="innerException">The inner <see cref="Exception"/></param>
protected IocContainerException(string message, Exception innerException)
: base(message, innerException) =>
InnerExceptions = new List<Exception> {innerException};
InnerExceptions = [innerException];
/// <summary>
/// The inner exceptions of the <see cref="IocContainerException"/>

@ -17,7 +17,7 @@ internal class NoMatchingConstructorFoundException : IocContainerException
: base($"No matching constructor for {type} found.")
{
Type = type;
InnerExceptions = new List<Exception>();
InnerExceptions = [];
}

@ -9,7 +9,4 @@ namespace LightweightIocContainer.Factories;
/// <summary>
/// <see cref="ITypedFactory"/> implementation for custom implemented factories
/// </summary>
public class CustomTypedFactory<TFactory> : TypedFactoryBase<TFactory>
{
}
public class CustomTypedFactory<TFactory> : TypedFactoryBase<TFactory>;

@ -20,7 +20,7 @@ public class AssemblyInstaller : IAssemblyInstaller
/// <param name="assembly">The <see cref="Assembly"/> from where the <see cref="IIocInstaller"/>s will be installed</param>
public AssemblyInstaller(Assembly assembly)
{
Installers = new List<IIocInstaller>();
Installers = [];
Type[] types = assembly.GetTypes();
foreach (Type type in types)

@ -21,23 +21,18 @@ public class IocContainer : IIocContainer, IIocResolver
{
private readonly RegistrationFactory _registrationFactory;
private readonly List<(Type type, object? instance)> _singletons = new();
private readonly List<(Type type, Type scope, Dictionary<object, object?> instances)> _multitons = new();
private readonly List<(Type type, object? instance)> _singletons = [];
private readonly List<(Type type, Type scope, Dictionary<object, object?> instances)> _multitons = [];
private readonly List<Type> _ignoreConstructorAttributes;
private readonly List<Type> _ignoreConstructorAttributes = [];
/// <summary>
/// The main container that carries all the <see cref="IRegistration"/>s and can resolve all the types you'll ever want
/// </summary>
public IocContainer()
{
_registrationFactory = new RegistrationFactory(this);
_ignoreConstructorAttributes = new List<Type>();
Registrations = new List<IRegistration>();
}
public IocContainer() => _registrationFactory = new RegistrationFactory(this);
internal List<IRegistration> Registrations { get; } = [];
internal List<IRegistration> Registrations { get; }
/// <summary>
/// Install the given installers for the current <see cref="IocContainer"/>
/// </summary>
@ -195,7 +190,7 @@ public class IocContainer : IIocContainer, IIocResolver
if (registration == null)
return (false, new object(), new TypeNotRegisteredException(typeof(T)));
List<Type> internalResolveStack = resolveStack == null ? new List<Type>() : new List<Type>(resolveStack);
List<Type> internalResolveStack = resolveStack == null ? [] : [..resolveStack];
(bool success, internalResolveStack, CircularDependencyException? circularDependencyException) = CheckForCircularDependencies<T>(internalResolveStack);
if (!success && circularDependencyException is not null)
@ -232,7 +227,7 @@ public class IocContainer : IIocContainer, IIocResolver
object multitonScopeArgument = TryGetMultitonScopeArgument(multitonRegistration, arguments);
parametersToResolve ??= new List<object?>();
parametersToResolve ??= [];
parametersToResolve.Insert(0, multitonScopeArgument); //insert scope at first place, won't be passed to ctor when creating multiton
}
@ -267,7 +262,7 @@ public class IocContainer : IIocContainer, IIocResolver
if (genericMethod == null)
throw new GenericMethodNotFoundException(nameof(TryResolve));
object? resolvedValue = genericMethod.Invoke(this, new object?[]{arguments, resolveStack, isFactoryResolve});
object? resolvedValue = genericMethod.Invoke(this, [arguments, resolveStack, isFactoryResolve]);
if (resolvedValue is not ValueTuple<bool, object, Exception?> resolvedTuple)
throw new Exception("Invalid return value!");
@ -600,12 +595,12 @@ public class IocContainer : IIocContainer, IIocResolver
{
List<ParameterInfo> constructorParameters = constructor.GetParameters().ToList();
List<ConstructorNotMatchingException> exceptions = new();
List<object?> parameters = new();
List<ConstructorNotMatchingException> exceptions = [];
List<object?> parameters = [];
List<object?>? passedArguments = null;
if (arguments != null)
passedArguments = new List<object?>(arguments);
passedArguments = [..arguments];
foreach (ParameterInfo parameter in constructorParameters)
{
@ -745,9 +740,9 @@ public class IocContainer : IIocContainer, IIocResolver
private (bool success, List<Type> resolveStack, CircularDependencyException? exception) CheckForCircularDependencies<T>(List<Type>? resolveStack)
{
if (resolveStack == null) //first resolve call
resolveStack = new List<Type> {typeof(T)}; //create new stack and add the currently resolving type to the stack
resolveStack = [typeof(T)]; //create new stack and add the currently resolving type to the stack
else if (resolveStack.Contains(typeof(T)))
return (false, new List<Type>(), new CircularDependencyException(typeof(T), resolveStack)); //currently resolving type is still resolving -> circular dependency
return (false, [], new CircularDependencyException(typeof(T), resolveStack)); //currently resolving type is still resolving -> circular dependency
else //not the first resolve call in chain but no circular dependencies for now
resolveStack.Add(typeof(T)); //add currently resolving type to the stack

@ -26,11 +26,11 @@ internal class MultipleMultitonRegistration<TInterface1, TInterface2, TImplement
public MultipleMultitonRegistration(Type interfaceType1, Type interfaceType2, Type implementationType, Type scope, IocContainer container)
: base(interfaceType1, implementationType, scope, container)
{
Registrations = new List<IRegistration>
{
Registrations =
[
new MultitonRegistration<TInterface1, TImplementation>(interfaceType1, implementationType, scope, container),
new MultitonRegistration<TInterface2, TImplementation>(interfaceType2, implementationType, scope, container)
};
];
}
/// <summary>

@ -22,13 +22,15 @@ internal abstract class MultipleRegistration<TInterface1, TImplementation> : Typ
/// <param name="lifestyle">The <see cref="Lifestyle"/> of this <see cref="MultipleRegistration{TInterface1,TInterface2}"/></param>
/// <param name="container">The current instance of the <see cref="IIocContainer"/></param>
protected MultipleRegistration(Type interfaceType1, Type implementationType, Lifestyle lifestyle, IocContainer container)
: base(interfaceType1, implementationType, lifestyle, container) =>
Registrations = new List<IRegistration>();
: base(interfaceType1, implementationType, lifestyle, container)
{
}
/// <summary>
/// A <see cref="List{T}"/> of <see cref="IRegistration"/>s that are registered within this <see cref="MultipleRegistration{TInterface1,TInterface2}"/>
/// </summary>
public List<IRegistration> Registrations { get; protected init; }
public List<IRegistration> Registrations { get; protected init; } = [];
}
/// <summary>
@ -50,11 +52,11 @@ internal class MultipleRegistration<TInterface1, TInterface2, TImplementation> :
public MultipleRegistration(Type interfaceType1, Type interfaceType2, Type implementationType, Lifestyle lifestyle, IocContainer container)
: base(interfaceType1, implementationType, lifestyle, container)
{
Registrations = new List<IRegistration>
{
Registrations =
[
new TypedRegistration<TInterface1, TImplementation>(interfaceType1, implementationType, lifestyle, container),
new TypedRegistration<TInterface2, TImplementation>(interfaceType2, implementationType, lifestyle, container)
};
];
}
/// <summary>
@ -97,12 +99,12 @@ internal class MultipleRegistration<TInterface1, TInterface2, TInterface3, TImpl
public MultipleRegistration(Type interfaceType1, Type interfaceType2, Type interfaceType3, Type implementationType, Lifestyle lifestyle, IocContainer container)
: base(interfaceType1, implementationType, lifestyle, container)
{
Registrations = new List<IRegistration>
{
Registrations =
[
new TypedRegistration<TInterface1, TImplementation>(interfaceType1, implementationType, lifestyle, container),
new TypedRegistration<TInterface2, TImplementation>(interfaceType2, implementationType, lifestyle, container),
new TypedRegistration<TInterface3, TImplementation>(interfaceType3, implementationType, lifestyle, container)
};
];
}
/// <summary>
@ -149,13 +151,13 @@ internal class MultipleRegistration<TInterface1, TInterface2, TInterface3, TInte
public MultipleRegistration(Type interfaceType1, Type interfaceType2, Type interfaceType3, Type interfaceType4, Type implementationType, Lifestyle lifestyle, IocContainer container)
: base(interfaceType1, implementationType, lifestyle, container)
{
Registrations = new List<IRegistration>
{
Registrations =
[
new TypedRegistration<TInterface1, TImplementation>(interfaceType1, implementationType, lifestyle, container),
new TypedRegistration<TInterface2, TImplementation>(interfaceType2, implementationType, lifestyle, container),
new TypedRegistration<TInterface3, TImplementation>(interfaceType3, implementationType, lifestyle, container),
new TypedRegistration<TInterface4, TImplementation>(interfaceType4, implementationType, lifestyle, container)
};
];
}
/// <summary>
@ -206,14 +208,14 @@ internal class MultipleRegistration<TInterface1, TInterface2, TInterface3, TInte
public MultipleRegistration(Type interfaceType1, Type interfaceType2, Type interfaceType3, Type interfaceType4, Type interfaceType5, Type implementationType, Lifestyle lifestyle, IocContainer container)
: base(interfaceType1, implementationType, lifestyle, container)
{
Registrations = new List<IRegistration>
{
Registrations =
[
new TypedRegistration<TInterface1, TImplementation>(interfaceType1, implementationType, lifestyle, container),
new TypedRegistration<TInterface2, TImplementation>(interfaceType2, implementationType, lifestyle, container),
new TypedRegistration<TInterface3, TImplementation>(interfaceType3, implementationType, lifestyle, container),
new TypedRegistration<TInterface4, TImplementation>(interfaceType4, implementationType, lifestyle, container),
new TypedRegistration<TInterface5, TImplementation>(interfaceType5, implementationType, lifestyle, container)
};
];
}
/// <summary>

@ -14,16 +14,12 @@ public class RegistrationCollector : IRegistrationCollector
{
private readonly RegistrationFactory _registrationFactory;
internal RegistrationCollector(RegistrationFactory registrationFactory)
{
_registrationFactory = registrationFactory;
Registrations = new List<IRegistration>();
}
internal RegistrationCollector(RegistrationFactory registrationFactory) => _registrationFactory = registrationFactory;
/// <summary>
/// The collected <see cref="IRegistration"/>s
/// </summary>
internal List<IRegistration> Registrations { get; }
internal List<IRegistration> Registrations { get; } = [];
/// <summary>
/// Add an Interface with a Type that implements it

@ -9,21 +9,15 @@ namespace LightweightIocContainer.ResolvePlaceholders;
/// <summary>
/// An internal placeholder that is used to hold factory methods for types that need to be resolved during the resolve process
/// </summary>
internal class InternalFactoryMethodPlaceholder<T> : IInternalToBeResolvedPlaceholder
internal class InternalFactoryMethodPlaceholder<T>(ISingleTypeRegistration<T> singleTypeRegistration) : IInternalToBeResolvedPlaceholder
{
public InternalFactoryMethodPlaceholder(ISingleTypeRegistration<T> singleTypeRegistration)
{
ResolvedType = singleTypeRegistration.InterfaceType;
SingleTypeRegistration = singleTypeRegistration;
}
/// <summary>
/// The <see cref="Type"/> to be resolved
/// </summary>
public Type ResolvedType { get; }
public Type ResolvedType { get; } = singleTypeRegistration.InterfaceType;
/// <summary>
/// The <see cref="ISingleTypeRegistration{T}"/>
/// </summary>
public ISingleTypeRegistration<T> SingleTypeRegistration { get; }
public ISingleTypeRegistration<T> SingleTypeRegistration { get; } = singleTypeRegistration;
}

@ -7,7 +7,4 @@ namespace LightweightIocContainer.ResolvePlaceholders;
/// <summary>
/// An internal placeholder that is used during the resolving process
/// </summary>
internal class InternalResolvePlaceholder
{
}
internal class InternalResolvePlaceholder;

@ -9,27 +9,20 @@ namespace LightweightIocContainer.ResolvePlaceholders;
/// <summary>
/// An internal placeholder that is used to hold types that need to be resolved during the resolving process
/// </summary>
internal class InternalToBeResolvedPlaceholder : IInternalToBeResolvedPlaceholder
internal class InternalToBeResolvedPlaceholder(Type resolvedType, IRegistration resolvedRegistration, List<object?>? parameters) : IInternalToBeResolvedPlaceholder
{
public InternalToBeResolvedPlaceholder(Type resolvedType, IRegistration resolvedRegistration, List<object?>? parameters)
{
ResolvedType = resolvedType;
ResolvedRegistration = resolvedRegistration;
Parameters = parameters;
}
/// <summary>
/// The <see cref="Type"/> to be resolved
/// </summary>
public Type ResolvedType { get; }
public Type ResolvedType { get; } = resolvedType;
/// <summary>
/// The <see cref="IRegistration"/> to be resolved
/// </summary>
public IRegistration ResolvedRegistration { get; }
public IRegistration ResolvedRegistration { get; } = resolvedRegistration;
/// <summary>
/// The parameters needed to resolve the <see cref="ResolvedRegistration"/>
/// </summary>
public List<object?>? Parameters { get; }
public List<object?>? Parameters { get; } = parameters;
}

@ -16,10 +16,7 @@ namespace Test.LightweightIocContainer.Validation;
[TestFixture]
public class IocValidatorTest
{
public interface ITest
{
}
public interface ITest;
[UsedImplicitly]
public interface IParameter
@ -33,22 +30,13 @@ public class IocValidatorTest
}
[UsedImplicitly]
public interface IConstraint
{
}
public interface IConstraint;
[UsedImplicitly]
public interface IGenericTest<T> where T : IConstraint, new()
{
}
public interface IGenericTest<T> where T : IConstraint, new();
[UsedImplicitly]
public class GenericTest<T> : IGenericTest<T> where T : IConstraint, new()
{
}
public class GenericTest<T> : IGenericTest<T> where T : IConstraint, new();
[UsedImplicitly]
public interface IGenericTestFactory

@ -6,7 +6,6 @@ using System.Reflection;
using JetBrains.Annotations;
using LightweightIocContainer;
using LightweightIocContainer.Installers;
using LightweightIocContainer.Interfaces;
using LightweightIocContainer.Interfaces.Installers;
using LightweightIocContainer.Interfaces.Registrations;
using NSubstitute;
@ -24,20 +23,16 @@ public class AssemblyInstallerTest
}
[UsedImplicitly]
public class AssemblyWrapper : Assembly
{
}
public class AssemblyWrapper : Assembly;
[Test]
public void TestInstall()
{
List<Type> types = new()
{
List<Type> types =
[
typeof(object),
typeof(TestInstaller)
};
];
AssemblyWrapper assemblyMock = Substitute.For<AssemblyWrapper>();
assemblyMock.GetTypes().Returns(types.ToArray());
@ -53,23 +48,23 @@ public class AssemblyInstallerTest
[Test]
public void TestFromAssemblyThis()
{
IIocContainer iocContainer = new IocContainer();
IocContainer iocContainer = new();
iocContainer.Install(FromAssembly.This());
}
[Test]
public void TestFromAssemblyInstance()
{
List<Type> types = new()
{
List<Type> types =
[
typeof(object),
typeof(TestInstaller)
};
];
AssemblyWrapper assemblyMock = Substitute.For<AssemblyWrapper>();
assemblyMock.GetTypes().Returns(types.ToArray());
IIocContainer iocContainer = new IocContainer();
IocContainer iocContainer = new();
iocContainer.Install(FromAssembly.Instance(assemblyMock));
}
}

@ -34,20 +34,20 @@ public class EnumerableExtensionTest
[SuppressMessage("ReSharper", "CollectionNeverUpdated.Local")]
public void TestFirstOrGivenNoPredicateEmpty()
{
List<ListObject> list = new();
List<ListObject> list = [];
Assert.That(list.FirstOrGiven<ListObject, Given>(), Is.InstanceOf<Given>());
}
[Test]
public void TestFirstOrGivenNoPredicate()
{
List<ListObject> list = new()
{
new ListObject {Index = 0},
new ListObject {Index = 1},
new ListObject {Index = 2},
new ListObject {Index = 3}
};
List<ListObject> list =
[
new() { Index = 0 },
new() { Index = 1 },
new() { Index = 2 },
new() { Index = 3 }
];
ListObject listObject = list.FirstOrGiven<ListObject, Given>();
@ -59,20 +59,20 @@ public class EnumerableExtensionTest
[SuppressMessage("ReSharper", "CollectionNeverUpdated.Local")]
public void TestFirstOrGivenPredicateEmpty()
{
List<ListObject> list = new();
List<ListObject> list = [];
Assert.That(list.FirstOrGiven<ListObject, Given>(o => o.Index == 2), Is.InstanceOf<Given>());
}
[Test]
public void TestFirstOrGivenPredicate()
{
List<ListObject> list = new()
{
new ListObject {Index = 0},
new ListObject {Index = 1},
new ListObject {Index = 2},
new ListObject {Index = 3}
};
List<ListObject> list =
[
new() { Index = 0 },
new() { Index = 1 },
new() { Index = 2 },
new() { Index = 3 }
];
ListObject listObject = list.FirstOrGiven<ListObject, Given>(o => o.Index == 2);
@ -88,7 +88,7 @@ public class EnumerableExtensionTest
ITest test3 = Substitute.For<ITest>();
ITest test4 = Substitute.For<ITest>();
IEnumerable<ITest> enumerable = new[] { test1, test2, test3, test4 };
IEnumerable<ITest> enumerable = [test1, test2, test3, test4];
enumerable.ForEach(t => t.DoSomething());

@ -12,15 +12,9 @@ namespace Test.LightweightIocContainer;
[TestFixture]
public class FluentFactoryRegistrationTest
{
public interface ITest
{
}
public interface ITest;
private class Test : ITest
{
}
private class Test : ITest;
private class TestByte : ITest
{
@ -130,10 +124,7 @@ public class FluentFactoryRegistrationTest
public MultitonScope Create();
}
public class MultitonScope
{
}
public class MultitonScope;
private IocContainer _iocContainer;

@ -12,22 +12,13 @@ namespace Test.LightweightIocContainer;
public class IgnoreConstructorAttributeTest
{
[AttributeUsage(AttributeTargets.Constructor)]
private class IgnoreAttribute : Attribute
{
}
private class IgnoreAttribute : Attribute;
[AttributeUsage(AttributeTargets.Class)]
private class InvalidIgnoreAttribute : Attribute
{
}
private class InvalidIgnoreAttribute : Attribute;
[UsedImplicitly]
public interface ITest
{
}
public interface ITest;
[UsedImplicitly]
private class TestIgnoreCtor : ITest

@ -11,29 +11,17 @@ namespace Test.LightweightIocContainer;
[TestFixture]
public class IocContainerInterfaceSegregationTest
{
private interface IBar
{
}
private interface IBar;
private interface IFoo
{
void ThrowFoo();
}
private interface IAnotherBar
{
}
private interface IAnotherBar;
private interface IAnotherFoo
{
}
private interface IAnotherFoo;
private interface IAnotherOne
{
}
private interface IAnotherOne;
[UsedImplicitly]
private class Foo : IFoo, IBar, IAnotherFoo, IAnotherBar, IAnotherOne

@ -20,16 +20,10 @@ public class IocContainerParameterRegistrationTest
}
[UsedImplicitly]
public interface IB
{
}
public interface IB;
[UsedImplicitly]
public interface IC
{
}
public interface IC;
[UsedImplicitly]
public interface ID
@ -64,10 +58,7 @@ public class IocContainerParameterRegistrationTest
}
[UsedImplicitly]
private class C : IC
{
}
private class C : IC;
[UsedImplicitly]
private class D : ID
@ -87,7 +78,6 @@ public class IocContainerParameterRegistrationTest
public IB B { get; }
public IC C { get; }
}
private IocContainer _iocContainer;
@ -97,7 +87,6 @@ public class IocContainerParameterRegistrationTest
[TearDown]
public void TearDown() => _iocContainer.Dispose();
[Test]
public void TestResolveOnlyRegistrationParameters()
{

@ -14,16 +14,10 @@ namespace Test.LightweightIocContainer;
public class IocContainerRecursionTest
{
[UsedImplicitly]
public interface IFoo
{
}
public interface IFoo;
[UsedImplicitly]
public interface IBar
{
}
public interface IBar;
[UsedImplicitly]
private class Foo : IFoo
@ -42,22 +36,13 @@ public class IocContainerRecursionTest
}
[UsedImplicitly]
public interface IA
{
}
public interface IA;
[UsedImplicitly]
public interface IB
{
}
public interface IB;
[UsedImplicitly]
public interface IC
{
}
public interface IC;
[UsedImplicitly]
private class A : IA
@ -78,10 +63,7 @@ public class IocContainerRecursionTest
}
[UsedImplicitly]
private class C : IC
{
}
private class C : IC;
[UsedImplicitly]
private class ATwoCtor : IA

@ -12,20 +12,11 @@ namespace Test.LightweightIocContainer;
[TestFixture]
public class IocContainerTest
{
private interface ITest
{
}
private interface IFoo
{
private interface ITest;
}
private class Test : ITest
{
private interface IFoo;
}
private class Test : ITest;
private class TestMultiton : ITest
{
@ -35,10 +26,7 @@ public class IocContainerTest
}
}
private class TestMultitonIntScope(int scope) : ITest
{
}
private class TestMultitonIntScope(int scope) : ITest;
[UsedImplicitly]
private class TestConstructor : ITest
@ -92,10 +80,7 @@ public class IocContainerTest
}
[UsedImplicitly]
private class Foo : IFoo
{
}
private class Foo : IFoo;
[UsedImplicitly]
private class FooConstructor : IFoo
@ -106,11 +91,7 @@ public class IocContainerTest
}
}
private class MultitonScope
{
}
private class MultitonScope;
private IocContainer _iocContainer;
@ -120,7 +101,6 @@ public class IocContainerTest
[TearDown]
public void TearDown() => _iocContainer.Dispose();
[Test]
public void TestInstall()
{

@ -14,10 +14,7 @@ public class MultipleMultitonRegistrationTest
private IocContainer _iocContainer;
[UsedImplicitly]
public interface ITest : IProvider
{
}
public interface ITest : IProvider;
public interface IProvider
{
@ -38,11 +35,7 @@ public class MultipleMultitonRegistrationTest
public void DoSomething(int number) => Number = number;
}
private class MultitonScope
{
}
private class MultitonScope;
[SetUp]
public void SetUp() => _iocContainer = new IocContainer();

@ -23,7 +23,6 @@ public class OnCreateTest
public void DoSomething() => throw new Exception();
public Task InitializeAsync() => throw new Exception();
}
[Test]
public void TestOnCreate()

@ -16,29 +16,17 @@ public class OpenGenericRegistrationTest
private IocContainer _iocContainer;
[UsedImplicitly]
public interface IConstraint
{
}
public interface IConstraint;
[UsedImplicitly]
public class Constraint : IConstraint
{
}
public class Constraint : IConstraint;
[UsedImplicitly]
[SuppressMessage("ReSharper", "UnusedTypeParameter")]
public interface ITest<T> where T : IConstraint, new()
{
}
public interface ITest<T> where T : IConstraint, new();
[UsedImplicitly]
public class Test<T> : ITest<T> where T : IConstraint, new()
{
}
public class Test<T> : ITest<T> where T : IConstraint, new();
[UsedImplicitly]
public class CtorTest<T> : ITest<T> where T : IConstraint, new()

@ -15,25 +15,13 @@ namespace Test.LightweightIocContainer;
[TestFixture]
public class RegistrationBaseTest
{
private interface ITest
{
}
private interface IFoo
{
}
private interface IBar
{
private interface ITest;
}
private interface IFoo;
private class Test : ITest
{
private interface IBar;
}
private class Test : ITest;
[UsedImplicitly]
private class Foo : IFoo
@ -44,11 +32,7 @@ public class RegistrationBaseTest
}
}
private class Bar : IBar
{
}
private class Bar : IBar;
[Test]
public void TestWithParameters()

@ -27,10 +27,7 @@ public class SingleTypeRegistrationTest
}
[UsedImplicitly]
public interface IBar
{
}
public interface IBar;
[UsedImplicitly]
private class Foo : IFoo
@ -41,10 +38,7 @@ public class SingleTypeRegistrationTest
}
[UsedImplicitly]
private class Bar : IBar
{
}
private class Bar : IBar;
[Test]
public void TestSingleTypeRegistrationWithFactoryMethod()

Loading…
Cancel
Save