-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Design tools unable create DbContext with custom constructor using the services provider #17273
Design tools unable create DbContext with custom constructor using the services provider #17273
Conversation
This will only help when your DbContext isn't registered as a service (e.g. via AddDbContext) but has a constructor that takes services. Is that the scenario you're trying to enable? |
Yes, but not only that. I could also happen when my DbContext is registered as a service, but not via AddDbContext. For example a context with a single constructor that takes a connection string, registered as a service with a factory. It will be provided by the service provider but not discoverable, because the code that looks for it actually looks for DbContextOptions. |
@VladDragnea If you have a single constructor taking the connection string, then how will the context created using |
@ajcvickers the parameters, whichever they are, could be provided by the factory that is registered with the service provider. I've simulated this situation in the test case with a dummy connection string. |
Notes from triage: we will take this for the release aligned with .NET 5. (Note that no new features are allowed in 3.1 without director-level approval.) |
test/EFCore.Design.Tests/Design/Internal/DbContextOperationsCustomTest.cs
Outdated
Show resolved
Hide resolved
Made a few tweaks:
|
I've noticed that design time tools cannot instantiate a DbContext if the constructors doesn't follow a standard pattern (default constructor or with DbContextOptions derived parameter), even if the service provider is able to create the context.
The proposed change only replace:
with:
which I think it will fallback to the previous behavior if the service provider is unable to create the context.
A test for checking this scenario has been added.