-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBuddyLanguageDependencyInjection.cs
113 lines (99 loc) · 4.29 KB
/
BuddyLanguageDependencyInjection.cs
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using BuddyLanguage.AzureServices;
using BuddyLanguage.ChatGPTServiceLib;
using BuddyLanguage.Data.EntityFramework;
using BuddyLanguage.Data.EntityFramework.Repositories;
using BuddyLanguage.Domain.Interfaces;
using BuddyLanguage.Domain.Services;
using BuddyLanguage.ExternalStatisticsServiceLib;
using BuddyLanguage.KiotaClient;
using BuddyLanguage.NAudioConcentusOggOpusToPcmConverterLib;
using BuddyLanguage.OpenAIWhisperSpeechRecognitionService;
using BuddyLanguage.PromptServices;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using OpenAI.ChatGpt.EntityFrameworkCore.Extensions;
using OpenAI.Extensions;
namespace BuddyLanguage.Infrastructure;
public static class BuddyLanguageDependencyInjection
{
public static IServiceCollection AddApplicationServices(
this IServiceCollection services,
IConfiguration configuration)
{
services.AddInfrastructureServices(configuration);
services.AddDomainServices();
return services;
}
private static IServiceCollection AddInfrastructureServices(
this IServiceCollection services,
IConfiguration configuration)
{
//Services
//Azure TTS
services.AddOptions<AzureConfig>()
.BindConfiguration("AzureTTSConfig")
.ValidateDataAnnotations()
; //.ValidateOnStart()
// Подключение репозитория для работы с Ролями
services.AddScoped(typeof(IRepository<>), typeof(EfRepository<>));
services.AddScoped<IRoleRepository, RoleRepositoryEf>();
services.AddScoped<IWordEntityRepository, WordEntityRepositoryEf>();
services.AddScoped<IUserRepository, UserRepositoryEf>();
services.AddScoped<IUnitOfWork, UnitOfWorkEf>();
// Can be replaced with Aspire.Microsoft.EntityFrameworkCore.SqlServer
services.AddDbContext<AppDbContext>(
options =>
{
options.UseSqlServer(
configuration.GetRequiredConnectionString("AZURE_SQL_CONNECTIONSTRING"),
builder =>
{
builder.UseAzureSqlDefaults();
builder.MigrationsAssembly(typeof(AppDbContext).Assembly.FullName);
})
.EnableDetailedErrors()
.EnableSensitiveDataLogging();
});
services.AddChatGptEntityFrameworkIntegration(
configuration,
options =>
{
options.UseSqlServer(
configuration.GetRequiredConnectionString("AZURE_SQL_CONNECTIONSTRING"),
builder =>
{
builder.UseAzureSqlDefaults();
builder.MigrationsAssembly(typeof(InfrastructureMig).Assembly.FullName);
})
.EnableDetailedErrors()
.EnableSensitiveDataLogging();
});
services.AddHealthChecks()
.AddDbContextCheck<AppDbContext>();
services.AddOpenAIService(
settings =>
{
settings.ApiKey = configuration.GetRequiredValue("OPENAI_API_KEY");
});
services.AddDistributedMemoryCache();
services.AddSingleton<IOggOpusToPcmConverter, NAudioConcentusOggOpusToPcmConverter>();
services.AddScoped<IPromptService, PromptService>();
services.AddScoped<ISpeechRecognitionService, WhisperSpeechRecognitionService>();
services.AddScoped<IPronunciationAssessmentService, PronunciationAssessmentService>();
services.AddHttpClient<ITextToSpeech, OpenAITextToSpeech>();
services.AddScoped<IChatGPTService, ChatGPTService>();
services.AddScoped<IStatisticsService, ExternalStatisticsService>();
//services.AddScoped<ITextToSpeech, AzureTextToSpeech>();
return services;
}
private static IServiceCollection AddDomainServices(
this IServiceCollection services)
{
services.AddScoped<RoleService>();
services.AddScoped<WordService>();
services.AddScoped<UserService>();
services.AddScoped<BuddyService>();
return services;
}
}