Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #476 #509

Merged
merged 1 commit into from
Sep 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/LightInject.Tests/Issue476.cs
Original file line number Diff line number Diff line change
@@ -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<IFoo>(factory => new Foo());
container.GetInstance<IFoo>();

var clonedContainer = container.Clone();

clonedContainer.GetInstance<IFoo>(); // IndexOutOfRangeException
}
}
}
7 changes: 4 additions & 3 deletions src/LightInject/LightInject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2471,7 +2471,6 @@ private ServiceContainer(
ServiceRegistry<Delegate> constructorDependencyFactories,
ServiceRegistry<Delegate> propertyDependencyFactories,
ServiceRegistry<ServiceRegistration> availableServices,
ServiceRegistry<Action<IEmitter>> emitters,
Storage<DecoratorRegistration> decorators,
Storage<ServiceOverride> overrides,
Storage<FactoryRule> factoryRules,
Expand All @@ -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;
Expand All @@ -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
}

Expand Down Expand Up @@ -3221,7 +3223,6 @@ public ServiceContainer Clone()
constructorDependencyFactories,
propertyDependencyFactories,
availableServices,
emitters,
decorators,
overrides,
factoryRules,
Expand Down