mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 09:11:10 +00:00
Adds telemetry instrumentation to application handlers
This commit is contained in:
1 parent
ffcb25c13f
commit
a2c99b1b79
13 files changed
+862
-2
No files matched your search
@@ -1,4 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Telemetry;
|
||||
using Lumina.Domain.Common.Events;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
@@ -46,9 +47,18 @@ public static class ApplicationLayerServices
|
||||
continue;
|
||||
|
||||
if (registration.Contract.GetGenericTypeDefinition() == typeof(Infrastructure.Validation.IValidator<>))
|
||||
{
|
||||
services.AddSingleton(registration.Contract, registration.Implementation);
|
||||
else
|
||||
services.AddScoped(registration.Contract, registration.Implementation);
|
||||
continue;
|
||||
}
|
||||
|
||||
// wrap query, command, and domain event handlers in their telemetry decorator, so that every invocation emits traces, metrics, and structured logs
|
||||
services.AddScoped(registration.Contract, serviceProvider =>
|
||||
{
|
||||
object handler = ActivatorUtilities.GetServiceOrCreateInstance(serviceProvider, registration.Implementation);
|
||||
Type decoratorType = TelemetryDecoratorFactory.GetDecoratorType(registration.Contract);
|
||||
return ActivatorUtilities.CreateInstance(serviceProvider, decoratorType, handler);
|
||||
});
|
||||
}
|
||||
|
||||
return services;
|
||||
|
||||
Reference in new issue
Block a user