| | 1 | | using ApplicationCore; |
| | 2 | | using ApplicationCore.Analytics; |
| | 3 | | using ApplicationCore.Model; |
| | 4 | | using Microsoft.Azure.WebJobs.Host.Bindings; |
| | 5 | | using Microsoft.Extensions.Configuration; |
| | 6 | | using Microsoft.Extensions.DependencyInjection; |
| | 7 | | using Microsoft.Extensions.Options; |
| | 8 | |
|
| | 9 | | namespace JekyllBlogCommentsAzure |
| | 10 | | { |
| | 11 | | public static class IServiceCollectionExtensions |
| | 12 | | { |
| | 13 | | public static IServiceCollection AddPostCommentService(this IServiceCollection services) |
| 2 | 14 | | { |
| 2 | 15 | | var executionContextOptions = services.BuildServiceProvider() |
| 2 | 16 | | .GetService<IOptions<ExecutionContextOptions>>().Value; |
| 2 | 17 | | var currentDirectory = executionContextOptions.AppDirectory; |
| | 18 | |
|
| 2 | 19 | | var configRoot = new ConfigurationBuilder() |
| 2 | 20 | | .SetBasePath(currentDirectory) |
| 2 | 21 | | .AddJsonFile("local.settings.json", optional: true, reloadOnChange: true) |
| 2 | 22 | | .AddEnvironmentVariables() |
| 2 | 23 | | .Build(); |
| | 24 | |
|
| 2 | 25 | | var config = new WebConfiguration(configRoot, new ConfigProvider()); |
| | 26 | |
|
| 2 | 27 | | var commentFactory = new CommentFactory( |
| 2 | 28 | | new CommentFormFactory(), |
| 2 | 29 | | new TextAnalyzer(config.TextAnalytics, new TextAnalyticsClientFactory(new CredentialsFactory()))); |
| 2 | 30 | | var pullRequestService = new PullRequestService( |
| 2 | 31 | | config.GitHub, |
| 2 | 32 | | config.Comment, |
| 2 | 33 | | new SerializerFactory().BuildSerializer(), |
| 2 | 34 | | new GitHubClientFactory(config.GitHub).CreateClient()); |
| | 35 | |
|
| 2 | 36 | | var postCommentService = new PostCommentService(config.Comment, commentFactory, pullRequestService); |
| 2 | 37 | | services.AddSingleton<IPostCommentService>(postCommentService); |
| | 38 | |
|
| 2 | 39 | | return services; |
| 2 | 40 | | } |
| | 41 | | } |
| | 42 | | } |