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 RegisterService(ServiceDescriptor service) { services = null; servicesByServiceId.Add(service.ServiceId, service); servicesByServiceTypeName.Add(service.ServiceTypeName, service); if (! service.ServiceTypeName.HasPartialAssemblyName) servicesByServiceTypeName.Add(service.ServiceTypeName.ConvertToPartialAssemblyName(), service); }
/// <inheritdoc /> public IServiceDescriptor RegisterService(ServiceRegistration serviceRegistration) { if (serviceRegistration == null) throw new ArgumentNullException("serviceRegistration"); return dataBox.Write(data => { if (data.GetPluginById(serviceRegistration.Plugin.PluginId) != serviceRegistration.Plugin) throw new ArgumentException("The specified plugin descriptor does not belong to this registry.", "serviceRegistration"); if (data.GetServiceById(serviceRegistration.ServiceId) != null) throw new ArgumentException(string.Format("There is already a service registered with id '{0}'.", serviceRegistration.ServiceId), "serviceRegistration"); IServiceDescriptor otherService = data.GetServiceByServiceTypeName(serviceRegistration.ServiceTypeName); if (otherService != null) throw new ArgumentException(string.Format("There is already a service registered with type name '{0}'. This service has id '{1}' and the other service has id '{2}'.", serviceRegistration.ServiceTypeName, serviceRegistration.ServiceId, otherService.ServiceId), "serviceRegistration"); ServiceDescriptor service = new ServiceDescriptor(this, serviceRegistration); data.RegisterService(service); return service; }); }