React to hosting
This commit is contained in:
parent
7a245eba5b
commit
b66b2df264
|
|
@ -1,21 +1,19 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using JetBrains.Annotations;
|
||||
using Microsoft.AspNet.Builder;
|
||||
using Microsoft.AspNet.Diagnostics.Entity.Utilities;
|
||||
using Microsoft.AspNet.Diagnostics.Entity.Views;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.RequestContainer;
|
||||
using Microsoft.Data.Entity;
|
||||
using Microsoft.Data.Entity.Infrastructure;
|
||||
using Microsoft.Data.Entity.Internal;
|
||||
using Microsoft.Data.Entity.Relational;
|
||||
using Microsoft.Data.Entity.Relational.Migrations;
|
||||
using Microsoft.Framework.Logging;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.AspNet.Diagnostics.Entity
|
||||
{
|
||||
|
|
@ -64,8 +62,6 @@ namespace Microsoft.AspNet.Diagnostics.Entity
|
|||
try
|
||||
{
|
||||
if (ShouldDisplayErrorPage(_loggerProvider.Logger.LastError, ex, _logger))
|
||||
{
|
||||
using (RequestServicesContainer.EnsureRequestServices(context, _serviceProvider))
|
||||
{
|
||||
var dbContextType = _loggerProvider.Logger.LastError.ContextType;
|
||||
var dbContext = (DbContext)context.RequestServices.GetService(dbContextType);
|
||||
|
|
@ -100,7 +96,6 @@ namespace Microsoft.AspNet.Diagnostics.Entity
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogError(Strings.DatabaseErrorPageMiddleware_Exception, e);
|
||||
|
|
|
|||
|
|
@ -2,17 +2,14 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using JetBrains.Annotations;
|
||||
using Microsoft.AspNet.Builder;
|
||||
using Microsoft.AspNet.Diagnostics.Entity.Utilities;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.Data.Entity;
|
||||
using Microsoft.Data.Entity.Relational.Migrations.Infrastructure;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
using System.Net;
|
||||
using Microsoft.Framework.Logging;
|
||||
using Microsoft.AspNet.RequestContainer;
|
||||
|
||||
namespace Microsoft.AspNet.Diagnostics.Entity
|
||||
{
|
||||
|
|
@ -44,8 +41,6 @@ namespace Microsoft.AspNet.Diagnostics.Entity
|
|||
{
|
||||
_logger.LogVerbose(Strings.FormatMigrationsEndPointMiddleware_RequestPathMatched(context.Request.Path));
|
||||
|
||||
using (RequestServicesContainer.EnsureRequestServices(context, _serviceProvider))
|
||||
{
|
||||
var db = await GetDbContext(context, _logger).WithCurrentCulture();
|
||||
if (db != null)
|
||||
{
|
||||
|
|
@ -69,7 +64,6 @@ namespace Microsoft.AspNet.Diagnostics.Entity
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
await _next(context).WithCurrentCulture();
|
||||
|
|
|
|||
|
|
@ -3,8 +3,9 @@
|
|||
"description": "ASP.NET 5 Middleware for error handling, error pages, and diagnostics information.",
|
||||
"dependencies": {
|
||||
"Microsoft.AspNet.Diagnostics.Interfaces": "1.0.0-*",
|
||||
"Microsoft.AspNet.RequestContainer": "1.0.0-*",
|
||||
"Microsoft.AspNet.Hosting": "1.0.0-*",
|
||||
"Microsoft.AspNet.WebUtilities": "1.0.0-*",
|
||||
"Microsoft.Framework.OptionsModel": "1.0.0-*",
|
||||
"Microsoft.Framework.NotNullAttribute.Internal": { "type": "build", "version": "1.0.0-*" },
|
||||
"Microsoft.Framework.WebEncoders.Core": "1.0.0-*"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -231,7 +231,13 @@ namespace Microsoft.AspNet.Diagnostics.Entity.Tests
|
|||
{
|
||||
var server = TestServer.Create(app =>
|
||||
{
|
||||
app.UseServices(services =>
|
||||
var options = DatabaseErrorPageOptions.ShowAll;
|
||||
options.MigrationsEndPointPath = new PathString(migrationsEndpoint);
|
||||
app.UseDatabaseErrorPage(options);
|
||||
|
||||
app.UseMiddleware<PendingMigrationsMiddleware>();
|
||||
},
|
||||
services =>
|
||||
{
|
||||
services.AddEntityFramework().AddSqlServer();
|
||||
services.AddScoped<BloggingContextWithMigrations>();
|
||||
|
|
@ -241,13 +247,6 @@ namespace Microsoft.AspNet.Diagnostics.Entity.Tests
|
|||
services.AddInstance<DbContextOptions>(optionsBuilder.Options);
|
||||
});
|
||||
|
||||
var options = DatabaseErrorPageOptions.ShowAll;
|
||||
options.MigrationsEndPointPath = new PathString(migrationsEndpoint);
|
||||
app.UseDatabaseErrorPage(options);
|
||||
|
||||
app.UseMiddleware<PendingMigrationsMiddleware>();
|
||||
});
|
||||
|
||||
HttpResponseMessage response = await server.CreateClient().GetAsync("http://localhost/");
|
||||
|
||||
Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);
|
||||
|
|
@ -266,23 +265,18 @@ namespace Microsoft.AspNet.Diagnostics.Entity.Tests
|
|||
|
||||
var server = TestServer.Create(app =>
|
||||
{
|
||||
app.UseServices(services =>
|
||||
app.UseDatabaseErrorPage();
|
||||
app.UseMiddleware<ContextNotRegisteredInServicesMiddleware>();
|
||||
app.ApplicationServices.GetService<ILoggerFactory>().AddProvider(logProvider);
|
||||
},
|
||||
services =>
|
||||
{
|
||||
services.AddEntityFramework()
|
||||
.AddSqlServer();
|
||||
|
||||
services.AddEntityFramework().AddSqlServer();
|
||||
var optionsBuilder = new DbContextOptionsBuilder();
|
||||
optionsBuilder.UseSqlServer(database.ConnectionString);
|
||||
services.AddInstance<DbContextOptions>(optionsBuilder.Options);
|
||||
});
|
||||
|
||||
app.UseDatabaseErrorPage();
|
||||
|
||||
app.UseMiddleware<ContextNotRegisteredInServicesMiddleware>();
|
||||
|
||||
app.ApplicationServices.GetService<ILoggerFactory>().AddProvider(logProvider);
|
||||
});
|
||||
|
||||
var ex = await Assert.ThrowsAsync<SqlException>(async () =>
|
||||
await server.CreateClient().GetAsync("http://localhost/"));
|
||||
|
||||
|
|
@ -383,18 +377,6 @@ namespace Microsoft.AspNet.Diagnostics.Entity.Tests
|
|||
{
|
||||
return TestServer.Create(app =>
|
||||
{
|
||||
app.UseServices(services =>
|
||||
{
|
||||
services.AddEntityFramework()
|
||||
.AddSqlServer();
|
||||
|
||||
services.AddScoped<TContext>();
|
||||
|
||||
var optionsBuilder = new DbContextOptionsBuilder();
|
||||
optionsBuilder.UseSqlServer(database.ConnectionString);
|
||||
services.AddInstance<DbContextOptions>(optionsBuilder.Options);
|
||||
});
|
||||
|
||||
app.UseDatabaseErrorPage();
|
||||
|
||||
app.UseMiddleware<TMiddleware>();
|
||||
|
|
@ -403,6 +385,17 @@ namespace Microsoft.AspNet.Diagnostics.Entity.Tests
|
|||
{
|
||||
app.ApplicationServices.GetService<ILoggerFactory>().AddProvider(logProvider);
|
||||
}
|
||||
},
|
||||
services =>
|
||||
{
|
||||
services.AddEntityFramework()
|
||||
.AddSqlServer();
|
||||
|
||||
services.AddScoped<TContext>();
|
||||
|
||||
var optionsBuilder = new DbContextOptionsBuilder();
|
||||
optionsBuilder.UseSqlServer(database.ConnectionString);
|
||||
services.AddInstance(optionsBuilder.Options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ using Microsoft.Data.Entity.Relational.Migrations.History;
|
|||
using Microsoft.Framework.DependencyInjection;
|
||||
using Xunit;
|
||||
using Microsoft.AspNet.Diagnostics.Entity.Tests.Helpers;
|
||||
using Microsoft.AspNet.Hosting.Startup;
|
||||
|
||||
namespace Microsoft.AspNet.Diagnostics.Entity.Tests
|
||||
{
|
||||
|
|
@ -70,13 +71,6 @@ namespace Microsoft.AspNet.Diagnostics.Entity.Tests
|
|||
|
||||
TestServer server = TestServer.Create(app =>
|
||||
{
|
||||
app.UseServices(services =>
|
||||
{
|
||||
services.AddEntityFramework().AddSqlServer();
|
||||
services.AddScoped<BloggingContextWithMigrations>();
|
||||
services.AddInstance<DbContextOptions>(optionsBuilder.Options);
|
||||
});
|
||||
|
||||
if (useCustomPath)
|
||||
{
|
||||
app.UseMigrationsEndPoint(new MigrationsEndPointOptions { Path = path });
|
||||
|
|
@ -85,6 +79,12 @@ namespace Microsoft.AspNet.Diagnostics.Entity.Tests
|
|||
{
|
||||
app.UseMigrationsEndPoint();
|
||||
}
|
||||
},
|
||||
services =>
|
||||
{
|
||||
services.AddEntityFramework().AddSqlServer();
|
||||
services.AddScoped<BloggingContextWithMigrations>();
|
||||
services.AddInstance<DbContextOptions>(optionsBuilder.Options);
|
||||
});
|
||||
|
||||
using (var db = BloggingContextWithMigrations.CreateWithoutExternalServiceProvider(optionsBuilder.Options))
|
||||
|
|
@ -155,14 +155,9 @@ namespace Microsoft.AspNet.Diagnostics.Entity.Tests
|
|||
[Fact]
|
||||
public async Task Context_not_registered_in_services()
|
||||
{
|
||||
var server = TestServer.Create(app =>
|
||||
{
|
||||
app.UseServices(services =>
|
||||
{
|
||||
services.AddEntityFramework().AddSqlServer();
|
||||
});
|
||||
app.UseMigrationsEndPoint();
|
||||
});
|
||||
var server = TestServer.Create(
|
||||
app => app.UseMigrationsEndPoint(),
|
||||
services => services.AddEntityFramework().AddSqlServer());
|
||||
|
||||
var formData = new FormUrlEncodedContent(new List<KeyValuePair<string, string>>
|
||||
{
|
||||
|
|
@ -185,16 +180,13 @@ namespace Microsoft.AspNet.Diagnostics.Entity.Tests
|
|||
var optionsBuilder = new DbContextOptionsBuilder();
|
||||
optionsBuilder.UseSqlServer(database.ConnectionString);
|
||||
|
||||
TestServer server = TestServer.Create(app =>
|
||||
{
|
||||
app.UseServices(services =>
|
||||
TestServer server = TestServer.Create(
|
||||
app => app.UseMigrationsEndPoint(),
|
||||
services =>
|
||||
{
|
||||
services.AddEntityFramework().AddSqlServer();
|
||||
services.AddScoped<BloggingContextWithSnapshotThatThrows>();
|
||||
services.AddInstance<DbContextOptions>(optionsBuilder.Options);
|
||||
});
|
||||
|
||||
app.UseMigrationsEndPoint();
|
||||
services.AddInstance(optionsBuilder.Options);
|
||||
});
|
||||
|
||||
var formData = new FormUrlEncodedContent(new List<KeyValuePair<string, string>>
|
||||
|
|
|
|||
Loading…
Reference in New Issue