Update to reflect changes in EF service registration
This commit is contained in:
parent
e57e177224
commit
1e80a9a85c
|
|
@ -11,9 +11,8 @@ namespace DatabaseErrorPageSample
|
|||
{
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddEntityFramework()
|
||||
.AddSqlServer()
|
||||
.AddDbContext<MyContext>(options => options.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=DatabaseErrorPageSample;Trusted_Connection=True;"));
|
||||
services.AddDbContext<MyContext>(
|
||||
options => options.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=DatabaseErrorPageSample;Trusted_Connection=True;"));
|
||||
}
|
||||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
|
|
@ -42,6 +41,11 @@ namespace DatabaseErrorPageSample
|
|||
|
||||
public class MyContext : DbContext
|
||||
{
|
||||
public MyContext(DbContextOptions options)
|
||||
: base(options)
|
||||
{
|
||||
}
|
||||
|
||||
public DbSet<Blog> Blog { get; set; }
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -267,7 +267,7 @@ namespace Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.Tests
|
|||
})
|
||||
.ConfigureServices(services =>
|
||||
{
|
||||
services.AddEntityFramework().AddSqlServer();
|
||||
services.AddAddEntityFrameworkSqlServer();
|
||||
services.AddScoped<BloggingContextWithMigrations>();
|
||||
|
||||
var optionsBuilder = new DbContextOptionsBuilder();
|
||||
|
|
@ -333,7 +333,7 @@ namespace Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.Tests
|
|||
public virtual Task Invoke(HttpContext context)
|
||||
{
|
||||
var options = context.RequestServices.GetService<DbContextOptions>();
|
||||
var db = new BloggingContext(context.RequestServices, options);
|
||||
var db = new BloggingContext(options);
|
||||
db.Blogs.Add(new Blog());
|
||||
db.SaveChanges();
|
||||
throw new Exception("SaveChanges should have thrown");
|
||||
|
|
|
|||
|
|
@ -9,14 +9,10 @@ namespace Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.Tests
|
|||
{
|
||||
public class BloggingContext : DbContext
|
||||
{
|
||||
protected BloggingContext(DbContextOptions options)
|
||||
public BloggingContext(DbContextOptions options)
|
||||
: base(options)
|
||||
{ }
|
||||
|
||||
public BloggingContext(IServiceProvider provider, DbContextOptions options)
|
||||
: base(provider, options)
|
||||
{ }
|
||||
|
||||
public DbSet<Blog> Blogs { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -11,14 +11,10 @@ namespace Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.Tests
|
|||
{
|
||||
public class BloggingContextWithMigrations : BloggingContext
|
||||
{
|
||||
protected BloggingContextWithMigrations(DbContextOptions options)
|
||||
public BloggingContextWithMigrations(DbContextOptions options)
|
||||
: base(options)
|
||||
{ }
|
||||
|
||||
public BloggingContextWithMigrations(IServiceProvider provider, DbContextOptions options)
|
||||
: base(provider, options)
|
||||
{ }
|
||||
|
||||
// Providing a factory method so that the ctor is hidden from DI
|
||||
public static BloggingContextWithMigrations CreateWithoutExternalServiceProvider(DbContextOptions options)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ namespace Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.Tests
|
|||
{
|
||||
public class BloggingContextWithPendingModelChanges : BloggingContext
|
||||
{
|
||||
public BloggingContextWithPendingModelChanges(IServiceProvider provider, DbContextOptions options)
|
||||
: base(provider, options)
|
||||
public BloggingContextWithPendingModelChanges(DbContextOptions options)
|
||||
: base(options)
|
||||
{ }
|
||||
|
||||
[DbContext(typeof(BloggingContextWithPendingModelChanges))]
|
||||
|
|
|
|||
|
|
@ -11,8 +11,8 @@ namespace Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.Tests
|
|||
{
|
||||
public class BloggingContextWithSnapshotThatThrows : BloggingContext
|
||||
{
|
||||
public BloggingContextWithSnapshotThatThrows(IServiceProvider provider, DbContextOptions options)
|
||||
: base(provider, options)
|
||||
public BloggingContextWithSnapshotThatThrows(DbContextOptions options)
|
||||
: base(options)
|
||||
{ }
|
||||
|
||||
[DbContext(typeof(BloggingContextWithSnapshotThatThrows))]
|
||||
|
|
|
|||
Loading…
Reference in New Issue