-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathEventSinkExtExtensions.cs
More file actions
52 lines (41 loc) · 1.9 KB
/
EventSinkExtExtensions.cs
File metadata and controls
52 lines (41 loc) · 1.9 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System.Collections.Generic;
using Duende.IdentityServer.Events;
using Duende.IdentityServer.Services;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using RSK.Audit;
using RSK.Audit.EF;
using Rsk.DuendeIdentityServer.AuditEventSink;
using Rsk.Samples.IdentityServer.AdminUiIntegration.Services;
using AuditProviderFactory = RSK.Audit.EF.AuditProviderFactory;
namespace Rsk.Samples.IdentityServer.AdminUiIntegration.Extensions;
public static class EventSinkExtExtensions
{
public static IServiceCollection AddAuditProviderFactory(this IServiceCollection services, DbContextOptionsBuilder<AuditDatabaseContext> auditDbBuilder, string schemName = null)
{
RSK.Audit.AuditProviderFactory auditFactory = new AuditProviderFactory(auditDbBuilder.Options, schemName);
services.AddSingleton(auditFactory.CreateAuditSource("IdentityServer"));
services.AddSingleton<IEventSink, AuditSink>();
return services;
}
public static IServiceCollection AddEventSinks(this IServiceCollection services)
{
var sp = services.BuildServiceProvider();
var eventSinkAgLogger = sp.GetService<ILogger<EventSinkAggregator>>();
var defaultEventLogger = sp.GetService<ILogger<DefaultEventService>>();
var eventStore = sp.GetService<IEventStore>();
var memoryCache = sp.GetService<IMemoryCache>();
IRecordAuditableActions recordAuditableActions = sp.GetService<IRecordAuditableActions>();
services.AddSingleton(provider => new EventSinkAggregator(eventSinkAgLogger)
{
EventSinks = new List<IEventSink>()
{
new CustomEventSink(defaultEventLogger, eventStore),
new AuditSink(recordAuditableActions),
}
});
return services;
}
}