MVC4 strongly-typed URL-routing… works

I published a post a few months ago about a project of mine, Dysphoria.Net.UrlRouting which aimed to bring strong typing to MVC4 ‘routes’.

If these words mean nothing to you, do not feel embarrassed (except if you’re a .NET web programmer, in which case, do feel embarrassed, and go read up on MVC post haste).

In the meantime I’ve excitingly a) used it for real in one production project two commercial, production projects, b) filled in some missing gaps, and c) improved the syntax a little. I’ve also d) published it as a NuGet package.

It’s reached the point where I wouldn’t work on an MVC project without it. I’d very much like if Microsoft took a wee look and added it, or added something similar, into MVC.

You can install it from NuGet. The package is called Dysphoria.Net.UrlRouting.

There’s now a webpage for it, which includes a bit of a tutorial.

You can grab the source off of github.

I should probably think of a catchy name for it. ‘STIR’? (Strongly Typed urI Routing?) ‘STRIM’? (Strongly Typed Routing urI Mechanism?)


The only real shortcoming I’m aware of at the moment is that it does not currently handle file uploads—but you can mix in some old-style MVC routing to deal with those.

Give it a try!

On Zombies (in World War Z)

[Movie poster: “World War Z”]I recently went to see World War Z. I’m not really a big zombie movie fan, but it was suitably exciting and nerve-wracking. I quite enjoyed it.

It is however, a little bit silly.

For example, the friend with whom I watched it, just didn’t buy John Gordon Sinclair as a US Navy SEAL Commander.

I didn’t quite buy how the zombies worked.

Now, if you don’t enjoy a bit of pedantic nit-picking or if you fear plot spoilers, please look away now.

SPOILERS FOLLOW

Continue reading

A letter to John Bercow

I wish I’d written this, (but I didn’t).

Some context: John Bercow, speaker of the House of Commons, was reported recently to be sympathetic to MP pay rises since MPs are paid an ‘ordinary’ amount of money. His annual salary is in excess of £142000. The average annual salary in the UK is a little under £27000.

A friend of mine wrote this email to John Bercow. I’ll post an update if there’s a response.

[Editor’s note: The original email underestimated Bercow’s salary by more than a factor of two. I’ve taken the liberty of correcting the numbers. Corrections in italics.]

To: BERCOWJ@parliament.uk

Dear Mr Bercow,

I find it impossible to resist emailing you having read various press reports today of your comments that MPs are not being sufficiently compensated for their work in Parliament.

I worked in a private sector firm for 15 years, reaching the level of Research & Development Manager. My line manager was the Operations Director for the firm and at points in the firm’s history this private, independent company had a turnover of ____ pounds.

In spite of this and in spite of the level of responsibility I had, my maximum salary was below £____ per year and I considered this to be a very generous amount, compared with the cost of living.

Unfortunately, thanks to the decision by the government to scrap Home Information Packs with immediate effect, I was made redundant. I accepted this with as much good grace as I could muster and immediately set out to find alternative means of earning a living in order to pay for food, pay for my house, pay for transport and cover my regular household bills.

I have never in my adult life claimed a single penny in state benefits. Everything I own and everything I use I have paid for through my own hard work and effort.

I have been self employed for three years now and in that time, my gross earnings have not exceeded £15,000. I am still, compared with many people in this country, not badly off. I have managed to pay my mortgage every month, covered my travel costs, fed and clothed myself and ensured my home remained wind and water tight. I am therefore better off than many people in this country at the moment. And I am still not hard done by.

You and your fellow MPs are meant to be employed by us, the British public, to represent our views and to work on our behalf to ensure that all the people in our country can enjoy a reasonable standard of living.

You are currently paid more than [4 times] the maximum wage I have ever earned in my life. You are already earning [more than 9] times my current annual salary. You also receive subsidies from the public purse for food, transport, housing and alcohol in the bars at the Houses of Parliament. These are subsidies which I and people like me have paid for and are STILL paying for through our taxes.

Thousands of people in this country are currently struggling to pay for basic necessities – food and shelter. You have both those things in abundance, at least partly paid for from the public purse. You are also in a position to take advantage of a better pension scheme than the vast majority of the people in the UK.

It is truly disgusting to me that you should consider yourself to be poorly recompensed. I am at a genuine loss to understand how you and your fellow MPs have managed to lose sight so completely of the experience of the majority of the people in this country. You are deeply out of touch and at the moment appear to be nothing more than a greedy man seeking to ensure your own position, with little or no thought for the people you asked to vote you as their representative.

I look forward to your response.

Sincerely

________

Strongly typed routing for Microsoft MVC4

(Right that title should have put off my casual audience who might have come here expecting a film review or a rant about religion.)

TR;DR: This post describes a new wee .NET library, to add static typing of URL routes in Microsoft MVC4. You can get it on github.

Basically it lets you:

  • Define URL routes as strongly-typed, first-class-objects
  • Bind routes to controller actions, fully statically-checked (so the compiler catches parameter mismatches/misspellings)
  • Generate links in your Razor code (a) succinctly and (b) fully statically type-checked.

Oh, and:

  • It all works at compile time—you don’t need to run a program to generate code or anything like that.

Continue reading