-
Notifications
You must be signed in to change notification settings - Fork 0
/
Startup.cs
92 lines (77 loc) · 3.48 KB
/
Startup.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
using System;
using System.IO;
using System.Reflection;
using AzureFunctions.Extensions.Swashbuckle;
using AzureFunctions.Extensions.Swashbuckle.Settings;
using Microsoft.Azure.Functions.Extensions.DependencyInjection;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Swashbuckle.AspNetCore.SwaggerGen;
[assembly: FunctionsStartup(typeof(az_function.Startup))]
namespace az_function
{
public class Startup : FunctionsStartup
{
IConfiguration configuration;
public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
{
FunctionsHostBuilderContext context = builder.GetContext();
builder.ConfigurationBuilder
.AddJsonFile(Path.Combine(context.ApplicationRootPath, "appsettings.json"), optional: true, reloadOnChange: false)
.AddJsonFile(Path.Combine(context.ApplicationRootPath, $"appsettings.{context.EnvironmentName}.json"), optional: true, reloadOnChange: false)
.AddEnvironmentVariables();
configuration = builder.ConfigurationBuilder.Build();
}
public override void Configure(IFunctionsHostBuilder builder)
{
builder.AddSwashBuckle(Assembly.GetExecutingAssembly(), opts =>
{
opts.AddCodeParameter = true;
opts.Documents = new[] {
new SwaggerDocument {
Name = "v1",
Title = "Swagger document",
Description = "Integrate Swagger UI With Azure Functions",
Version = "v2"
}
};
opts.ConfigureSwaggerGen = x =>
{
x.CustomOperationIds(apiDesc =>
{
return apiDesc.TryGetMethodInfo(out MethodInfo mInfo) ? mInfo.Name : default(Guid).ToString();
});
};
});
builder.Services.AddSingleton(configuration);
builder.Services.AddTransient<IGptClient>(provider =>
{
var apiKey = configuration["GPT_API_KEY"];
return new GptClient(apiKey);
});
builder.Services.AddTransient<IEmailClient>(provider =>
{
var senderEmail = configuration["EMAIL_ACCOUNT"];
var senderPassword = configuration["EMAIL_PASSWORD"];
var smtpHost = configuration["SMTP_HOST"];
var smtpPort = int.Parse(configuration["SMTP_PORT"]);
return new SmtpEmailClient(senderEmail, senderPassword, smtpHost, smtpPort);
});
// Register your services here
builder.Services.AddTransient<ILLMCompletionGenerator>(provider =>
{
// Resolve the IEmailClient dependency
var gptClient = provider.GetRequiredService<IGptClient>();
return new ItineraryGenerator(gptClient, configuration);
});
builder.Services.AddTransient<IFileGenerator, PdfGenerator>();
builder.Services.AddTransient<IFileUploader, BlobUploader>();
builder.Services.AddTransient<IEmailSender>(provider =>
{
// Resolve the IEmailClient dependency
var emailClient = provider.GetRequiredService<IEmailClient>();
return new EmailSender(emailClient);
});
}
}
}