-
-
Notifications
You must be signed in to change notification settings - Fork 208
/
ServiceCollectionExtensions.cs
38 lines (32 loc) · 1.39 KB
/
ServiceCollectionExtensions.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
using Microsoft.Extensions.DependencyInjection.Extensions;
using Sentry;
using Sentry.AspNetCore;
using Sentry.Extensibility;
using Sentry.Extensions.Logging.Extensions.DependencyInjection;
// ReSharper disable once CheckNamespace -- Discoverability
namespace Microsoft.Extensions.DependencyInjection;
/// <summary>
/// Extension methods for <see cref="IServiceCollection"/>
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public static class ServiceCollectionExtensions
{
/// <summary>
/// Adds Sentry's services to the <see cref="IServiceCollection"/>
/// </summary>
/// <param name="services">The services.</param>
public static ISentryBuilder AddSentry(this IServiceCollection services)
{
services.AddSingleton<ISentryEventProcessor, AspNetCoreEventProcessor>();
services.AddSingleton<ISentryEventExceptionProcessor, AspNetCoreExceptionProcessor>();
services.AddHttpContextAccessor();
services.TryAddSingleton<IUserFactory, DefaultUserFactory>();
services.TryAddSingleton<ISentryUserFactory, DefaultUserFactory>();
services
.AddSingleton<IRequestPayloadExtractor, FormRequestPayloadExtractor>()
// Last
.AddSingleton<IRequestPayloadExtractor, DefaultRequestPayloadExtractor>();
services.AddSentry<SentryAspNetCoreOptions>();
return new SentryAspNetCoreBuilder(services);
}
}