示例#1
0
 private PipelineGraph(ProfileManager profileManager, GenericsPluginGraph genericsGraph, GraphLog log)
 {
     _profileManager = profileManager;
     _genericsGraph  = genericsGraph;
     _log            = log;
     _transientCache = new MainObjectCache();
 }
示例#2
0
        /// <summary>
        /// Determines if the PluggedType can be upcast to the pluginType
        /// </summary>
        /// <param name="pluginType"></param>
        /// <param name="pluggedType"></param>
        /// <returns></returns>
        public static bool CanBeCastTo(this Type pluggedType, Type pluginType)
        {
            if (pluggedType == null)
            {
                return(false);
            }

            if (pluggedType == pluginType)
            {
                return(true);
            }


            if (pluginType.IsOpenGeneric())
            {
                return(GenericsPluginGraph.CanBeCast(pluginType, pluggedType));
            }

            if (IsOpenGeneric(pluggedType))
            {
                return(false);
            }


            return(pluginType.GetTypeInfo().IsAssignableFrom(pluggedType.GetTypeInfo()));
        }
示例#3
0
            /// <summary>
            /// Determines if the pluggedType can be upcast to the pluginType
            /// </summary>
            /// <param name="pluginType"></param>
            /// <param name="pluggedType"></param>
            /// <returns></returns>
            public static bool CanBeCastTo(this Type pluggedType, Type pluginType)
            {
                if (pluggedType == null)
                {
                    return(false);
                }

                if (pluggedType.IsInterface || pluggedType.IsAbstract)
                {
                    return(false);
                }

                if (pluginType.IsOpenGeneric())
                {
                    return(GenericsPluginGraph.CanBeCast(pluginType, pluggedType));
                }

                if (IsOpenGeneric(pluggedType))
                {
                    return(false);
                }


                return(pluginType.IsAssignableFrom(pluggedType));
            }
示例#4
0
        public void can_iterate_through_families()
        {
            var graph = new GenericsPluginGraph();

            graph.FindFamily(typeof(IGenericService <>)).AddType(typeof(GenericService <>));
            graph.FindFamily(typeof(IService <>)).AddType(typeof(Service <>));

            graph.Families.Count().ShouldEqual(2);
        }
示例#5
0
 public void Plugin_can_service_a_generic_type()
 {
     Assert.IsTrue(GenericsPluginGraph.CanBePluggedIntoGenericType(typeof(IConcept <>), typeof(SpecificConcept),
                                                                   typeof(object)));
     Assert.IsFalse(GenericsPluginGraph.CanBePluggedIntoGenericType(typeof(IConcept <>), typeof(SpecificConcept),
                                                                    typeof(string)));
     Assert.IsFalse(GenericsPluginGraph.CanBePluggedIntoGenericType(typeof(IConcept <>), typeof(SpecificConcept),
                                                                    typeof(int)));
 }
    public void Process(Type type, Registry registry)
    {
        if (!type.IsConcrete())
        {
            return;
        }

        var interfaceTypes = type.FindInterfacesThatClose(typeof(BaseService <>));

        foreach (var closedGenericType in interfaceTypes)
        {
            if (GenericsPluginGraph.CanBeCast(closedGenericType, type))
            {
                registry.For(closedGenericType).Singleton().Use(type).Named(type.Name);
            }
        }
    }
示例#7
0
        public void Import_from_adds_all_new_PluginFamily_from_source()
        {
            var sourceFamily  = new PluginFamily(typeof(ISomething <>));
            var sourceFamily2 = new PluginFamily(typeof(ISomething2 <>));
            var sourceFamily3 = new PluginFamily(typeof(ISomething3 <>));
            var source        = new GenericsPluginGraph();

            source.AddFamily(sourceFamily);
            source.AddFamily(sourceFamily2);
            source.AddFamily(sourceFamily3);

            var destination = new GenericsPluginGraph();

            destination.ImportFrom(source);

            Assert.AreEqual(3, destination.FamilyCount);

            Assert.AreNotSame(sourceFamily, destination.FindFamily(typeof(ISomething <>)));
        }
示例#8
0
        public void GetTemplatedFamily()
        {
            var          pluginGraph = new PluginGraph();
            PluginFamily family      = pluginGraph.FindFamily(typeof(IGenericService <>));

            family.AddPlugin(typeof(GenericService <>), "Default");
            family.AddPlugin(typeof(SecondGenericService <>), "Second");
            family.AddPlugin(typeof(ThirdGenericService <>), "Third");

            var genericsGraph = new GenericsPluginGraph();

            genericsGraph.AddFamily(family);

            PluginFamily templatedFamily = genericsGraph.CreateTemplatedFamily(typeof(IGenericService <int>),
                                                                               new ProfileManager());

            Assert.IsNotNull(templatedFamily);
            Assert.AreEqual(typeof(IGenericService <int>), templatedFamily.PluginType);
        }
示例#9
0
 private void assertCanNotBeCast(Type pluginType, Type TPluggedType)
 {
     Assert.IsFalse(GenericsPluginGraph.CanBeCast(pluginType, TPluggedType));
 }
示例#10
0
 private void assertCanNotBeCast(Type pluginType, Type TPluggedType)
 {
     GenericsPluginGraph.CanBeCast(pluginType, TPluggedType).ShouldBeFalse();
 }
示例#11
0
 public void SmokeTestCanBeCaseWithImplementationOfANonGenericInterface()
 {
     GenericsPluginGraph.CanBeCast(typeof(ITarget <,>), typeof(DisposableTarget <,>)).ShouldBeTrue();
 }
示例#12
0
 private void assertCanBeCast(Type pluginType, Type pluggedType)
 {
     Assert.IsTrue(GenericsPluginGraph.CanBeCast(pluginType, pluggedType));
 }