-
-
Save justinyoo/ec58468adb190e94621e73f463e3bc31 to your computer and use it in GitHub Desktop.
Precompiled Azure Functions Revisited
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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