public ComponentDescriptor(Registry registry, ComponentRegistration componentRegistration) { this.registry = registry; pluginDescriptor = (PluginDescriptor) componentRegistration.Plugin; serviceDescriptor = (ServiceDescriptor) componentRegistration.Service; componentId = componentRegistration.ComponentId; componentTypeName = componentRegistration.ComponentTypeName ?? serviceDescriptor.DefaultComponentTypeName; componentProperties = componentRegistration.ComponentProperties.Copy().AsReadOnly(); traitsProperties = componentRegistration.TraitsProperties.Copy().AsReadOnly(); componentHandlerFactory = componentRegistration.ComponentHandlerFactory; }
public void Plugin_Accessor_EnforcesConstraints() { var plugin = MockRepository.GenerateStub<IPluginDescriptor>(); var service = MockRepository.GenerateStub<IServiceDescriptor>(); var registration = new ComponentRegistration(plugin, service, "componentId", new TypeName("Component, Assembly")); Assert.AreSame(plugin, registration.Plugin); Assert.Throws<ArgumentNullException>(() => { registration.Plugin = null; }); var differentPlugin = MockRepository.GenerateStub<IPluginDescriptor>(); registration.Plugin = differentPlugin; Assert.AreSame(differentPlugin, registration.Plugin); }
/// <inheritdoc /> public IComponentDescriptor RegisterComponent(ComponentRegistration componentRegistration) { if (componentRegistration == null) { throw new ArgumentNullException("componentRegistration"); } return(dataBox.Write(data => { if (data.GetPluginById(componentRegistration.Plugin.PluginId) != componentRegistration.Plugin) { throw new ArgumentException("The specified plugin descriptor does not belong to this registry.", "componentRegistration"); } if (data.GetServiceById(componentRegistration.Service.ServiceId) != componentRegistration.Service) { throw new ArgumentException("The specified service descriptor does not belong to this registry.", "componentRegistration"); } if (componentRegistration.ComponentTypeName == null && componentRegistration.Service.DefaultComponentTypeName == null) { throw new ArgumentException("The specified service descriptor does not have a default component type name so the component registration must specify a component type name but it does not.", "componentRegistration"); } var servicePluginDependency = componentRegistration.Service.Plugin; var componentPlugin = componentRegistration.Plugin; if (componentPlugin != servicePluginDependency && !componentPlugin.PluginDependencies.Contains(servicePluginDependency)) { throw new ArgumentException(string.Format("The service belongs to a plugin that was not declared as a dependency of the plugin that provides this component. Plugin '{0}' should declare a dependency on plugin '{1}'.", componentPlugin.PluginId, servicePluginDependency.PluginId), "componentRegistration"); } if (data.GetComponentById(componentRegistration.ComponentId) != null) { throw new ArgumentException(string.Format("There is already a component registered with id '{0}'.", componentRegistration.ComponentId), "componentRegistration"); } ComponentDescriptor component = new ComponentDescriptor(this, componentRegistration); data.RegisterComponent(component); return component; })); }
private static void RegisterComponents(IRegistry registry, IList <PluginData> topologicallySortedPlugins, IList <IPluginDescriptor> pluginDescriptors) { for (int i = 0; i < topologicallySortedPlugins.Count; i++) { Plugin plugin = topologicallySortedPlugins[i].Plugin; IPluginDescriptor pluginDescriptor = pluginDescriptors[i]; foreach (Component component in plugin.Components) { var serviceDescriptor = registry.Services[component.ServiceId]; if (serviceDescriptor == null) { throw new RuntimeException(string.Format("Could not register component '{0}' of plugin '{1}' because it implements service '{2}' which was not found in the registry.", component.ComponentId, plugin.PluginId, component.ServiceId)); } try { var componentRegistration = new ComponentRegistration(pluginDescriptor, serviceDescriptor, component.ComponentId, component.ComponentType != null ? new TypeName(component.ComponentType) : null); if (component.Parameters != null) { componentRegistration.ComponentProperties = component.Parameters.PropertySet; } if (component.Traits != null) { componentRegistration.TraitsProperties = component.Traits.PropertySet; } registry.RegisterComponent(componentRegistration); } catch (Exception ex) { throw new RuntimeException(string.Format("Could not register component '{0}' of plugin '{1}'.", component.ComponentId, plugin.PluginId), ex); } } } }
private void RegisterComponent(Type interfaceType, string componentId, TypeName typeName, IPluginDescriptor plugin, IServiceDescriptor serviceDescriptor) { ComponentRegistration componentRegistration; if (IsAnEventHandler(interfaceType)) { componentRegistration = RegisterEventHandlerProxy(interfaceType, plugin, serviceDescriptor, componentId); } else { componentRegistration = new ComponentRegistration(plugin, serviceDescriptor, componentId, typeName); } registry.RegisterComponent(componentRegistration); }
private static ComponentRegistration RegisterEventHandlerProxy(Type interfaceType, IPluginDescriptor plugin, IServiceDescriptor serviceDescriptor, string componentId) { var proxyType = typeof(EventHandlerProxy<>).MakeGenericType(interfaceType.GetGenericArguments()); var typeName = new TypeName(proxyType).ConvertToPartialAssemblyName(); var componentRegistration = new ComponentRegistration(plugin, serviceDescriptor, Guid.NewGuid().ToString(), typeName); componentRegistration.ComponentProperties.Add("target", string.Format("${{{0}}}", componentId)); return componentRegistration; }
public void ComponentHandlerFactory_Accessor_EnforcesConstraints() { var plugin = MockRepository.GenerateStub<IPluginDescriptor>(); var service = MockRepository.GenerateStub<IServiceDescriptor>(); var registration = new ComponentRegistration(plugin, service, "componentId", new TypeName("Component, Assembly")); Assert.IsInstanceOfType<SingletonHandlerFactory>(registration.ComponentHandlerFactory); Assert.Throws<ArgumentNullException>(() => { registration.ComponentHandlerFactory = null; }); var differentHandlerFactory = MockRepository.GenerateStub<IHandlerFactory>(); registration.ComponentHandlerFactory = differentHandlerFactory; Assert.AreSame(differentHandlerFactory, registration.ComponentHandlerFactory); }
public void ComponentTypeName_Accessor_CanBeNullAndChanged() { var plugin = MockRepository.GenerateStub<IPluginDescriptor>(); var service = MockRepository.GenerateStub<IServiceDescriptor>(); var registration = new ComponentRegistration(plugin, service, "componentId", null); Assert.IsNull(registration.ComponentTypeName); registration.ComponentTypeName = new TypeName("DifferentComponent, Assembly"); Assert.AreEqual(new TypeName("DifferentComponent, Assembly"), registration.ComponentTypeName); }
private static void RegisterComponents(IRegistry registry, IList<PluginData> topologicallySortedPlugins, IList<IPluginDescriptor> pluginDescriptors) { for (int i = 0; i < topologicallySortedPlugins.Count; i++) { Plugin plugin = topologicallySortedPlugins[i].Plugin; IPluginDescriptor pluginDescriptor = pluginDescriptors[i]; foreach (Component component in plugin.Components) { var serviceDescriptor = registry.Services[component.ServiceId]; if (serviceDescriptor == null) throw new RuntimeException(string.Format("Could not register component '{0}' of plugin '{1}' because it implements service '{2}' which was not found in the registry.", component.ComponentId, plugin.PluginId, component.ServiceId)); try { var componentRegistration = new ComponentRegistration(pluginDescriptor, serviceDescriptor, component.ComponentId, component.ComponentType != null ? new TypeName(component.ComponentType) : null); if (component.Parameters != null) componentRegistration.ComponentProperties = component.Parameters.PropertySet; if (component.Traits != null) componentRegistration.TraitsProperties = component.Traits.PropertySet; registry.RegisterComponent(componentRegistration); } catch (Exception ex) { throw new RuntimeException(string.Format("Could not register component '{0}' of plugin '{1}'.", component.ComponentId, plugin.PluginId), ex); } } } }
private void RegisterComponent(string componentId, TypeName typeName, IPluginDescriptor plugin, IServiceDescriptor serviceDescriptor) { var componentRegistration = new ComponentRegistration(plugin, serviceDescriptor, componentId, typeName); registry.RegisterComponent(componentRegistration); }
/// <inheritdoc /> public IComponentDescriptor RegisterComponent(ComponentRegistration componentRegistration) { if (componentRegistration == null) throw new ArgumentNullException("componentRegistration"); return dataBox.Write(data => { if (data.GetPluginById(componentRegistration.Plugin.PluginId) != componentRegistration.Plugin) throw new ArgumentException("The specified plugin descriptor does not belong to this registry.", "componentRegistration"); if (data.GetServiceById(componentRegistration.Service.ServiceId) != componentRegistration.Service) throw new ArgumentException("The specified service descriptor does not belong to this registry.", "componentRegistration"); if (componentRegistration.ComponentTypeName == null && componentRegistration.Service.DefaultComponentTypeName == null) throw new ArgumentException("The specified service descriptor does not have a default component type name so the component registration must specify a component type name but it does not.", "componentRegistration"); var servicePluginDependency = componentRegistration.Service.Plugin; var componentPlugin = componentRegistration.Plugin; if (componentPlugin != servicePluginDependency && ! componentPlugin.PluginDependencies.Contains(servicePluginDependency)) throw new ArgumentException(string.Format("The service belongs to a plugin that was not declared as a dependency of the plugin that provides this component. Plugin '{0}' should declare a dependency on plugin '{1}'.", componentPlugin.PluginId, servicePluginDependency.PluginId), "componentRegistration"); if (data.GetComponentById(componentRegistration.ComponentId) != null) throw new ArgumentException(string.Format("There is already a component registered with id '{0}'.", componentRegistration.ComponentId), "componentRegistration"); ComponentDescriptor component = new ComponentDescriptor(this, componentRegistration); data.RegisterComponent(component); return component; }); }