コード例 #1
0
        public void FindAPluginFamilyForAGenericTypeFromPluginTypeName()
        {
            Type        serviceType   = typeof(IService <string>);
            PluginGraph pluginGraph   = PluginGraph.BuildGraphFromAssembly(serviceType.Assembly);
            var         pipelineGraph = new PipelineGraph(pluginGraph);

            Type stringService = typeof(IService <string>);

            IInstanceFactory factory = pipelineGraph.ForType(stringService);

            Assert.AreEqual(stringService, factory.PluginType);
        }
コード例 #2
0
        public void CanBuildAGenericObjectThatHasAnotherGenericObjectAsAChild()
        {
            Type        serviceType = typeof(IService <double>);
            PluginGraph pluginGraph = PluginGraph.BuildGraphFromAssembly(serviceType.Assembly);
            var         manager     = new Container(pluginGraph);

            Type doubleServiceType = typeof(IService <double>);

            var service =
                (ServiceWithPlug <double>)manager.GetInstance(doubleServiceType, "Plugged");

            Assert.AreEqual(typeof(double), service.Plug.PlugType);
        }
コード例 #3
0
        public void CanGetPluginFamilyFromPluginGraphWithNoParameters()
        {
            var graph = PluginGraph.BuildGraphFromAssembly(GetType().Assembly);

            graph.Families[typeof(IGenericService <int>)].ShouldBeTheSameAs(
                graph.Families[typeof(IGenericService <int>)]);

            graph.Families[typeof(IGenericService <string>)].ShouldBeTheSameAs(
                graph.Families[typeof(IGenericService <string>)]);

            graph.Families[typeof(IGenericService <>)].ShouldBeTheSameAs(
                graph.Families[typeof(IGenericService <>)]);
        }
コード例 #4
0
        public void GenericsTypeAndProfileOrMachine()
        {
            PluginGraph pluginGraph = PluginGraph.BuildGraphFromAssembly(typeof(IService <>).Assembly);

            pluginGraph.SetDefault("1", typeof(IService <>), new ReferencedInstance("Default"));
            pluginGraph.SetDefault("2", typeof(IService <>), new ReferencedInstance("Plugged"));


            var manager = new Container(pluginGraph);

            var plug = manager.GetInstance <IPlug <string> >();

            manager.SetDefaultsToProfile("1");
            Assert.IsInstanceOfType(typeof(Service <string>), manager.GetInstance(typeof(IService <string>)));

            manager.SetDefaultsToProfile("2");
            Assert.IsInstanceOfType(typeof(ServiceWithPlug <string>), manager.GetInstance(typeof(IService <string>)));

            manager.SetDefaultsToProfile("1");
            Assert.IsInstanceOfType(typeof(Service <string>), manager.GetInstance(typeof(IService <string>)));
        }