Skip to content

Instantly share code, notes, and snippets.

@justinyoo
Created April 29, 2017 23:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinyoo/ec58468adb190e94621e73f463e3bc31 to your computer and use it in GitHub Desktop.
Save justinyoo/ec58468adb190e94621e73f463e3bc31 to your computer and use it in GitHub Desktop.
Precompiled Azure Functions Revisited
using System;
using System.Configuration;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs.Host;
using PrecompiledSample.EntityModels;
using PrecompiledSample.Services;
namespace PrecompiledSample.Functions
{
public static class GetProductHttpTrigger
{
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
log.Info("C# HTTP trigger function processed a request.");
var productId = req.GetQueryNameValuePairs()
.FirstOrDefault(q => q.Key.Equals("id", StringComparison.CurrentCultureIgnoreCase))
.Value;
var connectionString = ConfigurationManager.ConnectionStrings["PrecompiledDbContext"].ConnectionString;
var dbContext = new PrecompiledDbContext(connectionString);
var service = new ProductService(dbContext);
var product = await service.GetAsync(productId).ConfigureAwait(false);
return req.CreateResponse(HttpStatusCode.OK, product);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment