From fb57e94fb68c110ee144638d9e0ccbc404839cd7 Mon Sep 17 00:00:00 2001 From: Simon Gockner Date: Fri, 7 Jun 2019 14:40:32 +0200 Subject: [PATCH] - remove IIocContainer backing field - pass IIocContainer as a parameter to CreateFactory() --- .../Registrations/TypedFactoryRegistration.cs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/LightweightIocContainer/Registrations/TypedFactoryRegistration.cs b/LightweightIocContainer/Registrations/TypedFactoryRegistration.cs index 5bf24c1..0e00fba 100644 --- a/LightweightIocContainer/Registrations/TypedFactoryRegistration.cs +++ b/LightweightIocContainer/Registrations/TypedFactoryRegistration.cs @@ -20,16 +20,12 @@ namespace LightweightIocContainer.Registrations /// The type of the abstract typed factory public class TypedFactoryRegistration : ITypedFactoryRegistration { - private readonly IIocContainer _container; - public TypedFactoryRegistration(Type factoryType, IIocContainer container) { - _container = container; - InterfaceType = factoryType; Name = $"{InterfaceType.Name}"; - CreateFactory(); + CreateFactory(container); } /// @@ -52,7 +48,7 @@ namespace LightweightIocContainer.Registrations /// Creates the factory from the given abstract factory type /// /// Factory registration is invalid - private void CreateFactory() + private void CreateFactory(IIocContainer container) { var createMethods = InterfaceType.GetMethods().Where(m => m.ReturnType != typeof(void)).ToList(); if (!createMethods.Any()) @@ -127,7 +123,7 @@ namespace LightweightIocContainer.Registrations generator.Emit(OpCodes.Ret); } - Factory.Factory = (TFactory) Activator.CreateInstance(typeBuilder.CreateTypeInfo().AsType(), _container); + Factory.Factory = (TFactory) Activator.CreateInstance(typeBuilder.CreateTypeInfo().AsType(), container); } } } \ No newline at end of file