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