From c4361560994df97071c1bbd4ea6f321b6b3e49d3 Mon Sep 17 00:00:00 2001 From: "Simon G." Date: Tue, 29 Oct 2024 10:50:05 +0100 Subject: [PATCH] #60: correctly add singleton instance to list --- LightweightIocContainer/IocContainer.cs | 2 +- .../InternalFactoryMethodPlaceholder.cs | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/LightweightIocContainer/IocContainer.cs b/LightweightIocContainer/IocContainer.cs index 2ab8847..7ed4cd6 100644 --- a/LightweightIocContainer/IocContainer.cs +++ b/LightweightIocContainer/IocContainer.cs @@ -284,7 +284,7 @@ public class IocContainer : IIocContainer, IIocResolver { T instance => instance, InternalToBeResolvedPlaceholder toBeResolvedPlaceholder => ResolvePlaceholder(toBeResolvedPlaceholder), - InternalFactoryMethodPlaceholder factoryMethodPlaceholder => factoryMethodPlaceholder.FactoryMethod(this), + InternalFactoryMethodPlaceholder factoryMethodPlaceholder => CreateInstance(factoryMethodPlaceholder.SingleTypeRegistration, null), _ => throw new InternalResolveException("Resolve returned wrong type.") }; diff --git a/LightweightIocContainer/ResolvePlaceholders/InternalFactoryMethodPlaceholder.cs b/LightweightIocContainer/ResolvePlaceholders/InternalFactoryMethodPlaceholder.cs index 3b6c3d5..eb1c5f7 100644 --- a/LightweightIocContainer/ResolvePlaceholders/InternalFactoryMethodPlaceholder.cs +++ b/LightweightIocContainer/ResolvePlaceholders/InternalFactoryMethodPlaceholder.cs @@ -2,7 +2,6 @@ // Created: 2021-12-14 // Copyright(c) 2021 SimonG. All Rights Reserved. -using LightweightIocContainer.Interfaces; using LightweightIocContainer.Interfaces.Registrations; namespace LightweightIocContainer.ResolvePlaceholders; @@ -15,7 +14,7 @@ internal class InternalFactoryMethodPlaceholder : IInternalToBeResolvedPlaceh public InternalFactoryMethodPlaceholder(ISingleTypeRegistration singleTypeRegistration) { ResolvedType = singleTypeRegistration.InterfaceType; - FactoryMethod = singleTypeRegistration.FactoryMethod ?? throw new InvalidOperationException("Factory method can't be null."); + SingleTypeRegistration = singleTypeRegistration; } /// @@ -24,7 +23,7 @@ internal class InternalFactoryMethodPlaceholder : IInternalToBeResolvedPlaceh public Type ResolvedType { get; } /// - /// The + /// The /// - public Func FactoryMethod { get; } + public ISingleTypeRegistration SingleTypeRegistration { get; } } \ No newline at end of file