-
Notifications
You must be signed in to change notification settings - Fork 9.8k
/
DatabaseDeveloperPageExceptionFilterServiceExtensions.cs
37 lines (33 loc) · 1.6 KB
/
DatabaseDeveloperPageExceptionFilterServiceExtensions.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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using Microsoft.AspNetCore.Diagnostics;
using Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection.Extensions;
namespace Microsoft.Extensions.DependencyInjection
{
/// <summary>
/// Service extension methods for the <see cref="DatabaseDeveloperPageExceptionFilter"/>.
/// </summary>
public static class DatabaseDeveloperPageExceptionFilterServiceExtensions
{
/// <summary>
/// In combination with UseDeveloperExceptionPage, this captures database-related exceptions that can be resolved by using Entity Framework migrations.
/// When these exceptions occur, an HTML response with details about possible actions to resolve the issue is generated.
/// </summary>
/// <param name="services">The <see cref="IServiceCollection"/> for adding services.</param>
/// <returns></returns>
/// <remarks>
/// This should only be enabled in the Development environment.
/// </remarks>
public static IServiceCollection AddDatabaseDeveloperPageExceptionFilter(this IServiceCollection services)
{
if (services == null)
{
throw new ArgumentNullException(nameof(services));
}
services.TryAddEnumerable(new ServiceDescriptor(typeof(IDeveloperPageExceptionFilter), typeof(DatabaseDeveloperPageExceptionFilter), ServiceLifetime.Singleton));
return services;
}
}
}