#60: correctly add singleton instance to list

master
Simon G. 1 year ago
parent c4d67e0ba3
commit c436156099
Signed by: SimonG
GPG Key ID: 0B82B964BA536523
  1. 2
      LightweightIocContainer/IocContainer.cs
  2. 7
      LightweightIocContainer/ResolvePlaceholders/InternalFactoryMethodPlaceholder.cs

@ -284,7 +284,7 @@ public class IocContainer : IIocContainer, IIocResolver
{ {
T instance => instance, T instance => instance,
InternalToBeResolvedPlaceholder toBeResolvedPlaceholder => ResolvePlaceholder<T>(toBeResolvedPlaceholder), InternalToBeResolvedPlaceholder toBeResolvedPlaceholder => ResolvePlaceholder<T>(toBeResolvedPlaceholder),
InternalFactoryMethodPlaceholder<T> factoryMethodPlaceholder => factoryMethodPlaceholder.FactoryMethod(this), InternalFactoryMethodPlaceholder<T> factoryMethodPlaceholder => CreateInstance<T>(factoryMethodPlaceholder.SingleTypeRegistration, null),
_ => throw new InternalResolveException("Resolve returned wrong type.") _ => throw new InternalResolveException("Resolve returned wrong type.")
}; };

@ -2,7 +2,6 @@
// Created: 2021-12-14 // Created: 2021-12-14
// Copyright(c) 2021 SimonG. All Rights Reserved. // Copyright(c) 2021 SimonG. All Rights Reserved.
using LightweightIocContainer.Interfaces;
using LightweightIocContainer.Interfaces.Registrations; using LightweightIocContainer.Interfaces.Registrations;
namespace LightweightIocContainer.ResolvePlaceholders; namespace LightweightIocContainer.ResolvePlaceholders;
@ -15,7 +14,7 @@ internal class InternalFactoryMethodPlaceholder<T> : IInternalToBeResolvedPlaceh
public InternalFactoryMethodPlaceholder(ISingleTypeRegistration<T> singleTypeRegistration) public InternalFactoryMethodPlaceholder(ISingleTypeRegistration<T> singleTypeRegistration)
{ {
ResolvedType = singleTypeRegistration.InterfaceType; ResolvedType = singleTypeRegistration.InterfaceType;
FactoryMethod = singleTypeRegistration.FactoryMethod ?? throw new InvalidOperationException("Factory method can't be null."); SingleTypeRegistration = singleTypeRegistration;
} }
/// <summary> /// <summary>
@ -24,7 +23,7 @@ internal class InternalFactoryMethodPlaceholder<T> : IInternalToBeResolvedPlaceh
public Type ResolvedType { get; } public Type ResolvedType { get; }
/// <summary> /// <summary>
/// The <see cref="ISingleTypeRegistration{T}.FactoryMethod"/> /// The <see cref="ISingleTypeRegistration{T}"/>
/// </summary> /// </summary>
public Func<IIocResolver, T> FactoryMethod { get; } public ISingleTypeRegistration<T> SingleTypeRegistration { get; }
} }
Loading…
Cancel
Save