Created
April 1, 2018 14:44
-
-
Save justinyoo/87b71ac2e6a5773f7325aa9067bf4dc2 to your computer and use it in GitHub Desktop.
Dependency Injections on Azure Functions V2
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
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 github = Container.GetService<GitHub>(); | |
var httpClient = Container.GetService<HttpClient>(); | |
var requestUrl = $"{github.BaseUrl}{string.Format(github.Endpoints.Repositories, type, name)}"; | |
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