public void RegisterExtension_RegisterMultipleInstances()
        {
            DefaultExtensionRegistry registry = new DefaultExtensionRegistry();

            ServiceA serviceA = new ServiceA();
            ServiceB serviceB = new ServiceB();
            ServiceC serviceC = new ServiceC();
            registry.RegisterExtension(typeof(IMyService), serviceA);
            registry.RegisterExtension(typeof(IMyService), serviceB);
            registry.RegisterExtension(typeof(IMyService), serviceC);

            OtherServiceA otherServiceA = new OtherServiceA();
            OtherServiceB otherServiceB = new OtherServiceB();
            registry.RegisterExtension(typeof(IMyOtherService), otherServiceA);
            registry.RegisterExtension(typeof(IMyOtherService), otherServiceB);

            object[] services = registry.GetExtensions(typeof(IMyService)).ToArray();
            Assert.Equal(3, services.Length);
            Assert.True(services.Contains(serviceA));
            Assert.True(services.Contains(serviceB));
            Assert.True(services.Contains(serviceC));

            services = registry.GetExtensions(typeof(IMyOtherService)).ToArray();
            Assert.Equal(2, services.Length);
            Assert.True(services.Contains(otherServiceA));
            Assert.True(services.Contains(otherServiceB));
        }
        public void apply_polymorphism_to_services()
        {
            FrameworkServiceContainer c = new FrameworkServiceContainer();
            ServiceB b = new ServiceB();
            ServiceC d = new ServiceC();
            c.AddService(typeof(ServiceB), b);
            c.AddService(typeof(ServiceC), d);

            Assert.That(c.GetServices<ServiceB>().Count(), Is.EqualTo(2));
            Assert.That(c.GetServices<ServiceB>(), Contains.Item(d));
        }
        public void IExtensionRegistryExtensions_RegisterAndRetrieve()
        {
            DefaultExtensionRegistry registry = new DefaultExtensionRegistry();

            // use the generic extension methods to register
            ServiceA serviceA = new ServiceA();
            ServiceB serviceB = new ServiceB();
            ServiceC serviceC = new ServiceC();
            registry.RegisterExtension<IMyService>(serviceA);
            registry.RegisterExtension<IMyService>(serviceB);
            registry.RegisterExtension<IMyService>(serviceC);

            IMyService[] services = registry.GetExtensions<IMyService>().ToArray();
            Assert.Equal(3, services.Length);
            Assert.True(services.Contains(serviceA));
            Assert.True(services.Contains(serviceB));
            Assert.True(services.Contains(serviceC));
        }
        public void dedupe_by_type_services_polymorphic()
        {
            FrameworkServiceContainer c = new FrameworkServiceContainer();
            ServiceC d = new ServiceC();
            c.AddService(typeof(ServiceB), d);
            c.AddService(typeof(ServiceC), d);

            Assert.That(c.GetServices<ServiceB>().Count(), Is.EqualTo(1));
        }
Exemplo n.º 5
0
 public ServiceB(IServiceA serviceA, ServiceC serviceC) {
     ServiceA = serviceA;
     ServiceC = serviceC;
 }