Reacting to ApplicationServices removal from HttpContext
This commit is contained in:
parent
6f5b20660e
commit
da7fe362c9
|
|
@ -22,7 +22,7 @@ namespace DatabaseErrorPageSample
|
|||
app.UseDatabaseErrorPage();
|
||||
app.Run(context =>
|
||||
{
|
||||
context.ApplicationServices.GetService<MyContext>().Blog.FirstOrDefault();
|
||||
context.RequestServices.GetService<MyContext>().Blog.FirstOrDefault();
|
||||
return Task.FromResult(0);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,9 +66,9 @@ namespace Microsoft.AspNet.Diagnostics.Views
|
|||
Request = Context.Request;
|
||||
Response = Context.Response;
|
||||
Output = new StreamWriter(Response.Body, Encoding.UTF8, 4096, leaveOpen: true);
|
||||
HtmlEncoder = context.ApplicationServices.GetHtmlEncoder();
|
||||
UrlEncoder = context.ApplicationServices.GetUrlEncoder();
|
||||
JavaScriptEncoder = context.ApplicationServices.GetJavaScriptEncoder();
|
||||
HtmlEncoder = context.RequestServices.GetHtmlEncoder();
|
||||
UrlEncoder = context.RequestServices.GetUrlEncoder();
|
||||
JavaScriptEncoder = context.RequestServices.GetJavaScriptEncoder();
|
||||
await ExecuteAsync();
|
||||
Output.Dispose();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ namespace Microsoft.AspNet.Diagnostics.Entity.Tests
|
|||
|
||||
public virtual Task Invoke(HttpContext context)
|
||||
{
|
||||
var db = context.ApplicationServices.GetService<BloggingContext>();
|
||||
var db = context.RequestServices.GetService<BloggingContext>();
|
||||
db.Database.EnsureCreated();
|
||||
db.Database.ExecuteSqlCommand("ALTER TABLE dbo.Blog DROP COLUMN Name");
|
||||
|
||||
|
|
@ -123,7 +123,7 @@ namespace Microsoft.AspNet.Diagnostics.Entity.Tests
|
|||
|
||||
public virtual Task Invoke(HttpContext context)
|
||||
{
|
||||
var db = context.ApplicationServices.GetService<BloggingContext>();
|
||||
var db = context.RequestServices.GetService<BloggingContext>();
|
||||
db.Blogs.Add(new Blog());
|
||||
db.SaveChanges();
|
||||
throw new Exception("SaveChanges should have thrown");
|
||||
|
|
@ -155,7 +155,7 @@ namespace Microsoft.AspNet.Diagnostics.Entity.Tests
|
|||
|
||||
public virtual Task Invoke(HttpContext context)
|
||||
{
|
||||
var db = context.ApplicationServices.GetService<BloggingContextWithMigrations>();
|
||||
var db = context.RequestServices.GetService<BloggingContextWithMigrations>();
|
||||
db.Blogs.Add(new Blog());
|
||||
db.SaveChanges();
|
||||
throw new Exception("SaveChanges should have thrown");
|
||||
|
|
@ -184,7 +184,7 @@ namespace Microsoft.AspNet.Diagnostics.Entity.Tests
|
|||
|
||||
public virtual Task Invoke(HttpContext context)
|
||||
{
|
||||
var db = context.ApplicationServices.GetService<BloggingContextWithPendingModelChanges>();
|
||||
var db = context.RequestServices.GetService<BloggingContextWithPendingModelChanges>();
|
||||
db.Database.Migrate();
|
||||
|
||||
db.Blogs.Add(new Blog());
|
||||
|
|
@ -237,7 +237,7 @@ namespace Microsoft.AspNet.Diagnostics.Entity.Tests
|
|||
|
||||
public virtual async Task Invoke(HttpContext context)
|
||||
{
|
||||
var db = context.ApplicationServices.GetService<BloggingContextWithMigrations>();
|
||||
var db = context.RequestServices.GetService<BloggingContextWithMigrations>();
|
||||
db.Blogs.Add(new Blog());
|
||||
db.SaveChanges();
|
||||
await context.Response.WriteAsync("Saved a Blog");
|
||||
|
|
@ -325,8 +325,8 @@ namespace Microsoft.AspNet.Diagnostics.Entity.Tests
|
|||
|
||||
public virtual Task Invoke(HttpContext context)
|
||||
{
|
||||
var options = context.ApplicationServices.GetService<DbContextOptions>();
|
||||
var db = new BloggingContext(context.ApplicationServices, options);
|
||||
var options = context.RequestServices.GetService<DbContextOptions>();
|
||||
var db = new BloggingContext(context.RequestServices, options);
|
||||
db.Blogs.Add(new Blog());
|
||||
db.SaveChanges();
|
||||
throw new Exception("SaveChanges should have thrown");
|
||||
|
|
@ -358,7 +358,7 @@ namespace Microsoft.AspNet.Diagnostics.Entity.Tests
|
|||
|
||||
public virtual Task Invoke(HttpContext context)
|
||||
{
|
||||
var db = context.ApplicationServices.GetService<BloggingContextWithSnapshotThatThrows>();
|
||||
var db = context.RequestServices.GetService<BloggingContextWithSnapshotThatThrows>();
|
||||
db.Blogs.Add(new Blog());
|
||||
db.SaveChanges();
|
||||
throw new Exception("SaveChanges should have thrown");
|
||||
|
|
@ -385,7 +385,7 @@ namespace Microsoft.AspNet.Diagnostics.Entity.Tests
|
|||
|
||||
public virtual Task Invoke(HttpContext context)
|
||||
{
|
||||
var db = context.ApplicationServices.GetService<BloggingContext>();
|
||||
var db = context.RequestServices.GetService<BloggingContext>();
|
||||
db.Blogs.Add(new Blog());
|
||||
try
|
||||
{
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ namespace Microsoft.AspNet.Diagnostics.Tests
|
|||
.SetupGet(c => c.Response.Body)
|
||||
.Returns(responseStream);
|
||||
contextMock
|
||||
.SetupGet(c => c.ApplicationServices)
|
||||
.SetupGet(c => c.RequestServices)
|
||||
.Returns(() => null);
|
||||
|
||||
// Act
|
||||
|
|
|
|||
|
|
@ -144,7 +144,7 @@ namespace Microsoft.AspNet.Diagnostics.Tests
|
|||
.SetupGet(c => c.Response.Body)
|
||||
.Returns(responseStream);
|
||||
contextMock
|
||||
.SetupGet(c => c.ApplicationServices)
|
||||
.SetupGet(c => c.RequestServices)
|
||||
.Returns(() => null);
|
||||
|
||||
// Act
|
||||
|
|
@ -203,7 +203,7 @@ namespace Microsoft.AspNet.Diagnostics.Tests
|
|||
.SetupGet(c => c.Response.Body)
|
||||
.Returns(responseStream);
|
||||
contextMock
|
||||
.SetupGet(c => c.ApplicationServices)
|
||||
.SetupGet(c => c.RequestServices)
|
||||
.Returns(new ServiceCollection()
|
||||
.AddSingleton<HtmlEncoder>(new HtmlTestEncoder())
|
||||
.BuildServiceProvider());
|
||||
|
|
|
|||
Loading…
Reference in New Issue