public void ExplicitPluginFamilyDefinitionOverridesImplicitDefinition()
        {
            PluginGraph pluginGraph = DataMother.GetPluginGraph("ExplicitPluginFamilyOverridesImplicitPluginFamily.xml");

            PluginFamily family = pluginGraph.FindFamily(typeof(GrandChild));

            Assert.AreEqual("Fred", family.DefaultInstanceKey);
        }
Exemple #2
0
        public void should_get_the_greediest_constructor_if_there_is_more_than_one()
        {
            var selector    = new ConstructorSelector(PluginGraph.CreateRoot());
            var constructor = selector.Select(typeof(GreaterThanRule), new DependencyCollection());

            constructor.GetParameters().Select(x => x.ParameterType)
            .ShouldHaveTheSameElementsAs(typeof(IWidget), typeof(Rule));
        }
Exemple #3
0
 public void Process(Type type, PluginGraph graph)
 {
     if (CanBeCast(typeof(IController), type))
     {
         string name = type.Name.Replace("Controller", "").ToLower();
         graph.AddType(typeof(IController), type, name);
     }
 }
 public RootPipelineGraph(PluginGraph pluginGraph)
 {
     _pluginGraph    = pluginGraph;
     _transientCache = new NulloTransientCache();
     _profiles       =
         new Cache <string, IPipelineGraph>(
             name => new ComplexPipelineGraph(this, _pluginGraph.Profile(name), new NulloTransientCache()));
 }
Exemple #5
0
        private void addCloseGenericPolicyTo(PluginGraph graph)
        {
            var policy = new CloseGenericFamilyPolicy(graph);

            graph.AddFamilyPolicy(policy);

            graph.Profiles.Each(addCloseGenericPolicyTo);
        }
        public void find_family_for_concrete_type_with_default()
        {
            PluginGraph graph = PluginGraph.Empty();

            graph.Families[typeof(BigThingy)].GetDefaultInstance()
            .ShouldBeOfType <ConstructorInstance>()
            .PluggedType.ShouldEqual(typeof(BigThingy));
        }
Exemple #7
0
        public IPipelineGraph ToNestedGraph()
        {
            var nestedPluginGraph = new PluginGraph(Profile + " - Nested");
            var instances         = new ComplexInstanceGraph(this, nestedPluginGraph, ContainerRole.Nested);

            return(new PipelineGraph(nestedPluginGraph, instances, this, _singletons,
                                     new NestedContainerTransientObjectCache()));
        }
Exemple #8
0
        public void transient_cache_of_nested_pipeline_graph_is_a_stateful_cache()
        {
            var plugins = PluginGraph.CreateRoot();

            var pipeline = PipelineGraph.BuildRoot(plugins);

            pipeline.ToNestedGraph().Transients.ShouldBeOfType <ContainerSpecificObjectCache>();
        }
        public void transient_cache_by_default_is_a_nullo()
        {
            var plugins = new PluginGraph();

            var pipeline = PipelineGraph.BuildRoot(plugins);

            pipeline.Transients.ShouldBeOfType <NulloTransientCache>();
        }
        public void transient_cache_of_nested_pipeline_graph_is_a_stateful_cache()
        {
            var plugins = new PluginGraph();

            var pipeline = PipelineGraph.BuildRoot(plugins);

            pipeline.ToNestedGraph().Transients.ShouldBeOfType <LifecycleObjectCache>();
        }
        public void all_instances_when_the_family_already_exists()
        {
            var graph = new PluginGraph();

            graph.Families.FillDefault(typeof(BigThingy));

            graph.AllInstances(typeof(BigThingy)).Any().ShouldBeFalse();
        }
        public void SetUp()
        {
            graph    = new PluginGraph();
            pipeline = new PipelineGraph(graph);
            library  = new InterceptorLibrary();

            builder = new ObjectBuilder(pipeline, library);
        }
        public void has_family_true_with_simple()
        {
            var graph = PluginGraph.Empty();

            graph.AddFamily(new PluginFamily(typeof(IThingy)));

            graph.HasFamily(typeof(IThingy)).ShouldBeTrue();
        }
        public void all_instances_when_family_has_not_been_created()
        {
            var graph = new PluginGraph();

            graph.AllInstances(typeof(BigThingy)).Any().ShouldBeFalse();

            graph.Families.Has(typeof(BigThingy)).ShouldBeFalse();
        }
        public void AssertErrors_throws_StructureMapConfigurationException_if_there_is_an_error()
        {
            var graph = new PluginGraph();

            graph.Log.RegisterError(400, new ApplicationException("Bad!"));

            graph.Log.AssertFailures();
        }
Exemple #16
0
        private static ITransientTracking chooseTransientTracking(PluginGraph pluginGraph)
        {
            ITransientTracking transients = pluginGraph.TransientTracking == TransientTracking.DefaultNotTrackedAtRoot
                ? (ITransientTracking) new NulloTransientCache()
                : new TrackingTransientCache();

            return(transients);
        }
Exemple #17
0
        public void CTOR_throws_StructureMapConfigurationException_if_there_is_an_error()
        {
            var graph = new PluginGraph();

            graph.Log.RegisterError(400, new ApplicationException("Bad!"));

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

            graph.Families[typeof(IThingy)].SetDefault(new SmartInstance <BigThingy>());

            graph.HasDefaultForPluginType(typeof(IThingy));
        }
        public void find_instance_negative_when_family_does_exist_but_instance_does_not()
        {
            var graph = new PluginGraph();

            graph.Families[typeof(BigThingy)].AddInstance(new SmartInstance <BigThingy>().Named("red"));

            graph.FindInstance(typeof(BigThingy), "blue").ShouldBeNull();
        }
        public DoctorReport RunReport(string bootstrapperTypeName)
        {
            var report = new DoctorReport
            {
                Result = DoctorResult.Success
            };


            IBootstrapper bootstrapper;

            try
            {
                var  path             = new TypePath(bootstrapperTypeName);
                Type bootstrapperType = path.FindType();
                bootstrapper = (IBootstrapper)Activator.CreateInstance(bootstrapperType);
            }
            catch (Exception e)
            {
                report.Result        = DoctorResult.BootstrapperCouldNotBeFound;
                report.ErrorMessages = e.ToString();

                return(report);
            }

            try
            {
                bootstrapper.BootstrapStructureMap();

                PluginGraph graph = ObjectFactory.PluginGraph;

                if (graph.Log.ErrorCount > 0)
                {
                    report.ErrorMessages = graph.Log.BuildFailureMessage();
                    report.Result        = DoctorResult.ConfigurationErrors;
                }
                else
                {
                    writeConfigurationAndValidate(report, graph);
                }


                return(report);
            }
            catch (StructureMapConfigurationException ex)
            {
                report.ErrorMessages = ex.Message;
                report.Result        = DoctorResult.ConfigurationErrors;

                return(report);
            }
            catch (Exception ex)
            {
                report.Result        = DoctorResult.BootstrapperFailure;
                report.ErrorMessages = ex.ToString();

                return(report);
            }
        }
Exemple #21
0
        public IPipelineGraph NewChild()
        {
            var childGraph = new PluginGraph();
            var instances  = new ComplexInstanceGraph(_root, childGraph, ContainerRole.ProfileOrChild);

            // RIGHT HERE, WE NEED TO USE A DIFFERENT SINGLETON CACHE

            return(new PipelineGraph(childGraph, instances, _root, _root.Singletons, _root.Transients));
        }
Exemple #22
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 get_the_first_constructor_marked_with_the_attribute_if_it_exists()
        {
            var selector = new ConstructorSelector(PluginGraph.CreateRoot());

            var constructor = selector.Select(typeof(ComplexRule), new DependencyCollection());

            constructor.GetParameters().Length
            .ShouldBe(7);
        }
Exemple #24
0
        public void all_instances_when_the_family_already_exists()
        {
            var graph = PluginGraph.CreateRoot();

            // just forcing the family to be created
            graph.Families[typeof(BigThingy)].ShouldNotBeNull();

            graph.AllInstances(typeof(BigThingy)).Any().ShouldBeFalse();
        }
Exemple #25
0
        public static IPipelineGraph BuildRoot(PluginGraph pluginGraph)
        {
            ITransientTracking transients = pluginGraph.TransientTracking == TransientTracking.DefaultNotTrackedAtRoot
                ? (ITransientTracking) new NulloTransientCache()
                : new TrackingTransientCache();

            return(new PipelineGraph(pluginGraph, new RootInstanceGraph(pluginGraph), null, pluginGraph.SingletonCache,
                                     transients));
        }
Exemple #26
0
        public void find_instance_positive()
        {
            var graph    = PluginGraph.CreateRoot();
            var instance = new SmartInstance <BigThingy>().Named("red");

            graph.Families[typeof(BigThingy)].AddInstance(instance);

            graph.FindInstance(typeof(BigThingy), "red").ShouldBeTheSameAs(instance);
        }
 // ASP.NET expects registered services to be considered when selecting a ctor, SM doesn't by default.
 public ConstructorInfo Find(Type pluggedType, DependencyCollection dependencies, PluginGraph graph) =>
 pluggedType.GetTypeInfo()
 .DeclaredConstructors
 .Where(ctor => ctor.IsConstructor && !ctor.IsPrivate)         // IsConstructor is false for static constructors
 .Select(ctor => new { Constructor = ctor, Parameters = ctor.GetParameters() })
 .Where(x => x.Parameters.All(param => graph.HasFamily(param.ParameterType) || dependencies.Any(dep => dep.Type == param.ParameterType)))
 .OrderByDescending(x => x.Parameters.Length)
 .Select(x => x.Constructor)
 .FirstOrDefault();
Exemple #28
0
        public void default_lifecycle_not_set_on_any_level()
        {
            var graph = PluginGraph.CreateRoot();

            var pipeline = PipelineGraph.BuildRoot(graph).Profiles.For("Red");

            pipeline.Instances.DefaultLifecycleFor(typeof(IGateway))
            .ShouldBeNull();
        }
Exemple #29
0
        public Profiles(PluginGraph pluginGraph, IPipelineGraph root)
        {
            _profiles = new Cache <string, IPipelineGraph>(name => {
                var profileGraph = pluginGraph.Profile(name);

                var instances = new ComplexInstanceGraph(root, profileGraph, ContainerRole.ProfileOrChild);
                return(new PipelineGraph(profileGraph, instances, root, root.Singletons, root.Transients));
            });
        }
Exemple #30
0
        public void value_is_instance_for_non_simple_resolves_to_lifecycle_source()
        {
            var instance = new FakeInstance();

            instance.SetLifecycleTo(new SingletonLifecycle());

            ConcreteType.SourceFor(new Policies(PluginGraph.CreateRoot()), ConcreteType.ConstructorArgument, "SomeProp", typeof(IGateway), instance)
            .ShouldBeTheSameAs(instance.DependencySource);
        }