Skip to content

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

Merged
merged 1 commit into from
Apr 28, 2017

Conversation

bricelam
Copy link
Contributor

@bricelam
Copy link
Contributor Author

I haven't tested this yet; I just wanted to get it out there for early review.

Copy link
Contributor

@Eilon Eilon left a 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!

@Eilon
Copy link
Contributor

Eilon commented Apr 27, 2017

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;
Copy link
Contributor Author

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>())
Copy link
Member

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

Copy link
Contributor Author

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>();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

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>();

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tsk tsk @danroth27 .

@bricelam
Copy link
Contributor Author

Updated

using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore.Infrastructure;
Copy link
Contributor

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 mlorbetske merged commit ebe35f8 into dotnet:rel/vs2017/post-rtw Apr 28, 2017
@bricelam bricelam deleted the dbfac branch April 28, 2017 03:04
@bricelam bricelam changed the title [WIP] Implement IDbContextFactory to work around aspnet/EntityFramework#8164 Implement IDbContextFactory to work around aspnet/EntityFramework#8164 Apr 28, 2017
@bricelam
Copy link
Contributor Author

@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.

@mlorbetske
Copy link
Contributor

Sorry, got the go ahead from @ajcvickers & @DamianEdwards

@DamianEdwards
Copy link
Member

Ahem, I believe I asked you to check with @bricelam first 🤔

@bricelam
Copy link
Contributor Author

No biggie. Sent #705

@mlorbetske
Copy link
Contributor

@DamianEdwards I tried to but got redirected. Anyway, it seems to be working out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants