public void UpdateFrom(ComponentAddedMessage message) { if (message == null) { throw new ArgumentNullException("message"); } TypeData limitType; if (!_types.TryGetItem(message.Component.LimitTypeId, out limitType)) { throw new InvalidOperationException("The component depends on an unknown type."); } var component = new Component( message.Component.Id, limitType, message.Component.Services.Select(svc => { TypeData serviceType; if (!_types.TryGetItem(svc.ServiceTypeId, out serviceType)) { throw new InvalidOperationException("The service provides an unknown type."); } return(new Service(svc.Description, serviceType, svc.Key)); }), message.Component.Ownership, message.Component.Sharing, message.Component.Metadata, message.Component.Activator, message.Component.Lifetime, message.Component.TargetComponentId); _components.Add(component); }
public void UpdateFrom(InstanceLookupBeginningMessage e) { if (e == null) { throw new ArgumentNullException("e"); } var instanceLookup = e.InstanceLookup; ResolveOperation resolveOperation; LifetimeScope activationScope; Component component; if (!_resolveOperations.TryGetItem(instanceLookup.ResolveOperationId, out resolveOperation) || !_lifetimeScopes.TryGetItem(instanceLookup.ActivationScopeId, out activationScope) || !_components.TryGetItem(instanceLookup.ComponentId, out component)) { throw new InvalidOperationException("Instance lookup depends on an unknown item."); } InstanceLookup item; if (resolveOperation.RootInstanceLookup == null) { item = new InstanceLookup(instanceLookup.Id, resolveOperation, activationScope, component); resolveOperation.RootInstanceLookup = item; resolveOperation.InstanceLookupStack.Push(item); } else { var top = resolveOperation.InstanceLookupStack.Peek(); item = new InstanceLookup(instanceLookup.Id, resolveOperation, activationScope, component, top); top.DependencyLookups.Add(item); resolveOperation.InstanceLookupStack.Push(item); } _instanceLookups.Add(item); }
public ComponentDetailViewModel(string componentId, IDispatcher dispatcher, IActiveItemRepository<Component> components) { dispatcher.Background(() => { Component component; if (!components.TryGetItem(componentId, out component)) throw new ArgumentException("Unknown component."); var description = component.Description; var services = component.DescribeServices(); var metadata = component.Metadata; var sharing = component.Sharing; var lifetime = component.Lifetime; var activator = component.Activator; var ownership = component.Ownership; var target = component.TargetComponentId; var id = component.Id; dispatcher.Foreground(() => { Description = description; Metadata = metadata; Services = services; Sharing = sharing.ToString(); Lifetime = lifetime.ToString(); Activator = activator.ToString(); Ownership = ownership.ToString(); Target = target; Id = id; }); }); }
public ComponentDetailViewModel(string componentId, IDispatcher dispatcher, IActiveItemRepository <Component> components) { dispatcher.Background(() => { Component component; if (!components.TryGetItem(componentId, out component)) { throw new ArgumentException("Unknown component."); } var description = component.Description; var services = component.DescribeServices(); var metadata = component.Metadata; var sharing = component.Sharing; var lifetime = component.Lifetime; var activator = component.Activator; var ownership = component.Ownership; var target = component.TargetComponentId; var id = component.Id; dispatcher.Foreground(() => { Description = description; Metadata = metadata; Services = services; Sharing = sharing.ToString(); Lifetime = lifetime.ToString(); Activator = activator.ToString(); Ownership = ownership.ToString(); Target = target; Id = id; }); }); }
public void UpdateFrom(InstanceLookupEndingMessage e) { InstanceLookup instanceLookup; if (!_instanceLookups.TryGetItem(e.InstanceLookupId, out instanceLookup)) { throw new InvalidOperationException("Instance lookup ending is unknown."); } var popped = instanceLookup.ResolveOperation.InstanceLookupStack.Pop(); if (popped != instanceLookup) { throw new InvalidOperationException("Wrong instance lookup was on the top of the stack."); } popped.SharedInstanceReused = !e.NewInstanceActivated; if (popped.SharedInstanceReused) { _instanceLookups.RemoveCompleted(popped); } }
public void UpdateFrom(ResolveOperationEndingMessage message) { ResolveOperation resolveOperation; if (!_resolveOperations.TryGetItem(message.ResolveOperationId, out resolveOperation)) { throw new InvalidOperationException("Ending resolve operation is unknown."); } resolveOperation.Thread.ResolveOperationStack.Pop(); _resolveOperations.RemoveCompleted(resolveOperation); }
public void UpdateFrom(LifetimeScopeBeginningMessage message) { if (message == null) { throw new ArgumentNullException("message"); } LifetimeScope parent = null; if (message.LifetimeScope.ParentLifetimeScopeId != null) { _lifetimeScopes.TryGetItem(message.LifetimeScope.ParentLifetimeScopeId, out parent); } var lifetimeScope = new LifetimeScope(message.LifetimeScope.Id, TagFor(message.LifetimeScope), parent); _lifetimeScopes.Add(lifetimeScope); if (parent != null) { parent.ActiveChildren.Add(lifetimeScope); } }
public void UpdateFrom(ResolveOperationBeginningMessage message) { LifetimeScope lifetimeScope; if (!_lifetimeScopes.TryGetItem(message.ResolveOperation.LifetimeScopeId, out lifetimeScope)) { throw new InvalidOperationException("Resolve operation beginning in an unknown lifetime scope."); } Thread thread; if (!_threads.TryGetItem(message.ResolveOperation.ThreadId, out thread)) { thread = new Thread(message.ResolveOperation.ThreadId); _threads.Add(thread); } ResolveOperation parent = null; if (thread.ResolveOperationStack.Count != 0) { parent = thread.ResolveOperationStack.Peek(); } MethodIdentifier callingMethod = null; if (message.ResolveOperation.CallingMethodName != null) { callingMethod = new MethodIdentifier(message.ResolveOperation.CallingMethodName, TypeIdentifier.Parse(message.ResolveOperation.CallingTypeAssemblyQualifiedName)); } var resolveOperation = new ResolveOperation(message.ResolveOperation.Id, lifetimeScope, thread, parent, callingMethod); if (parent != null) { parent.SubOperations.Add(resolveOperation); } _resolveOperations.Add(resolveOperation); thread.ResolveOperationStack.Push(resolveOperation); }