- Move some persistent resources into SingletonResources class (#1835)

- Rename ResultOk to ResultVoid

Move environment variables to singleton

Co-authored-by: stas <statis@microsoft.com>
This commit is contained in:
Stas
2022-04-22 17:40:11 -07:00
committed by GitHub
parent 62d824383a
commit e86854cf2a
22 changed files with 192 additions and 158 deletions

View File

@ -37,15 +37,15 @@ public class Program
}
public static List<ILog> GetLoggers()
public static List<ILog> GetLoggers(IServiceConfig config)
{
List<ILog> loggers = new List<ILog>();
foreach (var dest in EnvironmentVariables.LogDestinations)
foreach (var dest in config.LogDestinations)
{
loggers.Add(
dest switch
{
LogDestination.AppInsights => new AppInsights(),
LogDestination.AppInsights => new AppInsights(config.ApplicationInsightsInstrumentationKey!),
LogDestination.Console => new Console(),
_ => throw new Exception($"Unhandled Log Destination type: {dest}"),
}
@ -66,14 +66,14 @@ public class Program
)
.ConfigureServices((context, services) =>
services
.AddScoped<ILogTracer>(s => new LogTracerFactory(GetLoggers()).CreateLogTracer(Guid.Empty, severityLevel: EnvironmentVariables.LogSeverityLevel()))
.AddScoped<ILogTracer>(s =>
new LogTracerFactory(GetLoggers(s.GetService<IServiceConfig>()!)).CreateLogTracer(Guid.Empty, severityLevel: s.GetService<IServiceConfig>()!.LogSeverityLevel))
.AddScoped<INodeOperations, NodeOperations>()
.AddScoped<IEvents, Events>()
.AddScoped<IWebhookOperations, WebhookOperations>()
.AddScoped<IWebhookMessageLogOperations, WebhookMessageLogOperations>()
.AddScoped<ITaskOperations, TaskOperations>()
.AddScoped<IQueue, Queue>()
.AddScoped<ICreds, Creds>()
.AddScoped<IStorage, Storage>()
.AddScoped<IProxyOperations, ProxyOperations>()
.AddScoped<IConfigOperations, ConfigOperations>()
@ -83,9 +83,11 @@ public class Program
.AddScoped<INotificationOperations, NotificationOperations>()
.AddScoped<IUserCredentials, UserCredentials>()
//TODO: move out expensive resources into separate class, and add those as Singleton
// ArmClient, Table Client(s), Queue Client(s), HttpClient, etc.
//Move out expensive resources into separate class, and add those as Singleton
// ArmClient, Table Client(s), Queue Client(s), HttpClient, etc.
.AddSingleton<ICreds, Creds>()
.AddSingleton<IServiceConfig, ServiceConfiguration>()
)
.Build();