/
Config.cs
42 lines (36 loc) · 1.22 KB
/
Config.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
using Core.Aggregates;
using Core.OpenTelemetry;
using Core.OptimisticConcurrency;
using Microsoft.Extensions.DependencyInjection;
namespace Core.EventStoreDB.Repository;
public static class Config
{
public static IServiceCollection AddEventStoreDBRepository<T>(
this IServiceCollection services,
bool withAppendScope = true,
bool withTelemetry = true
) where T : class, IAggregate
{
services.AddScoped<IEventStoreDBRepository<T>, EventStoreDBRepository<T>>();
if (withAppendScope)
{
services.Decorate<IEventStoreDBRepository<T>>(
(inner, sp) => new EventStoreDBRepositoryWithETagDecorator<T>(
inner,
sp.GetRequiredService<IExpectedResourceVersionProvider>(),
sp.GetRequiredService<INextResourceVersionProvider>()
)
);
}
if (withTelemetry)
{
services.Decorate<IEventStoreDBRepository<T>>(
(inner, sp) => new EventStoreDBRepositoryWithTelemetryDecorator<T>(
inner,
sp.GetRequiredService<IActivityScope>()
)
);
}
return services;
}
}