Skip to content
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

DbContext: Throw on AddDbContext with options lambda when context has no options ctor #6963

Closed
anpete opened this issue Nov 7, 2016 · 3 comments
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-enhancement
Milestone

Comments

@anpete
Copy link
Contributor

anpete commented Nov 7, 2016

Right now we seem to silently ignore the options lambda. This bug is about whether we should throw or warn.

@ajcvickers
Copy link
Member

We discussed this in the past and decided against it because we would have to replicate the logic in D.I. to determine if a constructor that takes the options would be used.

Even if we did that, we don't know that the context is not depending on something else that it gets the options from. Could be using service locator, or just have another service that depends on the options.

So to be sure we are not throwing for correct code we basically have to replicate a lot of the D,I, resolution (or somehow use D.I. to do it without actually resolving).

Or we can be okay with throwing when there is no actual issue. We decided against this when we discussed this before.

@anpete
Copy link
Contributor Author

anpete commented Nov 7, 2016

Makes sense. Maybe just something simple to catch a common case? I.e. when I hit this, both times my context had a single default ctor.

@ajcvickers
Copy link
Member

Yeah, if the context only has a parameterless constructor, then I can't think of a way that AddDbContext would work correctly. So might be okay to throw then.

However, I would still consider this a breaking change because people do a lot of stuff that they don't need to do when it comes to D.I., presumably because its hard to understand how it works. I have seen several situations where code is using AddDbContext and has a parameterless constructor and the application works just fine because the context options set in AddDbContext are not actually used at all.

@rowanmiller rowanmiller added this to the 1.2.0 milestone Nov 9, 2016
@rowanmiller rowanmiller changed the title Usability: AddDbContext with options lambda when context has no options ctor Usability: Throw on AddDbContext with options lambda when context has no options ctor Nov 9, 2016
ajcvickers added a commit that referenced this issue Jan 6, 2017
ajcvickers added a commit that referenced this issue Jan 6, 2017
ajcvickers added a commit that referenced this issue Jan 6, 2017
@ajcvickers ajcvickers added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Jan 6, 2017
@ajcvickers ajcvickers changed the title Usability: Throw on AddDbContext with options lambda when context has no options ctor Infrastructure: Throw on AddDbContext with options lambda when context has no options ctor May 9, 2017
@ajcvickers ajcvickers changed the title Infrastructure: Throw on AddDbContext with options lambda when context has no options ctor DbContext: Throw on AddDbContext with options lambda when context has no options ctor May 9, 2017
@ajcvickers ajcvickers modified the milestones: 2.0.0-preview1, 2.0.0 Oct 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-enhancement
Projects
None yet
Development

No branches or pull requests

3 participants