From fd28c1012f6eb7cf8729e3c91feb5e12ae0ae496 Mon Sep 17 00:00:00 2001 From: Bernhard Richter Date: Mon, 5 Aug 2019 13:22:03 +0200 Subject: [PATCH] fixes #476 --- src/LightInject.Tests/Issue476.cs | 21 +++++++++++++++++++++ src/LightInject/LightInject.cs | 7 ++++--- 2 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 src/LightInject.Tests/Issue476.cs diff --git a/src/LightInject.Tests/Issue476.cs b/src/LightInject.Tests/Issue476.cs new file mode 100644 index 00000000..e4073607 --- /dev/null +++ b/src/LightInject.Tests/Issue476.cs @@ -0,0 +1,21 @@ +using LightInject.SampleLibrary; +using Xunit; + +namespace LightInject.Tests +{ + public class Issue476 + { + [Fact] + public void ShouldHandleIssue476() + { + var container = new ServiceContainer(); + + container.Register(factory => new Foo()); + container.GetInstance(); + + var clonedContainer = container.Clone(); + + clonedContainer.GetInstance(); // IndexOutOfRangeException + } + } +} \ No newline at end of file diff --git a/src/LightInject/LightInject.cs b/src/LightInject/LightInject.cs index 144b1903..c72755fa 100644 --- a/src/LightInject/LightInject.cs +++ b/src/LightInject/LightInject.cs @@ -2471,7 +2471,6 @@ private ServiceContainer( ServiceRegistry constructorDependencyFactories, ServiceRegistry propertyDependencyFactories, ServiceRegistry availableServices, - ServiceRegistry> emitters, Storage decorators, Storage overrides, Storage factoryRules, @@ -2495,7 +2494,6 @@ private ServiceContainer( this.constructorDependencyFactories = constructorDependencyFactories; this.propertyDependencyFactories = propertyDependencyFactories; this.availableServices = availableServices; - this.emitters = emitters; this.decorators = decorators; this.overrides = overrides; this.factoryRules = factoryRules; @@ -2513,6 +2511,10 @@ private ServiceContainer( ScopeManagerProvider = scopeManagerProvider; #if NET452 || NET46 || NETSTANDARD1_6 || NETCOREAPP2_0 AssemblyLoader = assemblyLoader; + foreach (var availableService in AvailableServices) + { + this.Register(availableService); + } #endif } @@ -3221,7 +3223,6 @@ public ServiceContainer Clone() constructorDependencyFactories, propertyDependencyFactories, availableServices, - emitters, decorators, overrides, factoryRules,