A while back I had to use JQuery mobile for a project. The project needed to have 2 themes on an application and the configuration would need to tell the application what theme to load. With JQuery Mobile, the theme string could only be a single letter. I like keeping to decent and meaningful naming conventions, so I created a configuration setting as follows:
<add key="Theme" value="Plain" />
I could see easily that the theme for this build of the application is the Plain theme. How could I relate that back to a JQuery theme? Plain would not be acceptable with JQuery Mobile. Therefore I had to do something different. I was able to use an attribute on the Theme Enum:
I then overrode the WebViewPage to include logic to get the Theme as follows:
As you can see, I have an extension method in place to get the string value of the enum. This then taps back into my String attribute as follows:
This then allowed me to turn a simple readable string from a web.config, into something that JQuery Mobile could understand and parse as normal
Today, 06 June 2011, was the second Guathon London run the the DDD guys. On today's session listing was ASP.NET MVC 3, Knockout.Js, C#5 and asynchronous Web applications and cloud computing with Windows Azure.
First on the bill was Scott Guthrie to do a 2 hour round robin talk on building an app using ASP.NET MVC 3, EF Code First, NuGet, and IIS. This was a whirlwind talk as usual as there was so much to cover. It wasn’t anything new to me as I use these technologies on a day-to-day basis at work. I also used them to create GiveCamp UK.
- I have questions about its accessibility
- i have questions about how you would actually write maintainable tests for this framework
This is not to say I hate the framework. This just means that initially I must say that my barriers went up as it made me feel outside my comfort zone. I will have a look into it a bit more before I make my mind up on whether I’d use it or not. Right now I’m unconvinced.
After the lunch break, Steve Sanderson was back on stage to take about the use of the new C#5 features (async and await) in order to create asynchronous web applications in ASP.NET vNext. This mean that Steve showed off some of the new MVC4 features and used a NuGet package, called SignalR. The talk demonstrated how the syntax in MVC4 will be a lot cleaner and readable that MVC3 where we use the Async and Completed methods in order to carry out async tasks. It seems to me that async Task<ActionResult> will be of great use to me in the future.
Steve then talked about taking the real time web beyond ajax. The talk spoke about polling, long polling and web sockets. This was my first sight of web sockets and they look very useful although it was pointed out that it was not ready for production applications yet due to non finalised specification. Steve took the long polling example and showed how we can use async in a chat room and voting application. The demos looked simple and easy to read and the MVC4 code looked good
The last talk of the day was back to the ‘Gu’ himself. This time he was talking on cloud computing. Scott was quick to point out that this was his first time talking about Azure since he took his new job and that even though he had taken that job, he was still very much a part of the ASP.NET team.
This talk was split into numerous parts. The first few pointing out what Azure is, what it’s infrastructure is made up of and how to take a simple application, make it ‘cloud ready’ and then deploy to the Azure platform. The next part focused on fault tolerance and latency and this was useful to see. My experience of developers new to ‘the cloud’ is that they take a web app, deploy to the cloud and this it’s automatically scalable. This is of course not strictly true.
Scott then talked about using servicebus as a message queuing service to help create a more load levelled application. The scalability of applications created in this way, means that instances of an app can be increased at peak times through code, Azure management API or via service configuration file changes. The talk was then refocused on how the cloud has made data storage cheaper and more efficient as the cost has dropped considerably over the years. Storing terabytes of data is now not an issue. It was pointed out that Azure replicated data storage in 3 locations for availability and consistency.
Mentions of Sql Azure and Table storage were made and Scott explained the benefits they bring like auto backups, auto sharding etc. The final demo was federated security using WIF. This allows the use of partner API’s (facebook Id, Google Id, Live id and active directory) in order for users to sign into your website. This was a new thing for me and I am annoyed I didn’t know of it before as it would have made the creation of GiveCamp UK easier.
Overall, I enjoyed the event. Thanks to Phil Winstanley, Dave Sussman and the DDD team for organising the event at short notice. Also thanks to Scott and Steve for coming along to speak. It is great to listen to presenters who really do know what they are talking about. It makes me jealous of all the folks heading to NDC2011 to hear more of these kind of talks.
Today I witnessed a real show of power of the Razor View engine included with ASP.NET MVC3.
Traditionally in sites scripts and styles are all thrown in the masterpage (webforms) or sitelayout (razor). This can lead to pages taking potentially longer to load when they don't even need some of the scripts or styles. As Google announced that page load times were going to be part of Google rankings, it’s not ideal for this to happen.
This has been made easier as Razor has introduced the ability to define sections in our pages.
The code here checks to see if a section of the required name is defined and if so it will render it. This can be used to encapsulate scripts and styles as shown. Here we load the site.css as this is required for the entire site and we load the jQuery main library as this will also be required all over the site. We can then define Sections in our sitelayout and render specific scripts and styles required for a specific View
This image shows that by then using the appropriate section named from the sitelayout page that we can play only the scripts required for that view in that section. This will help to make the views as lightweight as possible when they are being rendered.
This is a demonstration of the power of the Razor view engine. It just makes it very easy to achieve. I’m loving using MVC3 and feel as though things are not quite “right” when I go back to working on webforms projects! :(
Hope it helps!
I am working on a new application at work that’s an MVC3 app that talks to a WCF Service. I use a number of 3rd party libraries:
- Ninject WCF
- Ninject MVC
- Ninject Logging Extensions
- Fluent Validation
So when i had to upgrade to MVC3 RTM I had to see what happened to these 3rd party systems – FYI I had a bit of a nightmare! It happened in the following order:
MVCContrib – I was a bit ahead of the game here and checked out latest branch and build from source – SORTED!
Fluent Validation – Luckily Jeremy Skinner tweeted that Fluent Validation for MVC3 was available – SORTED!
Ninject – I had to download this from github, update the solution to run as .Net 4.0 and add the new MVC3 System.Web.MVC dll to it and build from source – SORTED!
Now things started getting a bit weird!
Ninject MVC – this required the solution to be downloaded from github, upgraded to .net 4, the MVC3 System.Web.MVC dll and the previously compiled ninject dll
Ninject WCF - this required the solution to be downloaded from github, upgraded to .net 4 and the previously compiled ninject dll
Ninject Logging - this required the solution to be downloaded from github, upgraded to .net 4 and the previously compiled ninject dll
This was a horrendous task! I’m not sure I'd want to upgrade something so complex again but its all for a good cause as I can now use the Razor view engine :)
EDIT: Those awesome codebetter guys have created these upgrades of Ninject on their build server so you don't have to - http://teamcity.codebetter.com/
Word of warning: DON’T TRY THIS AT HOME!