I have an ASP.NET Core 8 project with Entity Framework Core. The connection string is taken from web.config
in the root folder. While debugging in Visual Studio 2022, I enabled Hot Reload. I have figured out way to refresh DbContext
when hot reload is triggered.
I use this code:
[assembly: System.Reflection.Metadata.MetadataUpdateHandler(typeof(HotReloadManager))]
namespace xxx
{
internal static class HotReloadManager
{
public static void ClearCache(Type[]? types)
{
// Clear any caches if needed
}
public static void UpdateApplication(Type[]? types)
{
using var context = new xxxDbContext();
context.Database.EnsureCreated();
}
}
}
It works fine while hot reloading. DbContext
is refreshed. Then the next thing is when I edit connection string in web.config
, I find that this will not trigger hot reload. How can I achieve that?
8