mirror of
https://github.com/microsoft/onefuzz.git
synced 2025-06-23 06:38:50 +00:00
Switch dependency injection to Scoped (#1801)
Co-authored-by: stas <statis@microsoft.com>
This commit is contained in:
@ -17,17 +17,17 @@ public class Program
|
||||
{
|
||||
public async Async.Task Invoke(FunctionContext context, FunctionExecutionDelegate next)
|
||||
{
|
||||
//TODO
|
||||
//if correlation ID is available in HTTP request
|
||||
//if correlation ID is available in Queue message
|
||||
//log.ReplaceCorrelationId
|
||||
|
||||
var log = (ILogTracerInternal?)context.InstanceServices.GetService<ILogTracer>();
|
||||
if (log is not null)
|
||||
{
|
||||
log.AddTags(new[] {
|
||||
("InvocationId", context.InvocationId.ToString())
|
||||
//TODO
|
||||
//if correlation ID is available in HTTP request
|
||||
//if correlation ID is available in Queue message
|
||||
//log.ReplaceCorrelationId(Guid from request)
|
||||
|
||||
log.ReplaceCorrelationId(Guid.NewGuid());
|
||||
log.AddTags(new[] {
|
||||
("InvocationId", context.InvocationId.ToString())
|
||||
});
|
||||
}
|
||||
|
||||
@ -65,17 +65,21 @@ public class Program
|
||||
)
|
||||
.ConfigureServices((context, services) =>
|
||||
services
|
||||
.AddScoped<ILogTracer>(_ => new LogTracerFactory(GetLoggers()).CreateLogTracer(Guid.NewGuid(), severityLevel: EnvironmentVariables.LogSeverityLevel()))
|
||||
.AddSingleton<INodeOperations, NodeOperations>()
|
||||
.AddSingleton<IEvents, Events>()
|
||||
.AddSingleton<IWebhookOperations, WebhookOperations>()
|
||||
.AddSingleton<IWebhookMessageLogOperations, WebhookMessageLogOperations>()
|
||||
.AddSingleton<ITaskOperations, TaskOperations>()
|
||||
.AddSingleton<IQueue, Queue>()
|
||||
.AddSingleton<ICreds, Creds>()
|
||||
.AddSingleton<IStorage, Storage>()
|
||||
.AddSingleton<IProxyOperations, ProxyOperations>()
|
||||
.AddSingleton<IConfigOperations, ConfigOperations>()
|
||||
.AddScoped<ILogTracer>(s => new LogTracerFactory(GetLoggers()).CreateLogTracer(Guid.Empty, severityLevel: EnvironmentVariables.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>()
|
||||
|
||||
//TODO: move out expensive resources into separate class, and add those as Singleton
|
||||
// ArmClient, Table Client(s), Queue Client(s), HttpClient, etc.
|
||||
|
||||
)
|
||||
.Build();
|
||||
|
||||
|
Reference in New Issue
Block a user