In my ASP.Net core application, Startup class has many things that is not needed to do migrations. According to This it seems I can create a DesignTimeFactory which will prepare the specified context and use it for migration purposes.
So I have created the simple class implementing IDesignTimeDbContextFactory which will simply accept a parameter, do some work with it and then return the MigrationContext for rest of the work within CreateDbContext(string[] args).
My problem is when I run Add-Migration commands from the console, it still executes StartUp class. . I thought with DesignTimeFactory, it shouldn't try to wire-up everything but simply use the context returned by the factory and use it for migration purposes.
Is there a way to avoid executing Startup class
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
Debugger.Launch();
webBuilder.UseStartup<Startup>();
});
and simply rely only on the DBContextFactory for migration? So Startup class is only executing at run time