コード例 #1
0
            public void Process(Type type, Registry registry)
            {
                // Only work on concrete types
                if (!type.IsConcrete() || type.IsGenericType) return;

                // Register against all the interfaces implemented
                // by this concrete class
                type.GetInterfaces().Each(@interface => { registry.For(@interface).Use(type); });
            }
コード例 #2
0
        public IBindingScope To(Type concreteType)
        {
            Assert.IsNotNull(concreteType);
            Assert.IsTrue(concreteType.IsConcrete());
            Assert.IsTrue(concreteType.Is(ContractType));

            return ToMethod(c => c.Container.Instantiator
                .Instantiate(new InjectionContext { Container = c.Container, DeclaringType = concreteType }));
        }
		public IEnumerable<Route> GetServiceRoutes(Type serviceType)
		{
			if (!serviceType.IsConcrete())
				throw new ArgumentException("Type " + serviceType + " must be a concrete type", "serviceType");

			return MethodsToRoutes(
				this.GetServiceMethodsFrom(serviceType)
					.Where(x => !x.IsShadowed(serviceType))
					.Select(x => x.IsVirtual? x.GetBaseDefinition(): x));
		}
コード例 #4
0
        void IAssemblyScannerConvention.Process(Type type, IUnityRegistry registry)
        {
            if (!type.IsConcrete() || !type.CanBeCreated())
                return;

            Type interfaceType = GetInterfaceType(type);

            if (interfaceType != null)
                registry.Register(interfaceType, type);
        }
コード例 #5
0
        public void Process(Type type, Registry registry)
        {
            if (!type.IsConcrete()) return;

            var baseType = type.BaseType;
            if (baseType != null && baseType.IsGenericType && baseType.GetGenericTypeDefinition() == m_mapType)
            {
                registry.AddType(baseType, type);
            }
        }
コード例 #6
0
        public void Process(Type type, Registry registry)
        {
            // Only work on concrete types
            if (!type.IsConcrete() || type.IsGenericType) return;

            // Register against all the interfaces implemented
            // by this concrete class
            type.GetInterfaces()
                .Where(@interface => @interface.Name == string.Format("I{0}", type.Name))
                .ForEach(@interface => registry.For(@interface).Use(type).Singleton());
        }
コード例 #7
0
        public override void Process(Type type, Registry registry)
        {
            if (!type.IsConcrete() || !type.CanBeCreated()) return;

            Type interfaceType = type.AllInterfaces().FirstOrDefault();
            if (interfaceType != null)
            {
                registry.AddType(interfaceType, type);
                ConfigureFamily(registry.For(interfaceType));
            }
        }
コード例 #8
0
        public override void Process(Type type, Registry registry)
        {
            if (!type.IsConcrete()) return;

            var pluginType = FindPluginType(type);
            if (pluginType != null && type.HasConstructors())
            {
                registry.AddType(pluginType, type);
                ConfigureFamily(registry.For(pluginType));
            }
        }
コード例 #9
0
        public override void Process(Type type, Registry registry)
        {
            if (!type.IsConcrete() || !type.CanBeCreated()) return;

            Type interfaceType = type.AllInterfaces().FirstOrDefault();
            if (interfaceType != null)
            {
                Debug.WriteLine("Plugging {0} into {1}".ToFormat(type.Name, interfaceType.Name));
                registry.AddType(interfaceType, type);
                ConfigureFamily(registry.For(interfaceType));
            }
        }
コード例 #10
0
ファイル: EntityModelBinder.cs プロジェクト: pjdennis/fubumvc
        public object Bind(Type type, IBindingContext context)
        {
            var entity = context.ValueAs(type, "Id");

            if (entity != null) return entity;

            if (type.IsConcrete())
            {
                return Activator.CreateInstance(type);
            }

            return null;
        }
コード例 #11
0
        public void Process(Type type, Registry registry)
        {
            if (!type.IsConcrete())
                return;
            
            if (!typeof(IHelpContext).IsAssignableFrom(type))
                return;

            var name = type.GetCustomAttributes(false).OfType<InstanceNameAttribute>().Select(x => x.Name).FirstOrDefault();
            if (string.IsNullOrEmpty(name))
                return;
            registry.For(typeof(IHelpContext)).Use(type).Named(name.ToLowerInvariant());
        }
コード例 #12
0
        public override void Process(Type type, Registry registry)
        {
            if (!type.IsConcrete())
                return;
            
            var pluginType = FindPluginType(type);
            if (pluginType == null || !Constructor.HasConstructors(type))
                return;

            registry.For(pluginType)
                .EnrichWith(z => DynamicProxy.CreateInterfaceProxyWithTarget(pluginType, z, _aspects))
                .Use(type);
        }
コード例 #13
0
        public void Process(Type type, Registry registry)
        {
            // Only work on concrete types
            if (!type.IsConcrete() || type.IsGenericType) return;

            // Add against all the interfaces implemented
            // by this concrete class
            type.GetInterfaces()
                .Where(@interface => @interface.Name == $"I{type.Name}" )
                .ForEach(@interface => registry.For(@interface).Use(type).Singleton());

            if (type.Name.EndsWith("Job"))
                registry.For(type).Singleton();
        }
コード例 #14
0
        public Func<string, object> ConverterFor(Type type)
        {
            if (!type.IsConcrete()) {
                return null;
            }
            var constructor = type.GetConstructor (new [] { typeof(string) });
            if (constructor == null) {
                return null;
            }

            var param = Expression.Parameter (typeof(string), "arg");
            var body = Expression.New (constructor, param);

            return Expression.Lambda<Func<string, object>> (body, param).Compile();
        }
コード例 #15
0
        public override void Process(Type type, Registry registry)
        {
            var interfaceTypes = type.FindInterfacesThatClose(_openType);
            if (!interfaceTypes.Any()) return;

            if (type.IsConcrete())
            {
                _concretions.Add(type);
            }

            foreach (var interfaceType in interfaceTypes)
            {
                _interfaces.Add(interfaceType);
            }
        }
コード例 #16
0
	    public void Process(Type type, Registry registry)
	    {
            // ignore interfaces and abstract classes
            if (type.IsConcrete() == false)
                return;

            Type baseType = type.BaseType;

            // IF type has basetype AND basetype is generic AND basetype is Map<> THEN
            if (baseType != null && baseType.IsGenericType && baseType.GetGenericTypeDefinition() == m_mapType)
            {
                var instance = Activator.CreateInstance(type);
                string instanceName = instance.GetType().GetProperty("TemplatePath").GetValue(instance, null).ToString();
                registry.AddType(typeof(IMap), type, instanceName.ToLower());
            }
	    }
コード例 #17
0
        PluginFamily IFamilyPolicy.Build(Type pluginType)
        {
            if (pluginType.IsConcrete())
            {
                return null;
            }

            var family = new PluginFamily(pluginType);

            var service = _locator.Service(pluginType);

            var instance = new ObjectInstance(service);

            family.SetDefault(instance);

            return family;
        }
コード例 #18
0
ファイル: CoreExtensions.cs プロジェクト: RexMorgan/Commander
        private static IEnumerable<Type> rawFindInterfacesThatCloses(Type pluggedType, Type templateType)
        {
            if (!pluggedType.IsConcrete()) yield break;

            if (templateType.IsInterface)
            {
                foreach (var interfaceType in pluggedType.GetInterfaces().Where(type => type.IsGenericType && (type.GetGenericTypeDefinition() == templateType)))
                {
                    yield return interfaceType;
                }
            }
            else if (pluggedType.BaseType.IsGenericType && (pluggedType.BaseType.GetGenericTypeDefinition() == templateType))
            {
                yield return pluggedType.BaseType;
            }

            if (pluggedType.BaseType == typeof(object)) yield break;

            foreach (var interfaceType in rawFindInterfacesThatCloses(pluggedType.BaseType, templateType))
            {
                yield return interfaceType;
            }
        }
コード例 #19
0
ファイル: Bootstrapper.cs プロジェクト: raveller/raveller
            public void Process(Type type, Registry registry)
            {
                if (!type.IsConcrete())
                    return;

                Type matchingInterface = type.GetInterfaces().Where(x => x.Name.EndsWith(type.Name)).FirstOrDefault();
                if (matchingInterface == null)
                    return;

                registry.For(matchingInterface).Use(type);
            }
コード例 #20
0
ファイル: __Run.cs プロジェクト: distantcam/ProjectTemplate
 private static bool IsConventionTest(Type type)
 {
     return type.IsClass && type.IsConcrete<IConventionTest>();
 }
コード例 #21
0
 public void Process(Type type, Registry registry)
 {
     if (type.IsConcrete() && type.Name.EndsWith("Job"))
         registry.For(type).Singleton();
 }
コード例 #22
0
ファイル: ContainerBootstrapper.cs プロジェクト: wbinford/nu
            public void Process(Type type, Registry registry)
            {
                if (!type.IsConcrete())
                    return;

                if (!type.Name.EndsWith("Impl"))
                    return;

                string interfaceName = type.Name.Substring(0, type.Name.Length - 4);

                Type match = type.GetInterfaces()
                    .Where(x => x.Name.Equals(interfaceName))
                    .Where(x => type.Namespace.StartsWith(x.Namespace))
                    .SingleOrDefault();

                if (match != null)
                {
                    registry.AddType(match, type);
                }
            }
		public bool CanCreateBindingDelegateFor(Type requestType)
		{
			return requestType.IsConcrete();
		}