Currently, services are discovered before creating any IDesignTimeDbContextFactory instance. This ensures that we get the correct DbContext type when multiple may be registered, possibly from different assemblies. However, this is problematic when the context factory is being used as an escape hatch for something that is failing in service discovery--for example, see #27306 and comments on #9076.
To fix this, we could do an initial search using some heuristics. For example, we could search for IDesignTimeDbContextFactory implementations and if there is only one found for one context type which matches the context type specified on the command line, then use it with no further discovery.
Currently, services are discovered before creating any IDesignTimeDbContextFactory instance. This ensures that we get the correct DbContext type when multiple may be registered, possibly from different assemblies. However, this is problematic when the context factory is being used as an escape hatch for something that is failing in service discovery--for example, see #27306 and comments on #9076.
To fix this, we could do an initial search using some heuristics. For example, we could search for
IDesignTimeDbContextFactoryimplementations and if there is only one found for one context type which matches the context type specified on the command line, then use it with no further discovery.