Ejemplo n.º 1
0
        public async Task InvokeAsync(HttpContext context)
        {
            var resourceFilterProviders = context.RequestServices.GetService <IEnumerable <IResourceFilterProvider> >();

            if (resourceFilterProviders?.Any() == true)
            {
                var builder = new ResourceFilterBuilder();

                foreach (var provider in resourceFilterProviders)
                {
                    provider.AddResourceFilter(builder);
                }

                var activeFilters = builder.ResourceFilters.Where(filter => filter.Filter(context));

                if (activeFilters.Any())
                {
                    var resourceManager = context.RequestServices.GetService <IResourceManager>();

                    foreach (var filter in activeFilters)
                    {
                        filter.Execution(resourceManager);
                    }
                }
            }

            await _next(context);
        }
Ejemplo n.º 2
0
 public static ResourceFilter WhenPathStartsWith(this ResourceFilterBuilder builder, string path) =>
 builder.When(context => context.Request.Path.Value.ToUpperInvariant().StartsWith(path.ToUpperInvariant()));
Ejemplo n.º 3
0
 public static ResourceFilter WhenHomePage(this ResourceFilterBuilder builder) =>
 builder.WhenPath("/");