-
Notifications
You must be signed in to change notification settings - Fork 393
Implement IDbContextFactory to work around aspnet/EntityFramework#8164 #695
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I haven't tested this yet; I just wanted to get it out there for early review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, it doesn't seem crazy to me!
Only thing I don't know is whether there ought to be a comment on there. I'd add one only if it provided real value, as opposed to stating the obvious. |
using System.Threading.Tasks; | ||
using Microsoft.EntityFrameworkCore.Infrastructure; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Company.WebApplication1.Models; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will remove this using
.
public class ApplicationDbContextFactory : IDbContextFactory<ApplicationDbContext> | ||
{ | ||
public ApplicationDbContext Create(DbContextFactoryOptions options) | ||
=> Program.BuildWebHost(Array.Empty<string>()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move the =>
to the end of the declaring line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...and format it like this?
public ApplicationDbContext Create(DbContextFactoryOptions options) => Program
.BuildWebHost(Array.Empty<string>())
.Services
.GetRequiredService<ApplicationDbContext>();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(to match Program.BuildWebHost)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Egad, no, like this:
public ApplicationDbContext Create(DbContextFactoryOptions options) =>
Program.BuildWebHost(Array.Empty<string>()).Services.GetRequiredService<ApplicationDbContext>();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tsk tsk @danroth27 .
Updated |
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.EntityFrameworkCore.Infrastructure; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kind of an odd namespace for this apparently very useful type... but I guess that's not relevant to this PR...
@mlorbetske I wish you would have waited to merge this; dotnet/efcore#8314 will break this... Oh well, I'll send a new PR when it does. |
Sorry, got the go ahead from @ajcvickers & @DamianEdwards |
Ahem, I believe I asked you to check with @bricelam first 🤔 |
No biggie. Sent #705 |
@DamianEdwards I tried to but got redirected. Anyway, it seems to be working out. |
@Eilon @ajcvickers @DamianEdwards @divega @danroth27