public static Type DetermineLoaderType(Type type)
        {
            if (type.CanBeCastTo<IApplicationLoader>()) return type;

            if (type.CanBeCastTo<FubuRegistry>()) return typeof (FubuRegistryLoader<>).MakeGenericType(type);

            throw new ArgumentOutOfRangeException("type", "Only IApplicationLoader types can be used here");
        }
 public void Process(Type type, Registry registry) {
     if (type.CanBeCastTo<Controller>() && !type.IsAbstract) {
         registry.For(type).LifecycleIs(new UniquePerRequestLifecycle());
     }
     else if (type.CanBeCastTo<ApiController>() && !type.IsAbstract)
     {
         registry.For(type).LifecycleIs(new UniquePerRequestLifecycle());
     }
 }
        public static bool IsWebFormView(Type type)
        {



            return type != typeof(FubuPage) 
                && !type.IsOpenGeneric()
                && type.CanBeCastTo<Page>() 
                && type.CanBeCastTo<IFubuPage>();
        }
        public static bool IsLoaderTypeCandidate(Type type)
        {
            if (type.IsOpenGeneric()) return false;

            if (!type.IsConcreteWithDefaultCtor()) return false;

            if (type.CanBeCastTo<FubuRegistry>()) return true;

            return type.CanBeCastTo<IApplicationLoader>();
        }
示例#5
0
 public void Process(Type type, Registry registry)
 {
     if (type.CanBeCastTo<ITeam>() && type != typeof(ITeam))
     {
         registry.For(typeof(ITeam)).Add(type);
     }
 }
示例#6
0
        internal static SequenceDefinition CreateCollectionDefinition(Type type)
        {
            // IEnumerable<T> with Add(T) method
            Type itemType = type.GetGenericInterfaceType(typeof(IEnumerable<>));
            if (itemType != null)
            {
                MethodInfo addMethod = type.GetMethod("Add", new[] { itemType });
                if (addMethod != null)
                {
                    return new CollectionDefinition(type, itemType, ObjectInterfaceProvider.GetAction(addMethod));
                }
            }

            // IEumerable with Add(object) method
            if (type.CanBeCastTo(typeof(IEnumerable)))
            {
                MethodInfo addMethod = type.GetMethod("Add", new[] { typeof(object) });
                if (addMethod != null)
                {
                    return new CollectionDefinition(type, typeof(object), ObjectInterfaceProvider.GetAction(addMethod));
                }
            }

            return null;
        }
 public void Process(Type type, Registry registry)
 {
     if (type.CanBeCastTo(typeof(Controller)) && !type.IsAbstract)
     {
         registry.For(type).LifecycleIs(new UniquePerRequestLifecycle());// will create a new instance per request
     }
 }
 public void Process(Type type, StructureMap.Configuration.DSL.Registry registry)
 {
     if (type.CanBeCastTo(typeof(Controller)) && !type.IsAbstract)
     {
         registry.For(type).LifecycleIs(new UniquePerRequestLifecycle());
     }
 }
示例#9
0
 public IEnumerable<IValidationRule> RulesFor(Type type)
 {
     if (type.CanBeCastTo<IValidated>())
     {
         yield return new SelfValidatingClassRule(type);
     }
 }
        public static Type DetermineLoaderType(Type type)
        {
            if (type.CanBeCastTo<IApplicationLoader>()) return type;

            if (type.CanBeCastTo<IBootstrapper>())
            {
                return typeof (BootstrapperApplicationLoader<>).MakeGenericType(type);
            }

            var @interface = type.FindInterfaceThatCloses(typeof (IApplicationSource<,>));
            if (@interface == null) throw new ArgumentOutOfRangeException("type must implement either IBootstrapper, IApplicationLoader, or IApplicationSource<TApplication,TRuntime> (FubuMVC's IApplicationSource)");

            var genericArguments = @interface.GetGenericArguments();
            return typeof (ApplicationLoader<,,>)
                .MakeGenericType(type, genericArguments.First(), genericArguments.Last());
        }
 private void Process(Type type, Registry registry)
 {
     if (type.CanBeCastTo(typeof(Controller)) && !type.IsAbstract)
     {
         registry.For(type).LifecycleIs(new UniquePerRequestLifecycle());
     }
 }
示例#12
0
 public void Process(Type type, Registry registry)
 {
     if (type.CanBeCastTo(typeof(BaseDataService<>)) && !type.IsAbstract)
     {
         registry.For(type).LifecycleIs(new UniquePerRequestLifecycle());
     }
 }
示例#13
0
        public ConstructorInfo Find(Type pluggedType)
        {
            // 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 Type[] {typeof (IWidget)});
        }
 public void Process(Type type, Registry registry)
 {
     if (type.CanBeCastTo<IValueProvider>())
     {
         var factoryType = typeof(StructureMapValueProviderFactory<>).MakeGenericType(type);
         registry.For<ValueProviderFactory>().Use(c => (ValueProviderFactory)c.GetInstance(factoryType));
     }
 }
示例#15
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)});
        }
        public bool MatchesType(Type type)
        {
            if (typeof (IHandler).IsAssignableFrom(type)) return false;

            return
                type.ImplementsInterfaceTemplate(typeof (IListener<>)) ||
                type.CanBeCastTo(typeof (ICloseable));
        }
        public void Process(Type type, Registry registry)
        {
            if (!type.CanBeCastTo(typeof(IResponseWriter))) return;

            var name = type.Name.Replace("ResponseWriter", "");

            registry.AddType(typeof (IResponseWriter), type, name);
        }
        public void Process(Type type, Registry registry)
        {
            if (!type.CanBeCastTo(typeof(IStatusCodeTranslator))) return;

            var name = type.Name.Replace("StatusCodeTranslator", "");

            registry.AddType(typeof (IStatusCodeTranslator), type, name);
        }
示例#19
0
 public void Process(Type type, Registry registry)
 {
     if (type.CanBeCastTo(_pluginType) && Constructor.HasConstructors(type))
     {
         string name = _getName(type);
         registry.AddType(GetLeastSpecificButValidType(_pluginType, type), type, name);
     }
 }
        public AuthorizationFailureAttribute(Type failureHandler)
        {
            if (!failureHandler.CanBeCastTo<IAuthorizationFailureHandler>())
            {
                throw new ArgumentOutOfRangeException("failureHandler", "Must be a concrete type of IAuthorizationFailureHandler");
            }

            _type = failureHandler;
        }
示例#21
0
        public ChromeAttribute(Type contentType)
        {
            if (!contentType.CanBeCastTo<ChromeContent>())
            {
                throw new ArgumentOutOfRangeException("contentType", "contentType must be ChromeContent or a subclass of ChromeContent");
            }

            _contentType = contentType;
        }
        public AutoCompleteTagBuilder(Type lookupType)
        {
            if (!lookupType.CanBeCastTo<ILookupProvider>())
            {
                throw new ArgumentOutOfRangeException("lookupType", "lookupType must be assignable to ILookupProvider");
            }

            _lookupType = lookupType;
        }
示例#23
0
        public void Process(Type type, Registry registry)
        {
            if (!type.CanBeCastTo(typeof (IController)))
                return;

            string name = GetName(type);

            registry.AddType(typeof (IController), type, name);
        }
示例#24
0
        public EventMapping(StreamMapping parent, Type eventType) : base(eventType)
        {
            if (!eventType.CanBeCastTo<IEvent>())
                throw new ArgumentOutOfRangeException(nameof(eventType),
                    $"Only types implementing {typeof (IEvent)} can be accepted");

            Stream = parent;

            EventTypeName = ToEventTypeName(eventType);
        }
示例#25
0
        public static void IgnorePropertiesMarkedWithAttribute(Type attributeType)
        {
            if (!attributeType.CanBeCastTo(typeof(Attribute)))
                throw new ArgumentException("Type must derive from Attribute", "attributeType");

            lock (IgnoreAttributes)
            {
                IgnoreAttributes.Add(attributeType);
            }
        }
示例#26
0
        public RemoteFieldRule(Type type, Accessor accessor)
        {
            if(!type.CanBeCastTo<IFieldValidationRule>())
            {
                throw new ArgumentException("Must be an IFieldValidationRule", "type");
            }

            _type = type;
            _accessor = accessor;
        }
示例#27
0
        public void Process(Type type, Registry registry)
        {
            if (type.CanBeCastTo<IValidationRegistration>() && type.IsConcreteWithDefaultCtor())
            {
                var registration = (IValidationRegistration)Activator.CreateInstance(type);
                _registrations.Add(registration);

                registration.FieldSources().Each(x => registry.For<IFieldValidationSource>().Add(x));
            }
        }
        public void Process(Type type, Registry registry)
        {
            if (type.GetTypeInfo().IsAbstract) return;
            if (type.GetTypeInfo().IsInterface) return;

            if (type.CanBeCastTo(_pluginType) && type.HasConstructors())
            {
                var name = _getName(type);
                registry.AddType(GetLeastSpecificButValidType(_pluginType, type), type, name);
            }
        }
        public static Type RuleTypeFor(Type inputType, Type attributeType)
        {
            if (attributeType.CanBeCastTo<IAuthorizationPolicy>()) return attributeType;

            if (attributeType.Closes(typeof(IAuthorizationRule<>)))
            {
                return typeof(AuthorizationPolicy<,>).MakeGenericType(inputType, attributeType);
            }

            throw new ArgumentOutOfRangeException("attributeType", "attributeType must implement either IAuthorizationPolicy or IAuthorizationRule<> for the input type");
        }
        public IModelBinder GetBinder(Type modelType)
        {
            if (modelType.CanBeCastTo<Entity>())
            {
                var entityBinderType = typeof(EntityModelBinder<>).MakeGenericType(modelType);
                var entityBinder = ServiceLocator.Current.GetInstance(entityBinderType);
                return (IModelBinder)entityBinder;
            }

            return null;
        }