public static global::SimpleInjector.Container Clone(this global::SimpleInjector.Container parentContainer) { var clonedContainer = new global::SimpleInjector.Container(); clonedContainer.AllowToResolveArraysAndLists(); clonedContainer.Options.AllowOverridingRegistrations = true; clonedContainer.Options.DefaultScopedLifestyle = new AsyncScopedLifestyle(); clonedContainer.Options.AutoWirePropertiesImplicitly(); AsyncScopedLifestyle.BeginScope(clonedContainer); foreach (var reg in parentContainer.GetCurrentRegistrations()) { if (reg.Lifestyle == Lifestyle.Singleton && !HasComponent(clonedContainer, reg.ServiceType)) { clonedContainer.Register(reg.ServiceType, reg.GetInstance, reg.Lifestyle); } else { var registration = RegistrationOptions(reg, clonedContainer).First(r => r != null); clonedContainer.AddRegistration(reg.ServiceType, registration); } } return(clonedContainer); }