-
-
Save justinyoo/86fad732d01180d58f23d84e2d9927dd to your computer and use it in GitHub Desktop.
Testing Precompiled Azure Functions
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
namespace PrecompiledLibraries | |
{ | |
public class MyHttpTriggerWithDependencies | |
{ | |
// Define service locator as a publically accessible static field | |
public static MyServiceLocator Locator = new MyServiceLocator(); | |
// Define function | |
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log) | |
{ | |
string name = req.GetQueryNameValuePairs() | |
.FirstOrDefault(q => string.Compare(q.Key, "name", true) == 0) | |
.Value; | |
var res = new HttpResponseMessage(); | |
if (name == null) | |
{ | |
res.StatusCode = HttpStatusCode.BadRequest; | |
res.Content = new ObjectContent<string>("Please pass a name on the query string or in the request body", new JsonMediaTypeFormatter()); | |
return res; | |
} | |
var value = Locator.Dependency.SomeValue; // Gets the instance from the service locator | |
res.StatusCode = HttpStatusCode.OK; | |
res.Content = new ObjectContent<string>($"Hello {name}, here's the dependency value of **{value}**", new JsonMediaTypeFormatter()); | |
return res; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment