Skip to content

Instantly share code, notes, and snippets.

@justinyoo
Created January 19, 2017 06:51
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/86fad732d01180d58f23d84e2d9927dd to your computer and use it in GitHub Desktop.
Save justinyoo/86fad732d01180d58f23d84e2d9927dd to your computer and use it in GitHub Desktop.
Testing Precompiled Azure Functions
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