#54: enabled nullable

- fix nullable warnings
pull/57/head
Simon G 4 years ago
parent b4cf096e96
commit b7d0db3c9b
  1. 2
      LightweightIocContainer/ActionExtension.cs
  2. 2
      LightweightIocContainer/EnumerableExtension.cs
  3. 11
      LightweightIocContainer/Exceptions/IocContainerException.cs
  4. 6
      LightweightIocContainer/Exceptions/NoMatchingConstructorFoundException.cs
  5. 12
      LightweightIocContainer/Factories/TypedFactory.cs
  6. 8
      LightweightIocContainer/GenericMethodCaller.cs
  7. 4
      LightweightIocContainer/Interfaces/Registrations/Fluent/IOnCreate.cs
  8. 2
      LightweightIocContainer/Interfaces/Registrations/Fluent/IWithFactory.cs
  9. 2
      LightweightIocContainer/Interfaces/Registrations/Fluent/IWithParameters.cs
  10. 2
      LightweightIocContainer/Interfaces/Registrations/ISingleTypeRegistration.cs
  11. 65
      LightweightIocContainer/IocContainer.cs
  12. 1
      LightweightIocContainer/LightweightIocContainer.csproj
  13. 112
      LightweightIocContainer/LightweightIocContainer.xml
  14. 2
      LightweightIocContainer/Registrations/MultipleMultitonRegistration.cs
  15. 14
      LightweightIocContainer/Registrations/MultipleRegistration.cs
  16. 4
      LightweightIocContainer/Registrations/RegistrationBase.cs
  17. 2
      LightweightIocContainer/Registrations/SingleTypeRegistration.cs
  18. 8
      LightweightIocContainer/Registrations/TypedRegistration.cs
  19. 4
      LightweightIocContainer/ResolvePlaceholders/InternalToBeResolvedPlaceholder.cs
  20. 2
      LightweightIocContainer/TypeExtension.cs
  21. 6
      LightweightIocContainer/Validation/IocValidator.cs

@ -15,7 +15,7 @@ namespace LightweightIocContainer
/// <typeparam name="T2">The <see cref="Type"/> of the given <see cref="Action{T2}"/>, has to implement <typeparamref name="T1"/></typeparam>
/// <param name="action">The given <see cref="Action{T2}"/> to convert</param>
/// <returns>An <see cref="Action{T1}"/> converted from the given <see cref="Action{T2}"/></returns>
public static Action<T1> Convert<T1, T2>(this Action<T2> action) where T1 : T2
public static Action<T1>? Convert<T1, T2>(this Action<T2>? action) where T1 : T2
{
if (action == null)
return null;

@ -39,7 +39,7 @@ namespace LightweightIocContainer
/// <param name="source">The given <see cref="IEnumerable{T}"/></param>
/// <param name="predicate">A function to test each element for a condition</param>
/// <returns>The first element of the <see cref="IEnumerable{T}"/> or a new instance of the given <see cref="Type"/> when no element is found</returns>
private static TSource TryGetFirst<TSource, TGiven>(this IEnumerable<TSource> source, Func<TSource, bool> predicate) where TGiven : TSource, new()
private static TSource TryGetFirst<TSource, TGiven>(this IEnumerable<TSource> source, Func<TSource, bool>? predicate) where TGiven : TSource, new()
{
try
{

@ -16,20 +16,15 @@ namespace LightweightIocContainer.Exceptions
/// <summary>
/// A base <see cref="Exception"/> for the <see cref="LightweightIocContainer"/>
/// </summary>
protected IocContainerException()
{
}
protected IocContainerException() => InnerExceptions = new List<Exception>();
/// <summary>
/// A base <see cref="Exception"/> for the <see cref="LightweightIocContainer"/>
/// </summary>
/// <param name="message">The message of the <see cref="Exception"/></param>
protected IocContainerException(string message)
: base(message)
{
}
: base(message) =>
InnerExceptions = new List<Exception>();
/// <summary>
/// A base <see cref="Exception"/> for the <see cref="LightweightIocContainer"/>

@ -4,7 +4,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace LightweightIocContainer.Exceptions
{
@ -17,12 +16,11 @@ namespace LightweightIocContainer.Exceptions
/// No matching constructor was found for the given or resolvable arguments
/// </summary>
/// <param name="type">The <see cref="Type"/> with no matching constructor</param>
/// <param name="exceptions">The inner exceptions of type <see cref="ConstructorNotMatchingException"/></param>
public NoMatchingConstructorFoundException(Type type, params ConstructorNotMatchingException[] exceptions)
public NoMatchingConstructorFoundException(Type type)
: base($"No matching constructor for {type} found.")
{
Type = type;
InnerExceptions = exceptions == null ? new List<Exception>() : exceptions.OfType<Exception>().ToList();
InnerExceptions = new List<Exception>();
}

@ -24,7 +24,7 @@ namespace LightweightIocContainer.Factories
/// The
/// </summary>
/// <param name="container">The current instance of the <see cref="IIocContainer"/></param>
public TypedFactory(IIocContainer container) => CreateFactory(container);
public TypedFactory(IIocContainer container) => Factory = CreateFactory(container);
/// <summary>
/// The implemented abstract typed factory/>
@ -36,7 +36,7 @@ namespace LightweightIocContainer.Factories
/// </summary>
/// <exception cref="InvalidFactoryRegistrationException">Factory registration is invalid</exception>
/// <exception cref="IllegalAbstractMethodCreationException">Creation of abstract methods are illegal in their current state</exception>
private void CreateFactory(IIocContainer container)
private TFactory CreateFactory(IIocContainer container)
{
Type factoryType = typeof(TFactory);
@ -92,7 +92,7 @@ namespace LightweightIocContainer.Factories
}
else
{
MethodInfo emptyArray = typeof(Array).GetMethod(nameof(Array.Empty))?.MakeGenericMethod(typeof(object));
MethodInfo? emptyArray = typeof(Array).GetMethod(nameof(Array.Empty))?.MakeGenericMethod(typeof(object));
generator.EmitCall(OpCodes.Call, emptyArray, null);
}
@ -102,7 +102,7 @@ namespace LightweightIocContainer.Factories
}
//if factory contains a method to clear multiton instances
MethodInfo multitonClearMethod = factoryType.GetMethods().FirstOrDefault(m => m.Name.Equals(CLEAR_MULTITON_INSTANCE_METHOD_NAME));
MethodInfo? multitonClearMethod = factoryType.GetMethods().FirstOrDefault(m => m.Name.Equals(CLEAR_MULTITON_INSTANCE_METHOD_NAME));
if (multitonClearMethod != null)
{
//create a method that looks like this
@ -113,7 +113,7 @@ namespace LightweightIocContainer.Factories
if (multitonClearMethod.IsGenericMethod)
{
Type typeToClear = multitonClearMethod.GetGenericArguments().FirstOrDefault();
Type? typeToClear = multitonClearMethod.GetGenericArguments().FirstOrDefault();
if (typeToClear == null)
throw new IllegalAbstractMethodCreationException("No Type to clear specified.", multitonClearMethod);
@ -136,7 +136,7 @@ namespace LightweightIocContainer.Factories
}
}
Factory = (TFactory) Activator.CreateInstance(typeBuilder.CreateTypeInfo().AsType(), container);
return (TFactory) Activator.CreateInstance(typeBuilder.CreateTypeInfo()?.AsType(), container);
}
}
}

@ -24,10 +24,10 @@ namespace LightweightIocContainer
/// <returns>The result of invoking the method</returns>
/// <exception cref="GenericMethodNotFoundException">Could not find the generic method</exception>
/// <exception cref="Exception">Any <see cref="Exception"/> thrown after invoking the generic method</exception>
public static object Call(object caller, string functionName, Type genericParameter, BindingFlags bindingFlags, params object[] parameters)
public static object Call(object caller, string functionName, Type genericParameter, BindingFlags bindingFlags, params object?[] parameters)
{
MethodInfo method = caller.GetType().GetMethod(functionName, bindingFlags);
MethodInfo genericMethod = method?.MakeGenericMethod(genericParameter);
MethodInfo? method = caller.GetType().GetMethod(functionName, bindingFlags);
MethodInfo? genericMethod = method?.MakeGenericMethod(genericParameter);
if (genericMethod == null)
throw new GenericMethodNotFoundException(functionName);
@ -52,7 +52,7 @@ namespace LightweightIocContainer
/// <returns>The result of invoking the method</returns>
/// <exception cref="GenericMethodNotFoundException">Could not find the generic method</exception>
/// <exception cref="Exception">Any <see cref="Exception"/> thrown after invoking the generic method</exception>
public static object CallPrivate(object caller, string functionName, Type genericParameter, params object[] parameters) =>
public static object CallPrivate(object caller, string functionName, Type genericParameter, params object?[] parameters) =>
Call(caller, functionName, genericParameter, BindingFlags.NonPublic | BindingFlags.Instance, parameters);
}
}

@ -16,7 +16,7 @@ namespace LightweightIocContainer.Interfaces.Registrations.Fluent
/// This <see cref="Action"/> is invoked when an instance of this type is created.
/// <para>Can be set in the <see cref="IIocInstaller"/> by calling <see cref="IOnCreate{TInterface, TImplementation}.OnCreate"/></para>
/// </summary>
internal Action<object> OnCreateAction { get; }
internal Action<object?>? OnCreateAction { get; }
}
/// <summary>
@ -31,6 +31,6 @@ namespace LightweightIocContainer.Interfaces.Registrations.Fluent
/// </summary>
/// <param name="action">The <see cref="Action{T}"/></param>
/// <returns>The current instance of this <see cref="ITypedRegistration{TInterface,TImplementation}"/></returns>
ITypedRegistration<TInterface, TImplementation> OnCreate(Action<TImplementation> action);
ITypedRegistration<TInterface, TImplementation> OnCreate(Action<TImplementation?> action);
}
}

@ -32,6 +32,6 @@ namespace LightweightIocContainer.Interfaces.Registrations.Fluent
/// <summary>
/// The Factory added with the <see cref="IWithFactory.WithFactory{TFactory}"/> method
/// </summary>
ITypedFactory Factory { get; }
ITypedFactory? Factory { get; }
}
}

@ -38,6 +38,6 @@ namespace LightweightIocContainer.Interfaces.Registrations.Fluent
/// An <see cref="Array"/> of parameters that are used to <see cref="IocContainer.Resolve{T}()"/> an instance of this <see cref="IRegistration.InterfaceType"/>
/// <para>Can be set in the <see cref="IIocInstaller"/> by calling <see cref="IWithParameters.WithParameters(object[])"/></para>
/// </summary>
object[] Parameters { get; }
object[]? Parameters { get; }
}
}

@ -15,7 +15,7 @@ namespace LightweightIocContainer.Interfaces.Registrations
/// <summary>
/// <see cref="Func{T,TResult}"/> that is invoked instead of creating an instance of this <see cref="Type"/> the default way
/// </summary>
Func<IResolver, T> FactoryMethod { get; }
Func<IResolver, T>? FactoryMethod { get; }
/// <summary>
/// Pass a <see cref="Func{T,TResult}"/> that will be invoked instead of creating an instance of this <see cref="Type"/> the default way

@ -7,7 +7,6 @@ using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using JetBrains.Annotations;
using LightweightIocContainer.Exceptions;
using LightweightIocContainer.Interfaces;
using LightweightIocContainer.Interfaces.Factories;
@ -26,8 +25,8 @@ namespace LightweightIocContainer
{
private readonly RegistrationFactory _registrationFactory;
private readonly List<(Type type, object instance)> _singletons = new();
private readonly List<(Type type, Type scope, ConditionalWeakTable<object, object> instances)> _multitons = new();
private readonly List<(Type type, object? instance)> _singletons = new();
private readonly List<(Type type, Type scope, ConditionalWeakTable<object, object?> instances)> _multitons = new();
/// <summary>
/// The main container that carries all the <see cref="IRegistration"/>s and can resolve all the types you'll ever want
@ -266,7 +265,7 @@ namespace LightweightIocContainer
/// <param name="resolveStack">The current resolve stack</param>
/// <returns>An instance of the given <see cref="Type"/></returns>
/// <exception cref="InternalResolveException">Could not find function <see cref="ResolveInternal{T}"/></exception>
internal object Resolve(Type type, object[] arguments, List<Type> resolveStack) =>
internal object Resolve(Type type, object?[]? arguments, List<Type>? resolveStack) =>
GenericMethodCaller.CallPrivate(this, nameof(ResolveInternal), type, arguments, resolveStack);
/// <summary>
@ -301,7 +300,7 @@ namespace LightweightIocContainer
/// <returns>An instance of the given registered <see cref="Type"/></returns>
/// <exception cref="TypeNotRegisteredException">The given <see cref="Type"/> is not registered in this <see cref="IocContainer"/></exception>
/// <exception cref="UnknownRegistrationException">The registration for the given <see cref="Type"/> has an unknown <see cref="Type"/></exception>
private T ResolveInternal<T>(object[] arguments, List<Type> resolveStack = null)
private T ResolveInternal<T>(object[]? arguments, List<Type>? resolveStack = null)
{
IRegistration registration = FindRegistration<T>() ?? throw new TypeNotRegisteredException(typeof(T));
@ -330,11 +329,11 @@ namespace LightweightIocContainer
/// <param name="arguments">The arguments to resolve</param>
/// <param name="resolveStack">The current resolve stack</param>
/// <returns>An existing or newly created singleton instance of the given <see cref="Type"/></returns>
private T GetOrCreateSingletonInstance<T>(IRegistration registration, object[] arguments, List<Type> resolveStack)
private T GetOrCreateSingletonInstance<T>(IRegistration registration, object[]? arguments, List<Type> resolveStack)
{
Type type = GetType<T>(registration);
object instance = TryGetSingletonInstance(type);
object? instance = TryGetSingletonInstance(type);
if (instance != null)
return (T) instance;
@ -350,7 +349,7 @@ namespace LightweightIocContainer
/// </summary>
/// <param name="type">The given <see cref="Type"/></param>
/// <returns>A singleton instance if existing for the given <see cref="Type"/>, null if not</returns>
private object TryGetSingletonInstance(Type type) => _singletons.FirstOrDefault(s => s.type == type).instance; //if a singleton instance exists return it
private object? TryGetSingletonInstance(Type type) => _singletons.FirstOrDefault(s => s.type == type).instance; //if a singleton instance exists return it
/// <summary>
/// Gets or creates a multiton instance of a given <see cref="Type"/>
@ -362,7 +361,7 @@ namespace LightweightIocContainer
/// <returns>An existing or newly created multiton instance of the given <see cref="Type"/></returns>
/// <exception cref="MultitonResolveException">No arguments given</exception>
/// <exception cref="MultitonResolveException">Scope argument not given</exception>
private T GetOrCreateMultitonInstance<T>(IMultitonRegistration registration, object[] arguments, List<Type> resolveStack)
private T GetOrCreateMultitonInstance<T>(IMultitonRegistration registration, object[]? arguments, List<Type> resolveStack)
{
if (arguments == null || !arguments.Any())
throw new MultitonResolveException("Can not resolve multiton without arguments.", typeof(T));
@ -375,7 +374,7 @@ namespace LightweightIocContainer
var instances = _multitons.FirstOrDefault(m => m.type == registration.ImplementationType && m.scope == registration.Scope).instances; //get instances for the given type and scope (use implementation type to resolve the correct instance for multiple multiton registrations as well)
if (instances != null)
{
if (instances.TryGetValue(scopeArgument, out object instance))
if (instances.TryGetValue(scopeArgument, out object? instance) && instance != null)
return (T) instance;
T createdInstance = CreateInstance<T>(registration, arguments, resolveStack);
@ -386,7 +385,7 @@ namespace LightweightIocContainer
T newInstance = CreateInstance<T>(registration, arguments, resolveStack);
ConditionalWeakTable<object, object> weakTable = new();
ConditionalWeakTable<object, object?> weakTable = new();
weakTable.Add(scopeArgument, newInstance);
_multitons.Add((registration.ImplementationType, registration.Scope, weakTable));
@ -402,7 +401,7 @@ namespace LightweightIocContainer
/// <param name="arguments">The constructor arguments</param>
/// <param name="resolveStack">The current resolve stack</param>
/// <returns>A newly created instance of the given <see cref="Type"/></returns>
private T CreateInstance<T>(IRegistration registration, object[] arguments, List<Type> resolveStack)
private T CreateInstance<T>(IRegistration registration, object[]? arguments, List<Type> resolveStack)
{
if (registration is IWithParametersInternal { Parameters: { } } registrationWithParameters)
arguments = UpdateArgumentsWithRegistrationParameters(registrationWithParameters, arguments);
@ -450,8 +449,11 @@ namespace LightweightIocContainer
/// <param name="registration">The <see cref="IRegistrationBase"/> of the given <see cref="Type"/></param>
/// <param name="arguments">The constructor arguments</param>
/// <returns>The argument list updated with the <see cref="IWithParametersInternal.Parameters"/></returns>
private object[] UpdateArgumentsWithRegistrationParameters(IWithParametersInternal registration, object[] arguments)
private object[]? UpdateArgumentsWithRegistrationParameters(IWithParametersInternal registration, object[]? arguments)
{
if (registration.Parameters == null)
return arguments;
if (arguments != null && arguments.Any()) //if more arguments were passed to resolve
{
int argumentsSize = registration.Parameters.Length + arguments.Length;
@ -495,10 +497,9 @@ namespace LightweightIocContainer
/// <param name="resolveStack">The current resolve stack</param>
/// <returns>An array of all needed constructor arguments to create the <see cref="Type"/></returns>
/// <exception cref="NoMatchingConstructorFoundException">No matching constructor was found for the given or resolvable arguments</exception>
[CanBeNull]
private object[] ResolveTypeCreationArguments(Type type, object[] arguments, List<Type> resolveStack)
private object[]? ResolveTypeCreationArguments(Type type, object[]? arguments, List<Type> resolveStack)
{
(bool result, List<object> parameters, NoMatchingConstructorFoundException exception) = TryGetTypeResolveStack(type, arguments, resolveStack);
(bool result, List<object>? parameters, NoMatchingConstructorFoundException? exception) = TryGetTypeResolveStack(type, arguments, resolveStack);
if (result)
{
@ -534,15 +535,15 @@ namespace LightweightIocContainer
/// <para>parameters: The parameters needed to resolve the given <see cref="Type"/></para>
/// <para>exception: A <see cref="NoMatchingConstructorFoundException"/> if no matching constructor was found</para>
/// </returns>
private (bool result, List<object> parameters, NoMatchingConstructorFoundException exception) TryGetTypeResolveStack(Type type, object[] arguments, List<Type> resolveStack)
private (bool result, List<object>? parameters, NoMatchingConstructorFoundException? exception) TryGetTypeResolveStack(Type type, object[]? arguments, List<Type> resolveStack)
{
NoMatchingConstructorFoundException noMatchingConstructorFoundException = null;
NoMatchingConstructorFoundException? noMatchingConstructorFoundException = null;
//find best ctor
List<ConstructorInfo> sortedConstructors = TryGetSortedConstructors(type);
foreach (ConstructorInfo constructor in sortedConstructors)
{
(bool result, List<object> parameters, List<ConstructorNotMatchingException> exceptions) = TryGetConstructorResolveStack(constructor, arguments, resolveStack);
(bool result, List<object>? parameters, List<ConstructorNotMatchingException>? exceptions) = TryGetConstructorResolveStack(constructor, arguments, resolveStack);
if (result)
return (true, parameters, null);
@ -566,7 +567,7 @@ namespace LightweightIocContainer
/// <para>parameters: The parameters needed to resolve the given <see cref="Type"/></para>
/// <para>exception: A List of <see cref="ConstructorNotMatchingException"/>s if the constructor is not matching</para>
/// </returns>
private (bool result, List<object> parameters, List<ConstructorNotMatchingException> exceptions) TryGetConstructorResolveStack(ConstructorInfo constructor, object[] arguments, List<Type> resolveStack)
private (bool result, List<object>? parameters, List<ConstructorNotMatchingException>? exceptions) TryGetConstructorResolveStack(ConstructorInfo constructor, object[]? arguments, List<Type> resolveStack)
{
List<ParameterInfo> constructorParameters = constructor.GetParameters().ToList();
if (!constructorParameters.Any())
@ -575,7 +576,7 @@ namespace LightweightIocContainer
List<ConstructorNotMatchingException> exceptions = new();
List<object> parameters = new();
List<object> passedArguments = null;
List<object>? passedArguments = null;
if (arguments != null)
passedArguments = new List<object>(arguments);
@ -602,21 +603,21 @@ namespace LightweightIocContainer
Type registeredType = GetTypeNonGeneric(parameter.ParameterType, registration);
object singletonInstance = TryGetSingletonInstance(registeredType);
object? singletonInstance = TryGetSingletonInstance(registeredType);
if (singletonInstance != null)
fittingArgument = singletonInstance;
else
{
object[] argumentsForRegistration = null;
object[]? argumentsForRegistration = null;
if (registration is IWithParametersInternal { Parameters: { } } registrationWithParameters)
argumentsForRegistration = UpdateArgumentsWithRegistrationParameters(registrationWithParameters, null);
(bool result, List<object> parametersToResolve, NoMatchingConstructorFoundException exception) =
(bool result, List<object>? parametersToResolve, NoMatchingConstructorFoundException? exception) =
TryGetTypeResolveStack(registeredType, argumentsForRegistration, internalResolveStack);
if (result)
fittingArgument = new InternalToBeResolvedPlaceholder(registeredType, parametersToResolve);
else
else if (exception != null)
exceptions.Add(new ConstructorNotMatchingException(constructor, exception));
}
}
@ -648,18 +649,16 @@ namespace LightweightIocContainer
/// </summary>
/// <typeparam name="T">The given <see cref="Type"/></typeparam>
/// <returns>The <see cref="IRegistration"/> for the given <see cref="Type"/></returns>
[CanBeNull]
private IRegistration FindRegistration<T>() => FindRegistration(typeof(T));
private IRegistration? FindRegistration<T>() => FindRegistration(typeof(T));
/// <summary>
/// Find the <see cref="IRegistration"/> for the given <see cref="Type"/>
/// </summary>
/// <param name="type">The given <see cref="Type"/></param>
/// <returns>The <see cref="IRegistration"/> for the given <see cref="Type"/></returns>
[CanBeNull]
private IRegistration FindRegistration(Type type)
private IRegistration? FindRegistration(Type type)
{
IRegistration registration = Registrations.FirstOrDefault(r => r.InterfaceType == type);
IRegistration? registration = Registrations.FirstOrDefault(r => r.InterfaceType == type);
if (registration != null)
return registration;
@ -721,7 +720,7 @@ namespace LightweightIocContainer
/// <typeparam name="T">The given <see cref="Type"/></typeparam>
/// <returns>The new resolve stack</returns>
/// <exception cref="CircularDependencyException">A circular dependency was detected</exception>
private List<Type> CheckForCircularDependencies<T>(List<Type> resolveStack) => CheckForCircularDependencies(typeof(T), resolveStack);
private List<Type> CheckForCircularDependencies<T>(List<Type>? resolveStack) => CheckForCircularDependencies(typeof(T), resolveStack);
/// <summary>
/// Check the given resolve stack for circular dependencies
@ -730,7 +729,7 @@ namespace LightweightIocContainer
/// <param name="resolveStack">The given resolve stack</param>
/// <returns>The new resolve stack</returns>
/// <exception cref="CircularDependencyException">A circular dependency was detected</exception>
private List<Type> CheckForCircularDependencies(Type type, List<Type> resolveStack)
private List<Type> CheckForCircularDependencies(Type type, List<Type>? resolveStack)
{
if (resolveStack == null) //first resolve call
resolveStack = new List<Type> {type}; //create new stack and add the currently resolving type to the stack
@ -748,7 +747,7 @@ namespace LightweightIocContainer
/// <typeparam name="T">The <see cref="Type"/> to clear the multiton instances</typeparam>
public void ClearMultitonInstances<T>()
{
IRegistration registration = FindRegistration<T>();
IRegistration? registration = FindRegistration<T>();
if (registration is not IMultitonRegistration multitonRegistration)
return;

@ -14,6 +14,7 @@
<FileVersion>3.0.0.0</FileVersion>
<PackageLicenseFile>LICENSE.md</PackageLicenseFile>
<PackageVersion>3.0.0-beta</PackageVersion>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|netstandard2.0|AnyCPU'">

@ -213,12 +213,11 @@
No matching constructor was found for the given or resolvable arguments
</summary>
</member>
<member name="M:LightweightIocContainer.Exceptions.NoMatchingConstructorFoundException.#ctor(System.Type,LightweightIocContainer.Exceptions.ConstructorNotMatchingException[])">
<member name="M:LightweightIocContainer.Exceptions.NoMatchingConstructorFoundException.#ctor(System.Type)">
<summary>
No matching constructor was found for the given or resolvable arguments
</summary>
<param name="type">The <see cref="P:LightweightIocContainer.Exceptions.NoMatchingConstructorFoundException.Type"/> with no matching constructor</param>
<param name="exceptions">The inner exceptions of type <see cref="T:LightweightIocContainer.Exceptions.ConstructorNotMatchingException"/></param>
</member>
<member name="P:LightweightIocContainer.Exceptions.NoMatchingConstructorFoundException.Type">
<summary>
@ -946,6 +945,14 @@
<returns>An instance of the given <see cref="T:System.Type"/></returns>
<exception cref="T:LightweightIocContainer.Exceptions.InternalResolveException">Could not find function <see cref="M:LightweightIocContainer.IocContainer.ResolveInternal``1(System.Object[],System.Collections.Generic.List{System.Type})"/></exception>
</member>
<member name="M:LightweightIocContainer.IocContainer.Resolve(LightweightIocContainer.ResolvePlaceholders.InternalToBeResolvedPlaceholder,System.Collections.Generic.List{System.Type})">
<summary>
Recursively resolve a <see cref="T:System.Type"/> with the given parameters for an <see cref="T:LightweightIocContainer.ResolvePlaceholders.InternalToBeResolvedPlaceholder"/>
</summary>
<param name="toBeResolvedPlaceholder">The <see cref="T:LightweightIocContainer.ResolvePlaceholders.InternalToBeResolvedPlaceholder"/> that includes the type and resolve stack</param>
<param name="resolveStack">The current resolve stack</param>
<returns>A recursively resolved instance of the given <see cref="T:System.Type"/></returns>
</member>
<member name="M:LightweightIocContainer.IocContainer.ResolveInternal``1(System.Object[],System.Collections.Generic.List{System.Type})">
<summary>
Gets an instance of a given registered <see cref="T:System.Type"/>
@ -967,6 +974,13 @@
<param name="resolveStack">The current resolve stack</param>
<returns>An existing or newly created singleton instance of the given <see cref="T:System.Type"/></returns>
</member>
<member name="M:LightweightIocContainer.IocContainer.TryGetSingletonInstance(System.Type)">
<summary>
Try to get an existing singleton instance for a given <see cref="T:System.Type"/>
</summary>
<param name="type">The given <see cref="T:System.Type"/></param>
<returns>A singleton instance if existing for the given <see cref="T:System.Type"/>, null if not</returns>
</member>
<member name="M:LightweightIocContainer.IocContainer.GetOrCreateMultitonInstance``1(LightweightIocContainer.Interfaces.Registrations.IMultitonRegistration,System.Object[],System.Collections.Generic.List{System.Type})">
<summary>
Gets or creates a multiton instance of a given <see cref="T:System.Type"/>
@ -1007,6 +1021,90 @@
<returns>An array of all needed constructor arguments to create the <see cref="T:System.Type"/></returns>
<exception cref="T:LightweightIocContainer.Exceptions.NoMatchingConstructorFoundException">No matching constructor was found for the given or resolvable arguments</exception>
</member>
<member name="M:LightweightIocContainer.IocContainer.TryGetTypeResolveStack(System.Type,System.Object[],System.Collections.Generic.List{System.Type})">
<summary>
Try to get the resolve stack for a given <see cref="T:System.Type"/>
</summary>
<param name="type">The given <see cref="T:System.Type"/></param>
<param name="arguments">The given arguments</param>
<param name="resolveStack">The current resolve stack</param>
<returns>
<para>result: True if successful, false if not</para>
<para>parameters: The parameters needed to resolve the given <see cref="T:System.Type"/></para>
<para>exception: A <see cref="T:LightweightIocContainer.Exceptions.NoMatchingConstructorFoundException"/> if no matching constructor was found</para>
</returns>
</member>
<member name="M:LightweightIocContainer.IocContainer.TryGetConstructorResolveStack(System.Reflection.ConstructorInfo,System.Object[],System.Collections.Generic.List{System.Type})">
<summary>
Try to get the resolve stack for a given constructor
</summary>
<param name="constructor">The <see cref="T:System.Reflection.ConstructorInfo"/> for the given constructor</param>
<param name="arguments">The given arguments</param>
<param name="resolveStack">The current resolve stack</param>
<returns>
<para>result: True if successful, false if not</para>
<para>parameters: The parameters needed to resolve the given <see cref="T:System.Type"/></para>
<para>exception: A List of <see cref="T:LightweightIocContainer.Exceptions.ConstructorNotMatchingException"/>s if the constructor is not matching</para>
</returns>
</member>
<member name="M:LightweightIocContainer.IocContainer.FindRegistration``1">
<summary>
Find the <see cref="T:LightweightIocContainer.Interfaces.Registrations.IRegistration"/> for the given <see cref="T:System.Type"/>
</summary>
<typeparam name="T">The given <see cref="T:System.Type"/></typeparam>
<returns>The <see cref="T:LightweightIocContainer.Interfaces.Registrations.IRegistration"/> for the given <see cref="T:System.Type"/></returns>
</member>
<member name="M:LightweightIocContainer.IocContainer.FindRegistration(System.Type)">
<summary>
Find the <see cref="T:LightweightIocContainer.Interfaces.Registrations.IRegistration"/> for the given <see cref="T:System.Type"/>
</summary>
<param name="type">The given <see cref="T:System.Type"/></param>
<returns>The <see cref="T:LightweightIocContainer.Interfaces.Registrations.IRegistration"/> for the given <see cref="T:System.Type"/></returns>
</member>
<member name="M:LightweightIocContainer.IocContainer.TryGetSortedConstructors(System.Type)">
<summary>
Try to get the sorted constructors for the given <see cref="T:System.Type"/>
</summary>
<param name="type">The given <see cref="T:System.Type"/></param>
<returns>A list of sorted <see cref="T:System.Reflection.ConstructorInfo"/> for the given <see cref="T:System.Type"/></returns>
<exception cref="T:LightweightIocContainer.Exceptions.NoPublicConstructorFoundException">No public constructor was found for the given <see cref="T:System.Type"/></exception>
</member>
<member name="M:LightweightIocContainer.IocContainer.GetType``1(LightweightIocContainer.Interfaces.Registrations.IRegistration)">
<summary>
Get the implementation type for the given <see cref="T:LightweightIocContainer.Interfaces.Registrations.IRegistration"/>
</summary>
<param name="registration">The given <see cref="T:LightweightIocContainer.Interfaces.Registrations.IRegistration"/></param>
<typeparam name="T">The given <see cref="T:System.Type"/> of the interface</typeparam>
<returns>The implementation <see cref="T:System.Type"/> for the given <see cref="T:LightweightIocContainer.Interfaces.Registrations.IRegistration"/></returns>
<exception cref="T:LightweightIocContainer.Exceptions.UnknownRegistrationException">Unknown <see cref="T:LightweightIocContainer.Interfaces.Registrations.IRegistration"/> passed</exception>
</member>
<member name="M:LightweightIocContainer.IocContainer.GetTypeNonGeneric(System.Type,LightweightIocContainer.Interfaces.Registrations.IRegistration)">
<summary>
Non generic method to get the implementation type for the given <see cref="T:LightweightIocContainer.Interfaces.Registrations.IRegistration"/>
</summary>
<param name="type">The given <see cref="T:System.Type"/> of the interface</param>
<param name="registration">The given <see cref="T:LightweightIocContainer.Interfaces.Registrations.IRegistration"/></param>
<returns>The implementation <see cref="T:System.Type"/> for the given <see cref="T:LightweightIocContainer.Interfaces.Registrations.IRegistration"/></returns>
<exception cref="T:LightweightIocContainer.Exceptions.UnknownRegistrationException">Unknown <see cref="T:LightweightIocContainer.Interfaces.Registrations.IRegistration"/> passed</exception>
</member>
<member name="M:LightweightIocContainer.IocContainer.CheckForCircularDependencies``1(System.Collections.Generic.List{System.Type})">
<summary>
Check the given resolve stack for circular dependencies
</summary>
<param name="resolveStack">The given resolve stack</param>
<typeparam name="T">The given <see cref="T:System.Type"/></typeparam>
<returns>The new resolve stack</returns>
<exception cref="T:LightweightIocContainer.Exceptions.CircularDependencyException">A circular dependency was detected</exception>
</member>
<member name="M:LightweightIocContainer.IocContainer.CheckForCircularDependencies(System.Type,System.Collections.Generic.List{System.Type})">
<summary>
Check the given resolve stack for circular dependencies
</summary>
<param name="type">The given <see cref="T:System.Type"/></param>
<param name="resolveStack">The given resolve stack</param>
<returns>The new resolve stack</returns>
<exception cref="T:LightweightIocContainer.Exceptions.CircularDependencyException">A circular dependency was detected</exception>
</member>
<member name="M:LightweightIocContainer.IocContainer.ClearMultitonInstances``1">
<summary>
Clear the multiton instances of the given <see cref="T:System.Type"/> from the registered multitons list
@ -1514,6 +1612,16 @@
An internal placeholder that is used to hold types that need to be resolved during the resolving process
</summary>
</member>
<member name="P:LightweightIocContainer.ResolvePlaceholders.InternalToBeResolvedPlaceholder.ResolvedType">
<summary>
The <see cref="T:System.Type"/> to be resolved
</summary>
</member>
<member name="P:LightweightIocContainer.ResolvePlaceholders.InternalToBeResolvedPlaceholder.Parameters">
<summary>
The parameters needed to resolve the <see cref="P:LightweightIocContainer.ResolvePlaceholders.InternalToBeResolvedPlaceholder.ResolvedType"/>
</summary>
</member>
<member name="M:LightweightIocContainer.TypeExtension.GetDefault(System.Type)">
<summary>
Returns the default value for a given <see cref="T:System.Type"/>

@ -45,7 +45,7 @@ namespace LightweightIocContainer.Registrations
/// </summary>
/// <param name="action">The <see cref="Action{T}"/></param>
/// <returns>The current instance of this <see cref="ITypedRegistration{TInterface,TImplementation}"/></returns>
public override ITypedRegistration<TInterface1, TImplementation> OnCreate(Action<TImplementation> action)
public override ITypedRegistration<TInterface1, TImplementation> OnCreate(Action<TImplementation?> action)
{
foreach (IRegistration registration in Registrations)
{

@ -24,10 +24,8 @@ namespace LightweightIocContainer.Registrations
/// <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)
{
}
: base(interfaceType1, implementationType, lifestyle, container) =>
Registrations = new List<IRegistration>();
/// <summary>
/// A <see cref="List{T}"/> of <see cref="IRegistration"/>s that are registered within this <see cref="MultipleRegistration{TInterface1,TInterface2}"/>
@ -66,7 +64,7 @@ namespace LightweightIocContainer.Registrations
/// </summary>
/// <param name="action">The <see cref="Action{T}"/></param>
/// <returns>The current instance of this <see cref="ITypedRegistration{TInterface,TImplementation}"/></returns>
public override ITypedRegistration<TInterface1, TImplementation> OnCreate(Action<TImplementation> action)
public override ITypedRegistration<TInterface1, TImplementation> OnCreate(Action<TImplementation?> action)
{
foreach (IRegistration registration in Registrations)
{
@ -114,7 +112,7 @@ namespace LightweightIocContainer.Registrations
/// </summary>
/// <param name="action">The <see cref="Action{T}"/></param>
/// <returns>The current instance of this <see cref="ITypedRegistration{TInterface,TImplementation}"/></returns>
public override ITypedRegistration<TInterface1, TImplementation> OnCreate(Action<TImplementation> action)
public override ITypedRegistration<TInterface1, TImplementation> OnCreate(Action<TImplementation?> action)
{
foreach (IRegistration registration in Registrations)
{
@ -167,7 +165,7 @@ namespace LightweightIocContainer.Registrations
/// </summary>
/// <param name="action">The <see cref="Action{T}"/></param>
/// <returns>The current instance of this <see cref="ITypedRegistration{TInterface,TImplementation}"/></returns>
public override ITypedRegistration<TInterface1, TImplementation> OnCreate(Action<TImplementation> action)
public override ITypedRegistration<TInterface1, TImplementation> OnCreate(Action<TImplementation?> action)
{
foreach (IRegistration registration in Registrations)
{
@ -225,7 +223,7 @@ namespace LightweightIocContainer.Registrations
/// </summary>
/// <param name="action">The <see cref="Action{T}"/></param>
/// <returns>The current instance of this <see cref="ITypedRegistration{TInterface,TImplementation}"/></returns>
public override ITypedRegistration<TInterface1, TImplementation> OnCreate(Action<TImplementation> action)
public override ITypedRegistration<TInterface1, TImplementation> OnCreate(Action<TImplementation?> action)
{
foreach (IRegistration registration in Registrations)
{

@ -48,12 +48,12 @@ namespace LightweightIocContainer.Registrations
/// An <see cref="Array"/> of parameters that are used to <see cref="IocContainer.Resolve{T}()"/> an instance of this <see cref="IRegistration.InterfaceType"/>
/// <para>Can be set in the <see cref="IIocInstaller"/> by calling <see cref="WithParameters(object[])"/></para>
/// </summary>
public object[] Parameters { get; private set; }
public object[]? Parameters { get; private set; }
/// <summary>
/// The Factory added with the <see cref="WithFactory{TFactory}"/> method
/// </summary>
public ITypedFactory Factory { get; private set; }
public ITypedFactory? Factory { get; private set; }
/// <summary>
/// Pass parameters that will be used to <see cref="IocContainer.Resolve{T}()"/> an instance of this <see cref="IRegistration.InterfaceType"/>

@ -29,7 +29,7 @@ namespace LightweightIocContainer.Registrations
/// <summary>
/// <see cref="Func{T,TResult}"/> that is invoked instead of creating an instance of this <see cref="Type"/> the default way
/// </summary>
public Func<IResolver, T> FactoryMethod { get; private set; }
public Func<IResolver, T>? FactoryMethod { get; private set; }
/// <summary>
/// Pass a <see cref="Func{T,TResult}"/> that will be invoked instead of creating an instance of this <see cref="Type"/> the default way

@ -35,22 +35,22 @@ namespace LightweightIocContainer.Registrations
/// This <see cref="Action"/> is invoked when an instance of this type is created.
/// <para>Can be set in the <see cref="IIocInstaller"/> by calling <see cref="IOnCreate{TInterface,TImplementation}.OnCreate"/></para>
/// </summary>
private Action<object> OnCreateAction { get; set; }
private Action<object?>? OnCreateAction { get; set; }
/// <summary>
/// This <see cref="Action"/> is invoked when an instance of this type is created.
/// <para>Can be set in the <see cref="IIocInstaller"/> by calling <see cref="IOnCreate{TInterface,TImplementation}.OnCreate"/></para>
/// </summary>
Action<object> IOnCreate.OnCreateAction => OnCreateAction;
Action<object?>? IOnCreate.OnCreateAction => OnCreateAction;
/// <summary>
/// Pass an <see cref="Action{T}"/> that will be invoked when an instance of this type is created
/// </summary>
/// <param name="action">The <see cref="Action{T}"/></param>
/// <returns>The current instance of this <see cref="ITypedRegistration{TInterface,TImplementation}"/></returns>
public virtual ITypedRegistration<TInterface, TImplementation> OnCreate(Action<TImplementation> action)
public virtual ITypedRegistration<TInterface, TImplementation> OnCreate(Action<TImplementation?> action)
{
OnCreateAction = a => action((TImplementation) a);
OnCreateAction = a => action((TImplementation?) a);
return this;
}
}

@ -12,7 +12,7 @@ namespace LightweightIocContainer.ResolvePlaceholders
/// </summary>
internal class InternalToBeResolvedPlaceholder
{
public InternalToBeResolvedPlaceholder(Type resolvedType, List<object> parameters)
public InternalToBeResolvedPlaceholder(Type resolvedType, List<object>? parameters)
{
ResolvedType = resolvedType;
Parameters = parameters;
@ -26,6 +26,6 @@ namespace LightweightIocContainer.ResolvePlaceholders
/// <summary>
/// The parameters needed to resolve the <see cref="ResolvedType"/>
/// </summary>
public List<object> Parameters { get; }
public List<object>? Parameters { get; }
}
}

@ -13,6 +13,6 @@ namespace LightweightIocContainer
/// </summary>
/// <param name="type">The given <see cref="Type"/></param>
/// <returns>The default value for the given <see cref="Type"/></returns>
public static object GetDefault(this Type type) => type.IsValueType ? Activator.CreateInstance(type) : null;
public static object? GetDefault(this Type type) => type.IsValueType ? Activator.CreateInstance(type) : null;
}
}

@ -16,7 +16,7 @@ namespace LightweightIocContainer.Validation
public class IocValidator
{
private readonly IocContainer _iocContainer;
private readonly List<(Type type, object parameter)> _parameters;
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
@ -25,7 +25,7 @@ namespace LightweightIocContainer.Validation
public IocValidator(IocContainer iocContainer)
{
_iocContainer = iocContainer;
_parameters = new List<(Type, object)>();
_parameters = new List<(Type, object?)>();
}
/// <summary>
@ -67,7 +67,7 @@ namespace LightweightIocContainer.Validation
throw new AggregateException("Validation failed.", validationExceptions);
}
private void TryResolve(Type type, object[] arguments, List<Exception> validationExceptions)
private void TryResolve(Type type, object?[]? arguments, List<Exception> validationExceptions)
{
try
{

Loading…
Cancel
Save