設計階段服務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>()
}