Skip to content

Instantly share code, notes, and snippets.

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/fce7529f4bd2bfd2d4afeae5e713cf12 to your computer and use it in GitHub Desktop.
Save justinyoo/fce7529f4bd2bfd2d4afeae5e713cf12 to your computer and use it in GitHub Desktop.
Dependency Injections on Azure Functions V2
public static class CoreGitHubRepositoriesHttpTrigger
{
public static IServiceProvider Container = new ContainerBuilder()
.RegisterModule(new CoreAppModule())
.Build();
[FunctionName("CoreGitHubRepositoriesHttpTrigger")]
public static async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "get", Route = "core/repositories")]HttpRequest req, ILogger log)
{
var type = this._req.Query["type"];
var name = this._req.Query["name"];
var requestUrl = $"https://api.github.com/{type}/{name}/repos";
var httpClient = Container.GetService<HttpClient>();
using (var message = await httpClient.GetAsync(requestUrl).ConfigureAwait(false))
{
var result = await message.Content.ReadAsStringAsync().ConfigureAwait(false);
var res = JsonConvert.DeserializeObject<object>(result);
return new OkObjectResult(res);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment