public ServiceDescriptor(Registry registry, ServiceRegistration serviceRegistration)
 {
     this.registry = registry;
     pluginDescriptor = (PluginDescriptor) serviceRegistration.Plugin;
     serviceId = serviceRegistration.ServiceId;
     serviceTypeName = serviceRegistration.ServiceTypeName;
     defaultComponentTypeName = serviceRegistration.DefaultComponentTypeName;
     traitsHandlerFactory = serviceRegistration.TraitsHandlerFactory;
 }
        public void ServiceId_Accessor_EnforcesConstraints()
        {
            var plugin = MockRepository.GenerateStub<IPluginDescriptor>();
            var registration = new ServiceRegistration(plugin, "serviceId", new TypeName("Service, Assembly"));

            Assert.AreEqual("serviceId", registration.ServiceId);
            Assert.Throws<ArgumentNullException>(() => { registration.ServiceId = null; });

            registration.ServiceId = "differentServiceId";

            Assert.AreEqual("differentServiceId", registration.ServiceId);
        }
        private IServiceDescriptor GetServiceDescriptor(Type interfaceType, IPluginDescriptor plugin)
        {
            var serviceDescriptor = registry.Services.GetByServiceType(interfaceType);

            if (serviceDescriptor == null)
            {
                var serviceRegistration = new ServiceRegistration(plugin, interfaceType.FullName,
                    new TypeName(interfaceType));
                serviceDescriptor = registry.RegisterService(serviceRegistration);
            }

            return serviceDescriptor;
        }
        public void TraitsHandlerFactory_Accessor_EnforcesConstraints()
        {
            var plugin = MockRepository.GenerateStub<IPluginDescriptor>();
            var registration = new ServiceRegistration(plugin, "serviceId", new TypeName("Service, Assembly"));

            Assert.IsInstanceOfType<SingletonHandlerFactory>(registration.TraitsHandlerFactory);
            Assert.Throws<ArgumentNullException>(() => { registration.TraitsHandlerFactory = null; });

            var differentHandlerFactory = MockRepository.GenerateStub<IHandlerFactory>();
            registration.TraitsHandlerFactory = differentHandlerFactory;

            Assert.AreSame(differentHandlerFactory, registration.TraitsHandlerFactory);
        }
        public void DefaultComponentTypeName_Accessor_IsNullByDefaultButCanBeSet()
        {
            var plugin = MockRepository.GenerateStub<IPluginDescriptor>();
            var registration = new ServiceRegistration(plugin, "serviceId", new TypeName("Service, Assembly"));

            Assert.IsNull(registration.DefaultComponentTypeName);

            registration.DefaultComponentTypeName = new TypeName("Component, Assembly");
            Assert.AreEqual(new TypeName("Component, Assembly"), registration.DefaultComponentTypeName);

            registration.DefaultComponentTypeName = null;
            Assert.IsNull(registration.DefaultComponentTypeName);
        }
Example #6
0
        private static void RegisterServices(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 (Service service in plugin.Services)
                {
                    try
                    {
                        var serviceRegistration = new ServiceRegistration(pluginDescriptor,
                            service.ServiceId, new TypeName(service.ServiceType));
                        if (service.DefaultComponentType != null)
                            serviceRegistration.DefaultComponentTypeName = new TypeName(service.DefaultComponentType);

                        registry.RegisterService(serviceRegistration);
                    }
                    catch (Exception ex)
                    {
                        throw new RuntimeException(string.Format("Could not register service '{0}' of plugin '{1}'.",
                            service.ServiceId, plugin.PluginId), ex);
                    }
                }
            }
        }
Example #7
0
        /// <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;
            });
        }