Using Roslyn to compile controllers dynamically

With Roslyn CTP in the public domain, we can try to think about the cool things we can do with it, except for writing C # scripts.

Since asp.net mvc allows you to write custom controller factories, is it possible to write a factory that

  • Compiles controllers from the source file on the fly
  • Load the newly created type into the runtime (can this runtime descriptor?)
  • And discard the previous type if previous requests for the same controller have already been completed.

This will allow us to quickly prototype or change controllers, since you can simply write code and the controller will receive changes without having to recompile.

+5
source share
3 answers

I already implemented runtime controllers using the monos compiler as a service a few months ago.

Here you can find information and a link to the code on github: http://www.fusonic.net/en/blog/2011/04/01/scripting-asp-net-mvc-controllers-at-runtime/

Despite the fact that it looks very beautiful at first, it is not so useful in the real world due to several limitations.

First of all, Visual Studio is in the middle of you and your code, because it strictly blocks and prevents the source code from being changed during debugging. Thus, the only way to edit the source files is to run without a debugger.

, () . , ! , , .

, ...

, . .net, mvc- , (, ) .

java- : http://zeroturnaround.com/jrebel/

+5

MVC, , , . 2 Assembly.Load() . Roslyn , , .

Razor, .

+2

Take a look at ScriptCs . I believe that this will be possible sooner.

+1
source

All Articles