public void PluginFamilyImplicitlyConfiguredAsASingletonBehavesAsASingleton()
        {
            var pluginGraph = new PluginGraph();

            pluginGraph.Scan(x => { x.Assembly(Assembly.GetExecutingAssembly()); });

            pluginGraph.Seal();

            var manager = new Container(pluginGraph);

            var repository1 =
                (ISingletonRepository)manager.GetInstance(typeof(ISingletonRepository));
            var repository2 =
                (ISingletonRepository)manager.GetInstance(typeof(ISingletonRepository));
            var repository3 =
                (ISingletonRepository)manager.GetInstance(typeof(ISingletonRepository));
            var repository4 =
                (ISingletonRepository)manager.GetInstance(typeof(ISingletonRepository));
            var repository5 =
                (ISingletonRepository)manager.GetInstance(typeof(ISingletonRepository));

            Assert.AreSame(repository1, repository2);
            Assert.AreSame(repository1, repository3);
            Assert.AreSame(repository1, repository4);
            Assert.AreSame(repository1, repository5);
        }
Esempio n. 2
0
        private void construct(PluginGraph pluginGraph)
        {
            _interceptorLibrary = pluginGraph.InterceptorLibrary;

            if (!pluginGraph.IsSealed)
            {
                pluginGraph.Seal();
            }

            _pluginGraph = pluginGraph;

            var thisInstance = new ObjectInstance(this);

            _pluginGraph.FindFamily(typeof(IContainer)).AddInstance(thisInstance);
            _pluginGraph.ProfileManager.SetDefault(typeof(IContainer), thisInstance);

            var funcInstance = new FactoryTemplate(typeof(LazyInstance <>));

            _pluginGraph.FindFamily(typeof(Func <>)).AddInstance(funcInstance);
            _pluginGraph.ProfileManager.SetDefault(typeof(Func <>), funcInstance);



            pluginGraph.Log.AssertFailures();

            _pipelineGraph = new PipelineGraph(pluginGraph);
        }
        public void Seal_does_not_throw_an_exception_if_there_are_no_errors()
        {
            var graph = new PluginGraph();

            Assert.AreEqual(0, graph.Log.ErrorCount);

            graph.Seal();
        }
Esempio n. 4
0
        /// <summary>
        /// Uses the configuration expressions of this Registry to create a PluginGraph
        /// object that could be used to initialize a Container.  This method is
        /// mostly for internal usage, but might be helpful for diagnostics
        /// </summary>
        /// <returns></returns>
        public PluginGraph Build()
        {
            var graph = new PluginGraph();

            ConfigurePluginGraph(graph);
            graph.Seal();

            return(graph);
        }
        public void CreateTheInferredPluginCorrectly()
        {
            // Who needs the Law of Demeter?
            _graph.Seal();

            PluginFamily family = _graph.FindFamily(typeof(IWidget));

            Assert.AreEqual(4, family.InstanceCount);
        }
        public void CanCreateTheAutoFilledInstance()
        {
            // Builds a PluginGraph that includes all of the PluginFamily's and Plugin's
            // defined in this file
            var pluginGraph = new PluginGraph();

            pluginGraph.Scan(x => x.Assembly(Assembly.GetExecutingAssembly()));
            pluginGraph.Seal();

            var manager = new Container(pluginGraph);

            var mustang = (Mustang)manager.GetInstance(typeof(IAutomobile), "Mustang");

            Assert.IsNotNull(mustang);
            Assert.IsTrue(mustang.Engine is PushrodEngine);
        }
        public void BuildFamilyAndPluginThenSealAndCreateInstanceManagerWithGenericTypeWithOpenGenericParameters()
        {
            var graph = new PluginGraph();

            graph.Scan(x => x.TheCallingAssembly());


            PluginFamily family = graph.FindFamily(typeof(IGenericService <>));

            family.DefaultInstanceKey = "Default";
            family.AddPlugin(typeof(GenericService <>), "Default");

            graph.Seal();

            var manager = new Container(graph);
        }
        public void PutsRightNumberOfPluginsIntoAFamily()
        {
            var graph = new PluginGraph();

            graph.Scan(x => { x.Assembly("StructureMap.Testing.Widget"); });

            graph.FindFamily(typeof(IWidget)).DefaultInstanceKey = "Blue";
            graph.Seal();

            PluginFamily family = graph.FindFamily(typeof(IWidget));

            Assert.IsNotNull(family);

            Assert.AreEqual("Blue", family.DefaultInstanceKey);

            Assert.AreEqual(4, family.PluginCount, "3 different IWidget classes are marked as Pluggable");
        }
Esempio n. 9
0
        /// <summary>
        /// Reads the configuration information and returns the PluginGraph definition of
        /// plugin families and plugin's
        /// </summary>
        /// <returns></returns>
        public PluginGraph Build()
        {
            var graphBuilder = new GraphBuilder(_registries, _graph);

            forAllParsers(p =>
            {
                _graph.Log.StartSource(p.Description);
                p.ParseAssemblies(graphBuilder);
                p.ParseRegistries(graphBuilder);
            });

            forAllParsers(p => p.Parse(graphBuilder));

            _graph.Seal();

            return(_graph);
        }
        public void FindPlugins()
        {
            var graph = new PluginGraph();

            graph.Scan(x =>
            {
                x.Assembly("StructureMap.Testing.Widget");
                x.Assembly("StructureMap.Testing.Widget2");
            });

            graph.FindFamily(typeof(Rule));

            graph.Seal();

            PluginFamily family = graph.FindFamily(typeof(Rule));

            Assert.IsNotNull(family);
            Assert.AreEqual(5, family.PluginCount, "There are 5 Rule classes in the two assemblies");
        }
        public void FindPluginFamilies()
        {
            var graph = new PluginGraph();

            graph.Scan(x => { x.Assembly("StructureMap.Testing.Widget"); });

            graph.FindFamily(typeof(IWidget)).DefaultInstanceKey = "Blue";
            graph.CreateFamily(typeof(WidgetMaker));

            graph.Seal();


            foreach (PluginFamily family in graph.PluginFamilies)
            {
                Console.WriteLine(family.PluginType.AssemblyQualifiedName);
            }

            Assert.AreEqual(5, graph.FamilyCount);
        }
        public void PicksUpManuallyAddedPlugin()
        {
            var graph = new PluginGraph();

            graph.Scan(x => { x.Assembly("StructureMap.Testing.Widget"); });

            graph.FindFamily(typeof(IWidget)).DefaultInstanceKey = "Blue";


            PluginFamily family = graph.FindFamily(typeof(IWidget));

            family.AddPlugin(typeof(NotPluggableWidget), "NotPluggable");

            graph.Seal();


            Assert.IsNotNull(family);

            Assert.AreEqual(
                5,
                family.PluginCount,
                "5 different IWidget classes are marked as Pluggable, + the manual add");
        }
        public void FindRegistriesWithinPluginGraphSeal()
        {
            var graph = new PluginGraph();

            var scanner = new AssemblyScanner();

            scanner.AssemblyContainingType(typeof(RedGreenRegistry));
            scanner.LookForRegistries();
            scanner.ScanForAll(graph);

            graph.Seal();

            var          colors = new List <string>();
            PluginFamily family = graph.FindFamily(typeof(IWidget));

            family.Instances.Each(instance => colors.Add(instance.Name));

            Assert.Contains("Red", colors);
            Assert.Contains("Green", colors);
            Assert.Contains("Yellow", colors);
            Assert.Contains("Blue", colors);
            Assert.Contains("Brown", colors);
            Assert.Contains("Black", colors);
        }
Esempio n. 14
0
 public void FinishFamilies()
 {
     _pluginGraph.Seal();
 }