So, I'm very enthusiastic about the new stuff that's coming out. I've already played around with the Razor view engine that was included in WebMatrix. And now I got the first preview of ASP.NET MVC 3. Yei!
So what's nice and new in this one?
Razor view engine
This one I've played with already a bit. The razor engine is more streamlined option for HTML templates with minimalistic syntax. It just feels like coding C# inside a HTML page. E.g.
WebFormsViewEngine:
<ul>
<% foreach (var invoice in Model.Invoices) { %>
<li><%:invoice.Balance%></li>
<% } %>
</ul>
And same in Razor view engine:
<ul>
@foreach (var invoice in Model.Invoices) {
<li>@invoice.Balance</li>
}
</ul>
Or example with if and foreach statements:
@if(Model.Invoices.Count == 0)
{
No invoices open!
}
else
<ul>
@foreach (var invoice in Model.Invoices) {
<li>@invoice.Balance</li>
}
</ul>
}
So the idea here is to make things a bit easier for everyone.
ViewData dictionary improvement
Another thing that makes your life just a bit easier is the support for the dynamic ViewData dictionary.
Previously we added stuff to the ViewData dictionary like this:
ViewData["Field"] = "Field content stuff";
Now we can use dynamic properties:
ViewData.Field = "Field content stuff";
A small change that makes me happy!
Dependency injection support
To ease up the unit testing and TDD, there's also new DI and IoC related features, that I haven't yet had time to play with. The following hooks are provided:
- Creating controller factories
- Creating controllers and setting dependencies
- Setting dependencies on view pages for both the Web Form view engine and the Razor view engine
- Setting dependencies on action filters
And of course tons of more stuff, check the release notes for more!
Hi,
ReplyDeleteActually, I do not like this approach, first of all if you try to think about some enterprise solutions it's really hard to control this mesh-up of HTML markup and code behind injections :) Sure it easier to develop, but in my opinion the code itself is not structured. Dynamic properties is not good if you need great performance or have same limitation regarding response time.
Hi Jevgenij.
ReplyDeleteThat's a good point about the HTML markup & code behind injections. I would also limit the amount of actual logic on the screen, but for e.g. creating tables and making simple decisions about should we show a link or not depending on view model can be done very clean in Razor. Any additional logic is naturally handled by the Controller and the models that it uses. So this is more a coding guideline than tech issue.
The dynamic properties are probably bad for performance (haven't measured this yet), but the advantage of intellisense and such are more important for out teams (actually working on quite large enterprise systems). The ease of development should be the first priority until we can point out that we have performance issues, so I would not do performance optimizations in advance. However it is good to acknowledge that these probably cause a performance hit in page loads.
Very Nice post!
ReplyDeleteAnother beautifull blog by you .Thaks for sharing
ReplyDelete