Ejemplo n.º 1
0
        /// <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;
            }));
        }
Ejemplo n.º 2
0
 public void RegisterComponent(ComponentDescriptor component)
 {
     components = null;
     componentsByComponentId.Add(component.ComponentId, component);
     componentsByServiceId.Add(component.Service.ServiceId, component);
 }
Ejemplo n.º 3
0
 public void RegisterComponent(ComponentDescriptor component)
 {
     components = null;
     componentsByComponentId.Add(component.ComponentId, component);
     componentsByServiceId.Add(component.Service.ServiceId, component);
 }
Ejemplo n.º 4
0
 public ComponentDependencyResolver(ComponentDescriptor descriptor)
     : base(descriptor.registry.ServiceLocator, descriptor.registry.ResourceLocator)
 {
     this.descriptor = descriptor;
 }
Ejemplo n.º 5
0
 public ComponentDependencyResolver(ComponentDescriptor descriptor)
     : base(descriptor.registry.ServiceLocator, descriptor.registry.ResourceLocator)
 {
     this.descriptor = descriptor;
 }
Ejemplo n.º 6
0
        /// <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;
            });
        }