設計階段服務Design-time services

工具所使用的某些服務只會在設計階段使用。Some services used by the tools are only used at design time. 這些服務是與 EF Core 的執行時間服務分開管理,以防止它們與您的應用程式一起部署。These services are managed separately from EF Core's runtime services to prevent them from being deployed with your app. 若要覆寫這些服務的其中之一 (例如,用來產生遷移檔) 的服務,請將的執行新增 IDesignTimeServices 至啟始專案。To override one of these services (for example the service to generate migration files), add an implementation of IDesignTimeServices to your startup project.

class MyDesignTimeServices : IDesignTimeServices
{
    public void ConfigureDesignTimeServices(IServiceCollection services)
        => services.AddSingleton<IMigrationsCodeGenerator, MyMigrationsCodeGenerator>();
}