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