Fluent Interface based View Engine

Topics: ASP.NET MVC, ASP.NET Single Page Application, General
Aug 23, 2014 at 9:18 AM
Is there any plan to expose views as pure cs files - may be designing something on the lines of Fluent Interfaces and internal Domain Specific Languages(may be using delegates and expression trees) to design a custom view engine e.g....

RenderButtons(buttonBuilder =>

buttonBuilder.AddButtonGroup().AddButton(b =>


b.OnClientClick("Some js based ajax call to server side")

So this above snippet will render the button on the page.One of the biggest advantage of this approach is we can cleanly unit test such code.Also such an approach can lead to designing views in a totally object oriented way.
Even better might be to have this style to render js templates (may be using some LINQ to JS library) and make it purely Single Page Application.
Please share your thought(s).

Thanks and Regards,
Aug 26, 2014 at 5:01 PM
Hey Sandip,

There are no plan to build something like this. As much as it is attractive from unit testability perspective, the written code becomes less and less HTML like, and the path we are pushing towards is to make the CSHTML look more like HTML with less code.

So in short we don't plan to build it.

A few comments
  1. I don't see a reason why you can't build a view engine like that. The fact that it's not attractive for our team to build, shouldn't discourage you from building it yourself if you think it has a real promise
  2. You can theoretically already unit test views today, by precompiling them, and then treating them as code. Our approach in vNext though is to allow rendering views in memory (as well as running the whole pipeline). We feel it's a much better (and easy) way to test out your app.
Aug 26, 2014 at 5:32 PM
Hi Yishai,
        Regarding the testing of precompiled views approach - I am not sure whether it's the right approach. Anyways, it's not only testability but with the Fluent Interface approach the views can be more maintainable by using object oriented principles like polymorphism,inheritance,composition (a sort of composition is though provided by Partial view currently) etc. Just wanted to know why Microsoft is not using this approach.That's all.

        And as far as building the custom view engine by myself is concerned, that's not a bad idea at all.
Thanks and Regards,