-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfiguration.cs
More file actions
80 lines (68 loc) · 3.05 KB
/
Configuration.cs
File metadata and controls
80 lines (68 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using AzureDevopsTracker.Adapters;
using AzureDevopsTracker.Data;
using AzureDevopsTracker.Data.Context;
using AzureDevopsTracker.Integrations;
using AzureDevopsTracker.Interfaces;
using AzureDevopsTracker.Interfaces.Internals;
using AzureDevopsTracker.Services;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Linq;
namespace AzureDevopsTracker.Configurations
{
public static class Configuration
{
public static IServiceCollection AddAzureDevopsTracker(this IServiceCollection services,
DataBaseConfig configurations,
MessageConfig messageConfig = null)
{
services.AddDbContext<AzureDevopsTrackerContext>(options =>
options.UseSqlServer(DataBaseConfig.ConnectionsString));
try
{
using var serviceScope = services.BuildServiceProvider().CreateScope();
var dbContext = serviceScope.ServiceProvider.GetRequiredService<AzureDevopsTrackerContext>();
var pendingMigrations = dbContext.Database.GetPendingMigrations();
if (pendingMigrations.Any())
dbContext.Database.Migrate();
}
catch
{ }
services.AddMessageIntegrations();
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddScoped<AzureDevopsTrackerContext>();
services.AddScoped<IWorkItemAdapter, WorkItemAdapter>();
services.AddScoped<IWorkItemRepository, WorkItemRepository>();
services.AddScoped<IAzureDevopsTrackerService, AzureDevopsTrackerService>();
services.AddScoped<IChangeLogService, ChangeLogService>();
services.AddScoped<IChangeLogItemRepository, ChangeLogItemRepository>();
services.AddScoped<IChangeLogRepository, ChangeLogRepository>();
return services;
}
private static IServiceCollection AddMessageIntegrations(this IServiceCollection services)
{
switch (MessageConfig.Messenger)
{
case EMessengers.DISCORD:
services.AddScoped<MessageIntegration, DiscordIntegration>();
break;
case EMessengers.MICROSOFT_TEAMS:
services.AddScoped<MessageIntegration, MicrosoftTeamsIntegration>();
break;
default:
services.AddScoped<MessageIntegration, FakeIntegration>();
break;
}
return services;
}
public static IApplicationBuilder UseAzureDevopsTracker(this IApplicationBuilder app, IServiceProvider serviceProvider)
{
var context = serviceProvider.GetService<AzureDevopsTrackerContext>();
context.Database.Migrate();
return app;
}
}
}