/// <summary> /// Creates the controller handler for the given descriptor. /// </summary> /// <param name="descriptor">The descriptor.</param> /// <returns></returns> public override IControllerHandler CreateControllerHandler(IControllerDescriptor descriptor) { var type = descriptor.ControllerType as Type; if (type != null && typeof(IValidatable).IsAssignableFrom(type)) return new ValidatingControllerHandler(application, descriptor, application.LoggerFactory.GetLogger(typeof(ControllerHandler))); return base.CreateControllerHandler(descriptor); }
/// <summary> /// Initializes a new instance of the <see cref="ValidatingControllerHandler"/> class. /// </summary> /// <param name="descriptor"></param> /// <param name="logger"></param> protected internal ValidatingControllerHandler(Application application, IControllerDescriptor descriptor, ILogger logger) : base(application, descriptor, logger) { try { validators.InsertRange(0, ValidationRepository.Instance.RegisterValidatable(descriptor.ControllerType as Type)); } catch (InvalidCastException) { logger.Report(Exceptions.InvalidCast, descriptor.ControllerTypeName); } catch (Exception ex) { logger.Report(Exceptions.RuntimeError, ex, ex.Message, descriptor.ControllerTypeName); } }
/// <summary> /// Creates the controller handler for the given descriptor. /// </summary> /// <param name="descriptor">The descriptor.</param> /// <returns></returns> public virtual IControllerHandler CreateControllerHandler(IControllerDescriptor descriptor) { return new ControllerHandler(application, descriptor, application.LoggerFactory.GetLogger(typeof(ControllerHandler))); }
/// <summary> /// Initializes a new instance of the <see cref="ControllerHandler"/> class. /// </summary> /// <param name="controllerType">Type of the controller.</param> protected internal ControllerHandler(Application application, IControllerDescriptor descriptor, ILogger logger) { this.descriptor = descriptor; this.logger = logger; this.application = application; controllerConstructor = ((Type)descriptor.ControllerType).GetConstructor(Type.EmptyTypes); foreach (ControllerDescriptor.BindPointDescriptor bindPoint in descriptor.Targets) manipulatedFields.AddRange(bindPoint.ParameterFields.Values); manipulatedFields.AddRange(descriptor.FormFields.Values); manipulatedFields.AddRange(descriptor.RequestFields.Values); manipulatedFields.AddRange(descriptor.SessionFields.Values); foreach (ControllerDescriptor.CookieFieldDescriptor cookieField in descriptor.CookieFields.Values) manipulatedFields.Add(cookieField.Field); manipulatedFields.ForEach( (mbr) => { var attributes = mbr.GetCustomAttributes(typeof(FormatAsAttribute), false) as FormatAsAttribute[]; // Field can be Request and FormField at the same time. In that case - it will be added twice into the collection. if ((attributes.Length != 1) || (formatters.ContainsKey(mbr))) return; formatters.Add(mbr, application.FormatManagerFactory.GetManagerInstance().GetFormatterByFormat(attributes[0].FormatName)); } ); BuildMapper(descriptor); }
/// <summary> /// Builds the mapper. MapsWith attribute takes priority over InferMappingFor. Also, multiple mapping attributes are currently unsupported. /// </summary> /// <param name="descriptor">The descriptor.</param> protected virtual void BuildMapper(IControllerDescriptor descriptor) { var mapperAttribute = descriptor.ControllerType.GetCustomAttributes(typeof (MapsWithAttribute), false) as MapsWithAttribute[]; if (mapperAttribute != null && mapperAttribute.Length == 1) { mapper = Activator.CreateInstance(mapperAttribute[0].MapperType) as EntityMapperBase; if (mapper != null) { MapperRepository.Instance.RegisterMapper(mapper); return; } } var inferredAttribute = descriptor.ControllerType.GetCustomAttributes(typeof(InferMappingForAttribute), false) as InferMappingForAttribute[]; if (inferredAttribute != null && inferredAttribute.Length == 1) { var mapperType = typeof (EntityMapper<,>).MakeGenericType(new Type[] { descriptor.ControllerType as Type, inferredAttribute[0].TargetType }); mapper = Activator.CreateInstance(mapperType) as EntityMapperBase; // configure the mapper based on the strict flag. if (inferredAttribute[0].Strict) mapper.InferStrictOnly(); else mapper.InferOnly(); MapperRepository.Instance.RegisterMapper(mapper); } }
public void RegisterController(IControllerDescriptor info) { IMethodsControllerDesc infoNew = info as IMethodsControllerDesc; if (infoNew == null) { Logger.Report(Errors.InterfaceNotSupported, info.ControllerTypeName); } RegisterController(infoNew); }
public override void RegisterController(IControllerDescriptor descriptor) { dispatcherFactory.GetDispatcherInstance().RegisterController(descriptor); }
/// <summary> /// Registers the controller. /// </summary> /// <param name="descriptor">The descriptor.</param> public virtual void RegisterController(IControllerDescriptor descriptor) { handlers.Add(descriptor.ControllerType, handlerFactory.CreateControllerHandler(descriptor)); dispatcherFactory.GetDispatcherInstance().RegisterController(descriptor); }