Skip to content

Commit 37e2433

Browse files
author
John Luo
committed
Remove decoupling attempts
1 parent cbe1da3 commit 37e2433

File tree

7 files changed

+8
-67
lines changed

7 files changed

+8
-67
lines changed

src/DefaultBuilder/src/MigrationsEndPointStartupFilter.cs

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/DefaultBuilder/src/WebHost.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
using System.IO;
66
using System.Reflection;
77
using Microsoft.AspNetCore.Builder;
8-
//using Microsoft.AspNetCore.Diagnostics;
9-
//using Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore;
108
using Microsoft.AspNetCore.HostFiltering;
119
using Microsoft.AspNetCore.Hosting;
1210
using Microsoft.AspNetCore.Hosting.StaticWebAssets;
@@ -261,12 +259,6 @@ internal static void ConfigureWebDefaults(IWebHostBuilder builder)
261259
}
262260

263261
services.AddRouting();
264-
265-
//if (hostingContext.HostingEnvironment.IsDevelopment())
266-
//{
267-
// services.AddSingleton<IDeveloperPageExceptionFilter, DatabaseErrorHandler>();
268-
// services.AddTransient<IStartupFilter, MigrationsEndPointStartupFilter>();
269-
//}
270262
})
271263
.UseIIS()
272264
.UseIISIntegration();

src/Middleware/Diagnostics.EntityFrameworkCore/src/DatabaseErrorPageExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Builder
1111
/// <summary>
1212
/// <see cref="IApplicationBuilder"/> extension methods for the <see cref="DatabaseErrorPageMiddleware"/>.
1313
/// </summary>
14-
[Obsolete("This is obsolete and will be removed in a future version. Use DatabaseExceptionHandler instead.")]
14+
[Obsolete("This is obsolete and will be removed in a future version. Use DatabaseExceptionFilter instead.")]
1515
public static class DatabaseErrorPageExtensions
1616
{
1717
/// <summary>
@@ -20,7 +20,7 @@ public static class DatabaseErrorPageExtensions
2020
/// </summary>
2121
/// <param name="app">The <see cref="IApplicationBuilder"/> to register the middleware with.</param>
2222
/// <returns>The same <see cref="IApplicationBuilder"/> instance so that multiple calls can be chained.</returns>
23-
[Obsolete("This is obsolete and will be removed in a future version. Use DatabaseExceptionHandler instead.")]
23+
[Obsolete("This is obsolete and will be removed in a future version. Use DatabaseExceptionFilter instead.")]
2424
public static IApplicationBuilder UseDatabaseErrorPage(this IApplicationBuilder app)
2525
{
2626
if (app == null)
@@ -38,7 +38,7 @@ public static IApplicationBuilder UseDatabaseErrorPage(this IApplicationBuilder
3838
/// <param name="app">The <see cref="IApplicationBuilder"/> to register the middleware with.</param>
3939
/// <param name="options">A <see cref="DatabaseErrorPageOptions"/> that specifies options for the middleware.</param>
4040
/// <returns>The same <see cref="IApplicationBuilder"/> instance so that multiple calls can be chained.</returns>
41-
[Obsolete("This is obsolete and will be removed in a future version. Use DatabaseExceptionHandler instead.")]
41+
[Obsolete("This is obsolete and will be removed in a future version. Use DatabaseExceptionFilter instead.")]
4242
public static IApplicationBuilder UseDatabaseErrorPage(
4343
this IApplicationBuilder app, DatabaseErrorPageOptions options)
4444
{

src/Middleware/Diagnostics.EntityFrameworkCore/src/DatabaseErrorPageMiddleware.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@
1212
using Microsoft.AspNetCore.Http;
1313
using Microsoft.EntityFrameworkCore;
1414
using Microsoft.EntityFrameworkCore.Diagnostics;
15-
using Microsoft.EntityFrameworkCore.Infrastructure;
16-
using Microsoft.EntityFrameworkCore.Metadata;
17-
using Microsoft.EntityFrameworkCore.Metadata.Conventions;
18-
using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure;
19-
using Microsoft.EntityFrameworkCore.Migrations;
20-
using Microsoft.EntityFrameworkCore.Storage;
2115
using Microsoft.Extensions.Logging;
2216
using Microsoft.Extensions.Options;
2317

@@ -56,7 +50,7 @@ public void Hold(Exception exception, Type contextType)
5650
/// consumes them to detect database related exception.
5751
/// </param>
5852
/// <param name="options">The options to control what information is displayed on the error page.</param>
59-
[Obsolete("This is obsolete and will be removed in a future version. Use DatabaseExceptionHandler instead.")]
53+
[Obsolete("This is obsolete and will be removed in a future version. Use DatabaseExceptionFilter instead.")]
6054
public DatabaseErrorPageMiddleware(
6155
RequestDelegate next,
6256
ILoggerFactory loggerFactory,

src/Middleware/Diagnostics.EntityFrameworkCore/src/DatabaseExceptionHandler.cs renamed to src/Middleware/Diagnostics.EntityFrameworkCore/src/DatabaseExceptionFilter.cs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,18 @@
99
using Microsoft.AspNetCore.Builder;
1010
using Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.Views;
1111
using Microsoft.EntityFrameworkCore;
12-
using Microsoft.EntityFrameworkCore.Infrastructure;
13-
using Microsoft.EntityFrameworkCore.Metadata;
14-
using Microsoft.EntityFrameworkCore.Metadata.Conventions;
15-
using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure;
16-
using Microsoft.EntityFrameworkCore.Migrations;
17-
using Microsoft.EntityFrameworkCore.Storage;
1812
using Microsoft.Extensions.DependencyInjection;
1913
using Microsoft.Extensions.Logging;
2014
using Microsoft.Extensions.Options;
2115

2216
namespace Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore
2317
{
24-
public class DatabaseErrorHandler : IDeveloperPageExceptionFilter
18+
public class DatabaseExceptionFilter : IDeveloperPageExceptionFilter
2519
{
2620
private readonly ILogger _logger;
2721
private readonly DatabaseErrorPageOptions _options;
2822

29-
public DatabaseErrorHandler(ILogger<DatabaseErrorHandler> logger, IOptions<DatabaseErrorPageOptions> options)
23+
public DatabaseExceptionFilter(ILogger<DatabaseExceptionFilter> logger, IOptions<DatabaseErrorPageOptions> options)
3024
{
3125
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
3226
_options = options?.Value ?? throw new ArgumentNullException(nameof(options));
@@ -39,7 +33,6 @@ public async Task HandleExceptionAsync(ErrorContext errorContext, Func<ErrorCont
3933
try
4034
{
4135
// Look for DbContext classes registered in the service provider
42-
// TODO: Decouple
4336
var registeredContexts = errorContext.HttpContext.RequestServices.GetServices<DbContextOptions>()
4437
.Select(o => o.ContextType);
4538

@@ -73,13 +66,9 @@ public async Task HandleExceptionAsync(ErrorContext errorContext, Func<ErrorCont
7366
{
7467
_logger.DatabaseErrorPageMiddlewareException(e);
7568
}
76-
77-
await next(errorContext);
78-
}
79-
else
80-
{
81-
await next(errorContext);
8269
}
70+
71+
await next(errorContext);
8372
}
8473
}
8574
}

src/Middleware/Diagnostics.EntityFrameworkCore/src/HttpContextDatabaseContextDetailsExtensions.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ internal static class HttpContextDatabaseContextDetailsExtensions
2222
{
2323
public static async Task<DatabaseContextDetails> GetContextDetailsAsync(this HttpContext httpContext, Type dbcontextType, ILogger logger)
2424
{
25-
// TODO: Decouple
2625
var context = (DbContext)httpContext.RequestServices.GetService(dbcontextType);
27-
// TODO: Decouple
2826
var relationalDatabaseCreator = context.GetService<IDatabaseCreator>() as IRelationalDatabaseCreator;
2927
if (relationalDatabaseCreator == null)
3028
{
@@ -39,34 +37,27 @@ public static async Task<DatabaseContextDetails> GetContextDetailsAsync(this Htt
3937
databaseExists = await relationalDatabaseCreator.HasTablesAsync();
4038
}
4139

42-
// TODO: Decouple
4340
var migrationsAssembly = context.GetService<IMigrationsAssembly>();
44-
// TODO: Decouple
4541
var modelDiffer = context.GetService<IMigrationsModelDiffer>();
4642

4743
var snapshotModel = migrationsAssembly.ModelSnapshot?.Model;
48-
// TODO: Decouple
4944
if (snapshotModel is IConventionModel conventionModel)
5045
{
51-
// TODO: Decouple
5246
var conventionSet = context.GetService<IConventionSetBuilder>().CreateConventionSet();
5347

54-
// TODO: Decouple
5548
var typeMappingConvention = conventionSet.ModelFinalizingConventions.OfType<TypeMappingConvention>().FirstOrDefault();
5649
if (typeMappingConvention != null)
5750
{
5851
typeMappingConvention.ProcessModelFinalizing(conventionModel.Builder, null);
5952
}
6053

61-
// TODO: Decouple
6254
var relationalModelConvention = conventionSet.ModelFinalizedConventions.OfType<RelationalModelConvention>().FirstOrDefault();
6355
if (relationalModelConvention != null)
6456
{
6557
snapshotModel = relationalModelConvention.ProcessModelFinalized(conventionModel);
6658
}
6759
}
6860

69-
// TODO: Decouple
7061
if (snapshotModel is IMutableModel mutableModel)
7162
{
7263
snapshotModel = mutableModel.FinalizeModel();

src/Middleware/Diagnostics.EntityFrameworkCore/src/MigrationsEndPointMiddleware.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,11 @@ public virtual async Task Invoke(HttpContext context)
7474

7575
if (db != null)
7676
{
77-
// TODO: Decouple
7877
var dbName = db.GetType().FullName;
7978
try
8079
{
8180
_logger.ApplyingMigrations(dbName);
8281

83-
// TODO: Decouple
8482
await db.Database.MigrateAsync();
8583

8684
context.Response.StatusCode = (int)HttpStatusCode.NoContent;
@@ -119,7 +117,6 @@ private static async Task<DbContext> GetDbContext(HttpContext context, ILogger l
119117
return null;
120118
}
121119

122-
// TODO: Decouple
123120
// Look for DbContext classes registered in the service provider
124121
var registeredContexts = context.RequestServices.GetServices<DbContextOptions>()
125122
.Select(o => o.ContextType);
@@ -137,7 +134,6 @@ private static async Task<DbContext> GetDbContext(HttpContext context, ILogger l
137134

138135
var contextType = Type.GetType(contextTypeName);
139136

140-
// TODO: Decouple
141137
var db = (DbContext)context.RequestServices.GetService(contextType);
142138

143139
return db;

0 commit comments

Comments
 (0)