Saturday, October 6, 2018

RazorInterfaces: interfaces for the standard HTTP methods

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>.

Sunday, August 12, 2018

Minimal ASP.NET Core Dependencies for Google Cloud

After a long hiatus, I'm slowly starting back on blogging and some personal projects. To get me back in the swing of things, here's a short post on running ASP.NET core on Google Cloud, since this seems poorly documented online.

The default project created by the Google Cloud tools includes Microsoft.AspNetCore.All which is a huge dependency. If you want something more minimal:

  1. uninstall-package Microsoft.AspNetCore.All
  2. install-package Microsoft.AspNetCore
  3. install-package Microsoft.AspNetCore.Mvc.Core
  4. install-package Microsoft.AspNetCore.Mvc

This creates a runnable project using the standard Google Cloud Web API project template, although it still isn't ideal as it includes the Razor pages dependencies.