Open DamianEdwards opened 1 year ago
This might already be working for free due to the fact that the underlying types generated by the Razor compiler for each .cshtml file are attributed to reload the whole type on hot reload. It certainly seems to be working in the sample app in the repo. I have a hunch it might be only work when the project is configured to publish native AOT though as in that case slice creation goes through Activator.CreateInstance
which is likely honoring the replacement type metadata whereas when not using native AOT I generate a custom delegate that directly news up the slice type via its constructor. That will likely need to be updated to explicitly support Hot Reload.
I just tried with a simple sample - the slice isn't reloaded on dotnet watch
when modified.
https://github.com/dodyg/practical-aspnetcore/tree/net8.0/projects/razor-slices/hello-world
@dodyg yep, but it will be if you add <PublishAot>true</PublishAot>
in the project file. It's a side effect of the different code paths taken to create slices when the runtime doesn't support dynamic code compilation. I intend to update it to support hot reload in all cases though.
Do the needful.
Docs: https://learn.microsoft.com/dotnet/api/system.reflection.metadata.metadataupdatehandlerattribute