In playing around with Razor Pages, I was irritated again that Microsoft couldn't just standardize a set of interfaces for their methods so that they wouldn't need so much magic.
So I just quickly hacked up RazorInterfaces, available also on nuget.org. It's probably most useful to people just learning Razor Pages, since it requires you to correctly implement the common HTTP methods you'll need to get things running:
public class CustomerPage : PageModel
, IPageGet
, IPagePostAsync<Customer>
{
public IActionResult OnGet()
{
return Page();
}
public async Task<IActionResult> OnPostAsync(Customer customer)
{
await DataLayer.Update(customer);
return Page();
}
}
There are interfaces for all of the standard HTTP methods: GET, POST, PUT, DELETE, HEAD, OPTIONS. The interface names conform to the following format: IPage[HTTP method]
and IPage[HTTP method]Async
for the async variant, and there are variants also accepting a single type parameter, IPage[HTTP method]<T>
and IPage[HTTP method]Async<T>
.
Comments
I've almost got a pretty fast Ruby-on-Rails like ControllerBase abstract base class that gives me List, Create, Update, Delete pretty much for free.