-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCostTrackingDecoratorFactory.cs
More file actions
30 lines (27 loc) · 1.06 KB
/
CostTrackingDecoratorFactory.cs
File metadata and controls
30 lines (27 loc) · 1.06 KB
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
using Microsoft.Extensions.DependencyInjection;
namespace ProjectVG.Application.Services.Chat.CostTracking
{
public static class CostTrackingDecoratorFactory
{
public static IServiceCollection AddCostTrackingDecorator<T>(
this IServiceCollection services,
string processName,
ServiceLifetime lifetime = ServiceLifetime.Scoped)
where T : class
{
// 원본 서비스 등록
services.Add(new ServiceDescriptor(typeof(T), typeof(T), lifetime));
// 비용 추적 데코레이터 등록
services.Add(new ServiceDescriptor(
typeof(ICostTrackingDecorator<T>),
provider =>
{
var service = provider.GetRequiredService<T>();
var metricsService = provider.GetRequiredService<IChatMetricsService>();
return new CostTrackingDecorator<T>(service, metricsService, processName);
},
lifetime));
return services;
}
}
}