Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature - Add support for Razor Class Library views #64

Open
jakenuts opened this issue Sep 30, 2022 · 5 comments
Open

Feature - Add support for Razor Class Library views #64

jakenuts opened this issue Sep 30, 2022 · 5 comments

Comments

@jakenuts
Copy link

First let me say, remarkable work. This is absolutely the closest I've found to the "holy grail" of hot-swappable MVC controllers & views. That it unpacks nuget packages and loads from there is 100% what I've dreamt of (short of a service that polls nuget feeds and downloads updates to the plugins folder).

I tried adding Prise to a solution with one main WebApp and several Razor Class Libraries with their own views and controllers and was able to load/update one of the RCL projects at runtime. The only flaw I ran into there was that the views (usually merged into the main project at build/start) weren't found so I could only return content results.

I may be pushing this farther than was intended, or farther than anyone has time to devote to making possible but if down the road you could reference & update RCL packages at runtime that would be a stunning achievement.

Thanks again!

James White

@jakenuts
Copy link
Author

jakenuts commented Oct 3, 2022

Here is an example project with two RCL's, one statically linked to the web project, one loaded dynamically. By default new RCL's use MVC Areas but I've tried it without areas and get the same result, can call a controller and get a content result but when it returns a view it can't be found.

https://github.com/jakenuts/PriseMvcExample

@merken
Copy link
Owner

merken commented Oct 4, 2022

Hi James,

Thanks for your interest, I take a look at your example and see what the culprit is.
I must say in advance that Razor Views are a bit edgy to work with, classic assemblies can be loaded without issue, but including assets (like views) may result in dropping the hotswapping support, as you might've seen in the source code:

/// - No DispatchProxy can be used, backwards compatability is compromised (DispatchProxy requires an interface as base class, not ControllerBase)

@jakenuts
Copy link
Author

jakenuts commented Oct 4, 2022

Thanks so much!

I was able to load and render Razor Pages if I add a CompiledRazorAssemblyPart after the PluginAssemblyPart. That seems to match how the statically linked RCL works. I added diagnostic views to the example home page so you can see the routes & parts before and after enabling a plugin.

I think the backwards compatability is less of an issue for me, through unloading the assemblies is definitely something I'd hope to preserve. I'll do some tests loading/unloading RCL's with their views to see what sort of objects stick around after they should be gone.

I think the only remaining piece I haven't gotten working is the view location, the controller can be called, razor pages rendered but when it looks for an MVC view it fails - probably a view location list that is created at startup and needs to be updated on load/unload.

@jakenuts
Copy link
Author

jakenuts commented Oct 6, 2022

Found it! Needed a CustomViewCompiler that could be reset (Hot Reload does this with the default one). I added a CompiledRazorAssemblyPart along with the PluginAssemblyPart and reset that cache and now it loads and displays the view. Will try to clean it up and see if I can add the new views rather than clearing the entire cache. Guess I'll also need to remove views that are being unloaded. So close..

@rfriend-zilo
Copy link

@jakenuts Any luck with this, im using it with blazor and im so close

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants