public void transient_cache_by_default_is_a_nullo()
        {
            var plugins = new PluginGraph();

            var pipeline = new RootPipelineGraph(plugins);
            pipeline.Transients.ShouldBeOfType<NulloTransientCache>();
        }
 private void validateInstance(IDiagnosticInstance instance, PluginFamily family, PluginGraph graph)
 {
     if (!instance.CanBePartOfPluginFamily(family))
     {
         graph.Log.RegisterError(104, instance.CreateToken(), family.PluginType);
     }
 }
Ejemplo n.º 3
0
        public GraphBuilder(PluginGraph pluginGraph)
        {
            _pluginGraph = pluginGraph;
            _assemblyScanner = new AssemblyScanner();

            _instanceReader = new XmlInstanceReader(_pluginGraph.Log, new Registry());
        }
        public void Read_in_a_class_with_primitive_arrays()
        {
            string xml = @"
<Instance>
    <numbers Values='1,2,3'/>
    <strings Values='1,2,3'/>
</Instance>
";

            XmlElement element = DataMother.BuildDocument(xml).DocumentElement;
            element.SetAttribute("PluggedType", typeof (ClassWithStringAndIntArray).AssemblyQualifiedName);

            var memento = new XmlAttributeInstanceMemento(element);
            var graph = new PluginGraph();
            Instance instance = memento.ReadInstance(typeof (ClassWithStringAndIntArray));

            Assert.Fail("NWO");

//            var theObject = (ClassWithStringAndIntArray) instance.Build(typeof (ClassWithStringAndIntArray),
//                                                                        BuildSession.ForPluginGraph(graph));
//
//            theObject.Numbers.ShouldEqual(new[] {1, 2, 3});
//            theObject.Strings.ShouldEqual(new[] {"1", "2", "3"});
//
//            Debug.WriteLine(theObject.GetType().AssemblyQualifiedName);
        }
Ejemplo n.º 5
0
        public void AssertErrors_throws_StructureMapConfigurationException_if_there_is_an_error()
        {
            var graph = new PluginGraph();
            graph.Log.RegisterError(400, new ApplicationException("Bad!"));

            graph.Log.AssertFailures();
        }
Ejemplo n.º 6
0
        private void addCloseGenericPolicyTo(PluginGraph graph)
        {
            var policy = new CloseGenericFamilyPolicy(graph);
            graph.AddFamilyPolicy(policy);

            graph.Profiles.Each(addCloseGenericPolicyTo);
        }
 private static void ThrowIfMarkerInterfaceIsRegistered(PluginGraph graph)
 {
     if (graph.HasFamily<IMarkerInterface>())
     {
         throw new InvalidOperationException("Populate should only be called once per container.");
     }
 }
Ejemplo n.º 8
0
    public PluginFamily(Type pluginType, PluginGraph parent)
    {
        _parent = parent;
            _pluginType = pluginType;

            PluginFamilyAttribute.ConfigureFamily(this);
    }
Ejemplo n.º 9
0
        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();
        }
Ejemplo n.º 10
0
        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>();
        }
Ejemplo n.º 11
0
 public PluginGraphBuilder(ConfigurationParser[] parsers, Registry[] registries, GraphLog log)
 {
     _parsers = parsers;
     _registries = registries;
     _graph = new PluginGraph();
     _graph.Log = log;
 }
Ejemplo n.º 12
0
        public void Apply(PluginGraph graph)
        {
            var registry = new Registry();

            _interfaces.Each(@interface =>
            {
                var expression = registry.For(@interface);
                ConfigureFamily(expression);

                var exactMatches = _concretions.Where(x => x.CanBeCastTo(@interface)).ToArray();
                if (exactMatches.Length == 1)
                {
                    expression.Use(exactMatches.Single());
                }
                else
                {
                    exactMatches.Each(type => expression.Add(type));
                }


                if ([email protected]())
                {
                    addConcretionsThatCouldBeClosed(@interface, expression);
                }
            });

            _concretions.Each(t => graph.ConnectedConcretions.Fill(t));
            registry.As<IPluginGraphConfiguration>().Configure(graph);
        }
Ejemplo n.º 13
0
        public IPipelineGraph NewChild()
        {
            var childGraph = new PluginGraph();
            var instances = new ComplexInstanceGraph(_root, childGraph, ContainerRole.ProfileOrChild);

            return new PipelineGraph(childGraph, instances, _root, _root.Singletons, _root.Transients);
        }
Ejemplo n.º 14
0
            public void Process(Type type, PluginGraph graph)
            {
                if (!IsConcrete(type)) return;

                if (type.Name.EndsWith("Actor") && type.Implements<AsyncHttpActor>())
                    graph.AddType(typeof(AsyncHttpActor), type);
            }
        public void build_root_for_tracked_transients()
        {
            var pluginGraph = new PluginGraph { TransientTracking = TransientTracking.ExplicitReleaseMode };
            var graph = PipelineGraph.BuildRoot(pluginGraph);

            graph.Transients.ShouldBeOfType<TrackingTransientCache>();
        }
        public void build_root_for_default_tracking_style()
        {
            var pluginGraph = new PluginGraph {TransientTracking = TransientTracking.DefaultNotTrackedAtRoot};
            var graph = PipelineGraph.BuildRoot(pluginGraph);

            graph.Transients.ShouldBeOfType<NulloTransientCache>();
        }
 public void Process(Type type, PluginGraph graph)
 {
     Type interfaceType = type.FindInterfaceThatCloses(typeof(IHbmWriter<>));
     if (interfaceType != null)
     {
         graph.AddType(interfaceType, type);
     }
 }
 // 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
         .Select(ctor => new { Constructor = ctor, Parameters = ctor.GetParameters() })
         .Where(x => x.Parameters.All(param => graph.HasFamily(param.ParameterType)))
         .OrderByDescending(x => x.Parameters.Length)
         .Select(x => x.Constructor)
         .FirstOrDefault();
Ejemplo n.º 19
0
        public ConstructorInfo Find(Type pluggedType, DependencyCollection dependencies, PluginGraph graph)
        {
            // if this rule does not apply to the pluggedType,
            // just return null to denote "not applicable"
            if (!pluggedType.CanBeCastTo<BaseThing>()) return null;

            return pluggedType.GetConstructor(new[] {typeof (IWidget)});
        }
Ejemplo n.º 20
0
 public RootPipelineGraph(PluginGraph pluginGraph)
 {
     _pluginGraph = pluginGraph;
     _transientCache = new NulloTransientCache();
     _profiles =
         new Cache<string, IPipelineGraph>(
             name => new ComplexPipelineGraph(this, _pluginGraph.Profile(name), new NulloTransientCache()));
 }
        public void default_lifecycle_not_set_on_any_level()
        {
            var graph = new PluginGraph();

            var pipeline = PipelineGraph.BuildRoot(graph).Profiles.For("Red");
            pipeline.Instances.DefaultLifecycleFor(typeof(IGateway))
                .ShouldBeNull();
        }
 public ConstructorInfo Find(Type pluggedType, DependencyCollection dependencies, PluginGraph graph)
 {
     return pluggedType
         .GetConstructors()
         .Where(x => !HasMissingPrimitives(x, dependencies))
         .OrderByDescending(x => x.GetParameters().Count())
         .FirstOrDefault();
 }
        public void SetUp()
        {
            graph = new PluginGraph();
            pipeline = new PipelineGraph(graph);
            library = new InterceptorLibrary();

            builder = new ObjectBuilder(pipeline, library);
        }
        public void singleton_is_just_the_plugin_graph_singletons()
        {
            var plugins = new PluginGraph();
            plugins.SingletonCache.ShouldNotBeNull();

            var pipeline = new RootPipelineGraph(plugins);
            pipeline.Singletons.ShouldBeTheSameAs(plugins.SingletonCache);
        }
Ejemplo n.º 25
0
        public void default_lifecycle_is_explicitly_set()
        {
            var graph = new PluginGraph();
            graph.Families[typeof(IGateway)].SetLifecycleTo<SingletonLifecycle>();

            var root = new RootInstanceGraph(graph);
            root.DefaultLifecycleFor(typeof(IGateway)).ShouldBeOfType<SingletonLifecycle>();
        }
Ejemplo n.º 26
0
        public void default_lifecycle_is_null_if_family_has_no_lifecycle()
        {
            var graph = new PluginGraph();
            graph.Families[typeof (IGateway)].SetDefault(new SmartInstance<StubbedGateway>());

            var root = new RootInstanceGraph(graph);
            root.DefaultLifecycleFor(typeof(IGateway)).ShouldBeNull();
        }
 public InstanceMementoPropertyReader(ConfiguredInstance instance, InstanceMemento memento,
     PluginGraph pluginGraph, Type pluginType)
 {
     _instance = instance;
     _memento = memento;
     _pluginGraph = pluginGraph;
     _pluginType = pluginType;
 }
Ejemplo n.º 28
0
        public IPipelineGraph NewChild(PluginGraph parent)
        {
            var childGraph = parent.NewChild();

            var instances = new ComplexInstanceGraph(_root, childGraph, ContainerRole.ProfileOrChild);

            var transientTracking = parent.TransientTracking == TransientTracking.DefaultNotTrackedAtRoot ? _root.Transients : new TrackingTransientCache();
            return new PipelineGraph(childGraph, instances, _root, _root.Singletons, transientTracking);
        }
        public void lifecyle_for_pluginType_not_explicitly_set_falls_back_to_parent()
        {
            var graph = new PluginGraph();
            graph.Families[typeof(IGateway)].SetLifecycleTo<SingletonLifecycle>();

            var pipeline = PipelineGraph.BuildRoot(graph).Profiles.For("Red");
            pipeline.Instances.DefaultLifecycleFor(typeof(IGateway))
                .ShouldBeOfType<SingletonLifecycle>();
        }
Ejemplo n.º 30
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);
        }
Ejemplo n.º 31
0
        public void ScanForTypes(TypePool types, PluginGraph pluginGraph)
        {
            var registry = new Registry();

            types.For(_assemblies, _filter).Each(
                type => _conventions.Each(c => c.Process(type, registry)));

            registry.As <IPluginGraphConfiguration>().Configure(pluginGraph);
            _postScanningActions.Each(x => x(pluginGraph));
        }
Ejemplo n.º 32
0
        public static PluginGraph BuildGraphFromAssembly(Assembly assembly)
        {
            var graph = new PluginGraph();

            graph.Scan(x => x.Assembly(assembly));

            graph.Seal();

            return(graph);
        }
Ejemplo n.º 33
0
        /// <summary>
        /// Creates a top level PluginGraph with the default policies
        /// </summary>
        /// <param name="profile"></param>
        /// <returns></returns>
        public static PluginGraph CreateRoot(string profile = null)
        {
            var graph = new PluginGraph();

            graph.ProfileName = profile ?? "DEFAULT";

            graph.Families[typeof(Func <>)].SetDefault(new FuncFactoryTemplate());
            graph.Families[typeof(Func <,>)].SetDefault(new FuncWithArgFactoryTemplate());
            graph.Families[typeof(Lazy <>)].SetDefault(new LazyFactoryTemplate());

            return(graph);
        }
Ejemplo n.º 34
0
        public void ScanForTypes(PluginGraph pluginGraph)
        {
            var registry = new Registry();

            TypeRepository.FindTypes(_assemblies, TypeClassification.All, _filter.Matches)
            .ContinueWith(t =>
            {
                t.Result.Each(type => _conventions.Each(c => c.Process(type, registry)));
            }).Wait();

            registry.As <IPluginGraphConfiguration>().Configure(pluginGraph);
            _postScanningActions.Each(x => x(pluginGraph));
        }
Ejemplo n.º 35
0
        public void Apply(PluginGraph graph)
        {
            var registry = new Registry();

            _interfaces.Each(@interface => {
                var expression = registry.For(@interface);
                ConfigureFamily(expression);

                _concretions.Where(x => x.CanBeCastTo(@interface)).Each(type => expression.Add(type));
            });

            registry.As <IPluginGraphConfiguration>().Configure(graph);
        }
Ejemplo n.º 36
0
        public void RegisterSingleImplementations(PluginGraph graph)
        {
            var singleImplementationRegistry = new SingleImplementationRegistry();

            _types.Each((pluginType, types) => {
                if (types.Count == 1)
                {
                    singleImplementationRegistry.AddType(pluginType, types[0]);
                    ConfigureFamily(singleImplementationRegistry.For(pluginType));
                }
            });
            singleImplementationRegistry.As <IPluginGraphConfiguration>().Configure(graph);
        }
        internal void ScanForAll(PluginGraph pluginGraph)
        {
            var registry = new Registry();

            pluginGraph.Types.For(_assemblies, _filter).Each(
                type =>
            {
                _scanners.Each(x => x.Process(type, pluginGraph));
                _conventions.Each(c => c.Process(type, registry));
            });

            registry.ConfigurePluginGraph(pluginGraph);
            _postScanningActions.Each(x => x(pluginGraph));
        }
 public TypePool(PluginGraph graph)
 {
     _types.OnMissing = assembly =>
     {
         try
         {
             return(assembly.GetExportedTypes());
         }
         catch (Exception ex)
         {
             graph.Log.RegisterError(170, ex, assembly.FullName);
             return(new Type[0]);
         }
     };
 }
Ejemplo n.º 39
0
 public PluginFamilyCollection(PluginGraph pluginGraph)
 {
     _pluginGraph    = pluginGraph;
     _pluginFamilies = new Dictionary <Type, PluginFamily>();
 }
Ejemplo n.º 40
0
 public CloseGenericFamilyPolicy(PluginGraph graph)
 {
     _graph = graph;
 }