private ScopeRestrictedRegistry CreateScopeRestrictedRegistry(object tag, Action <ContainerBuilder> configurationAction) { var builder = new ContainerBuilder(new FallbackDictionary <string, object>(ComponentRegistry.Properties)); foreach (var source in ComponentRegistry.Sources .Where(src => src.IsAdapterForIndividualComponents)) { builder.RegisterSource(source); } // Issue #272: Only the most nested parent registry with HasLocalComponents is registered as an external source // It provides all non-adapting registrations from itself and from it's parent registries var parent = Traverse.Across <ISharingLifetimeScope>(this, s => s.ParentLifetimeScope) .Where(s => s.ComponentRegistry.HasLocalComponents) .Select(s => new ExternalRegistrySource(s.ComponentRegistry)) .FirstOrDefault(); if (parent != null) { builder.RegisterSource(parent); } configurationAction(builder); var locals = new ScopeRestrictedRegistry(tag, builder.Properties); builder.UpdateRegistry(locals); return(locals); }
ScopeRestrictedRegistry CreateScopeRestrictedRegistry(object tag, Action <ContainerBuilder> configurationAction) { var builder = new ContainerBuilder(); foreach (var source in ComponentRegistry.Sources .Where(src => src.IsAdapterForIndividualComponents)) { builder.RegisterSource(source); } var parents = Traverse.Across <ISharingLifetimeScope>(this, s => s.ParentLifetimeScope) .Where(s => s.ComponentRegistry.HasLocalComponents) .Select(s => new ExternalRegistrySource(s.ComponentRegistry)) .Reverse(); foreach (var external in parents) { builder.RegisterSource(external); } configurationAction(builder); var locals = new ScopeRestrictedRegistry(tag); builder.Update(locals); return(locals); }
public void SingletonsRegisteredDirectlyAreWrappedWithLifetimeDecorator() { var registry = new ScopeRestrictedRegistry(new object(), new Dictionary <string, object>()); registry.Register(ObjectRegistration); var typedService = new TypedService(typeof(object)); registry.TryGetRegistration(typedService, out IComponentRegistration registration); Assert.IsType <ComponentRegistrationLifetimeDecorator>(registration); }
private ScopeRestrictedRegistry CreateScopeRestrictedRegistry(object tag, Action <ContainerBuilder> configurationAction) { ContainerBuilder builder = new ContainerBuilder(); foreach (IRegistrationSource source in from src in this.ComponentRegistry.Sources where src.IsAdapterForIndividualComponents select src) { builder.RegisterSource(source); } foreach (ExternalRegistrySource source2 in (from s in Traverse.Across <ISharingLifetimeScope>(this, s => s.ParentLifetimeScope) where s.ComponentRegistry.HasLocalComponents select new ExternalRegistrySource(s.ComponentRegistry)).Reverse <ExternalRegistrySource>()) { builder.RegisterSource(source2); } configurationAction(builder); ScopeRestrictedRegistry componentRegistry = new ScopeRestrictedRegistry(tag); builder.Update(componentRegistry); return(componentRegistry); }
ScopeRestrictedRegistry CreateScopeRestrictedRegistry(object tag, Action <ContainerBuilder> configurationAction) { var builder = new ContainerBuilder(); foreach (var source in ComponentRegistry.Sources) { if (source.IsAdapterForIndividualComponents) { builder.RegisterSource(source); } } ISharingLifetimeScope current = this; var list = new LinkedList <ExternalRegistrySource>(); while (current != null) { if (current.ComponentRegistry.HasLocalComponents) { list.AddFirst(new ExternalRegistrySource(current.ComponentRegistry)); } current = current.ParentLifetimeScope; } foreach (var external in list) { builder.RegisterSource(external); } configurationAction(builder); var locals = new ScopeRestrictedRegistry(tag); builder.Update(locals); return(locals); }