{"id":28917328,"url":"https://github.com/mrahhal/mr.aspnetcore.mvcpack","last_synced_at":"2025-10-10T10:38:49.830Z","repository":{"id":56345759,"uuid":"80996302","full_name":"mrahhal/MR.AspNetCore.MvcPack","owner":"mrahhal","description":"A better way for writing controller action filters, inspired by rails.","archived":false,"fork":false,"pushed_at":"2020-11-13T05:18:38.000Z","size":43,"stargazers_count":5,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-22T00:12:54.245Z","etag":null,"topics":["aspnetcore","csharp","filters","mvc"],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mrahhal.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-05T13:56:48.000Z","updated_at":"2025-03-01T08:40:28.000Z","dependencies_parsed_at":"2022-08-15T17:00:54.630Z","dependency_job_id":null,"html_url":"https://github.com/mrahhal/MR.AspNetCore.MvcPack","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/mrahhal/MR.AspNetCore.MvcPack","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrahhal%2FMR.AspNetCore.MvcPack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrahhal%2FMR.AspNetCore.MvcPack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrahhal%2FMR.AspNetCore.MvcPack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrahhal%2FMR.AspNetCore.MvcPack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mrahhal","download_url":"https://codeload.github.com/mrahhal/MR.AspNetCore.MvcPack/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrahhal%2FMR.AspNetCore.MvcPack/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261212832,"owners_count":23125596,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aspnetcore","csharp","filters","mvc"],"created_at":"2025-06-22T00:12:53.874Z","updated_at":"2025-10-10T10:38:44.787Z","avatar_url":"https://github.com/mrahhal.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MR.AspNetCore.MvcPack\n\n[![Build status](https://img.shields.io/appveyor/ci/mrahhal/mr-aspnetcore-mvcpack/master.svg)](https://ci.appveyor.com/project/mrahhal/mr-aspnetcore-mvcpack)\n\n[![NuGet version](https://img.shields.io/nuget/v/MR.AspNetCore.MvcPack.svg)](https://www.nuget.org/packages/MR.AspNetCore.MvcPack)\n[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n\nA better way for writing controller action filters, inspired by rails.\n\n## Usage\n\n#### Configure\n\n```cs\nservices\n    .AddMvc(...)\n    .InitializeMvcPack(); // Add this\n\nservices.AddMvcPack(); // Add this\n```\n\n#### Packs\n\nA \"pack\" is a class that configures a certain controller. You can put them anywhere, but as this is inspired by rails I like to put them nested in the controller class:\n\n```cs\npublic class SomeController : SomeBaseController\n{\n    public class Pack : MvcPackSupport\u003cSomeController\u003e\n    {\n        public Pack()\n        {\n            // Use this if you want to skip a filter configured in a base controller.\n            SkipBeforeAction(x =\u003e x.AuthorizeSome);\n\n            // Always run a filter.\n            BeforeAction(x =\u003e x.Some1);\n\n            // Use this to configure a filter to be run `only` when certain actions are selected.\n            BeforeAction(x =\u003e x.Some2, only: L(\n                nameof(SomeController.Get)));\n\n            // Use this to configure a filter to be run on all except certain actions.\n            BeforeAction(x =\u003e x.Some3, except: L(\n                nameof(SomeController.Foo),\n                nameof(SomeController.Bar)));\n        }\n    }\n\n    // This should always be the prototype of method filters.\n    protected Task Some1(ActionExecutingContext context)\n    {\n        // You can inspect action arguments, do authorization, set a result to shortcircuit if necessary, etc...\n    }\n}\n```\n\n## Motive\n\nThis is all about factoring out specific controllers' cross cutting concerns and putting them inside reusable methods.\n\nCreating custom filters for each business concern is tedious, and overriding a controller's \"OnActionExecuting\" loses its appeal when you're inheriting other custom controllers that also have concerns.\n\nRails solves this in a great way, a major part of it is due to the expressiveness of ruby as a language. Asp.Net Core doesn't give us that flexibility by default, but we can improvise.\n\nCheck the samples for more info.\n\n## NestedRouting\n\nUsing this together with [NestedRouting](http://github.com/mrahhal/MR.AspNetCore.NestedRouting) will give you a great way for organizing your controllers.\n\n## Samples\n\nCheck out the [`samples`](samples) under \"samples/\" for more practical use cases.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrahhal%2Fmr.aspnetcore.mvcpack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmrahhal%2Fmr.aspnetcore.mvcpack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrahhal%2Fmr.aspnetcore.mvcpack/lists"}