Пример #1
0
 private static bool FilterMatchesController(FilterContext filterContext, FilterMetadata metadata)
 {
     return(metadata.ControllerType != null &&
            metadata.ControllerType.IsAssignableFrom(filterContext.ControllerType) &&
            metadata.FilterScope == FilterScope.Controller &&
            metadata.MethodInfo == null);
 }
Пример #2
0
        AsFilterFor <TFilter, TController>(IRegistrationBuilder <object, IConcreteActivatorData, SingleRegistrationStyle> registration, string metadataKey, Expression <Action <TController> > actionSelector, int order)
            where TController : IController
        {
            if (registration == null)
            {
                throw new ArgumentNullException(nameof(registration));
            }

            if (actionSelector == null)
            {
                throw new ArgumentNullException(nameof(actionSelector));
            }

            var limitType = registration.ActivatorData.Activator.LimitType;

            if (!limitType.IsAssignableTo <TFilter>())
            {
                string message = string.Format(CultureInfo.CurrentCulture, RegistrationExtensionsResources.MustBeAssignableToFilterType,
                                               limitType.FullName, typeof(TFilter).FullName);
                throw new ArgumentException(message, nameof(registration));
            }

            var metadata = new FilterMetadata
            {
                ControllerType = typeof(TController),
                FilterScope    = FilterScope.Action,
                MethodInfo     = GetMethodInfo(actionSelector),
                Order          = order
            };

            return(registration.As <TFilter>().WithMetadata(metadataKey, metadata));
        }
Пример #3
0
        private static void AsOverrideFor <TFilter, TController>(ContainerBuilder builder, string metadataKey)
        {
            var metadata = new FilterMetadata
            {
                ControllerType = typeof(TController),
                FilterScope    = FilterScope.Controller,
                MethodInfo     = null
            };

            builder.RegisterInstance(new AutofacOverrideFilter(typeof(TFilter)))
            .As <IOverrideFilter>()
            .WithMetadata(metadataKey, metadata);
        }
Пример #4
0
        private static void AsOverrideFor <TFilter, TController>(ContainerBuilder builder, string metadataKey, Expression <Action <TController> > actionSelector)
        {
            if (actionSelector == null)
            {
                throw new ArgumentNullException(nameof(actionSelector));
            }

            var metadata = new FilterMetadata
            {
                ControllerType = typeof(TController),
                FilterScope    = FilterScope.Action,
                MethodInfo     = GetMethodInfo(actionSelector)
            };

            builder.RegisterInstance(new AutofacOverrideFilter(typeof(TFilter)))
            .As <IOverrideFilter>()
            .WithMetadata(metadataKey, metadata);
        }
Пример #5
0
 private static bool FilterMatchesAction(FilterContext filterContext, MethodInfo methodInfo, FilterMetadata metadata)
 {
     return(metadata.ControllerType != null &&
            metadata.ControllerType.IsAssignableFrom(filterContext.ControllerType) &&
            metadata.FilterScope == FilterScope.Action &&
            metadata.MethodInfo.GetBaseDefinition() == methodInfo.GetBaseDefinition());
 }