Sunday, July 27, 2014

Using Nancy.Linker with Views


You have two options: 
  • The simplest is to use Nancy.Linker in your route handler to generate the links needed in the views, put them on the view model and pass the view model to the view as usual. 
  • The other is to pass IResourceLinker to the view and allow it to generate links as needed. For this to work you may need a little bit of web.config'ing to make Razor play nice. 
This post shows the former.

Nothing New

In the last post I introduced Nancy.Linker, showed how to use it to create links to named routes and place them on a model object returned by a Nancy route handler.

In essence; given this module:

This route handler will return a model with a link to the route in the module above in either XML, JSON or whatever other format you have support for in your application:

(how the format is chosen, and which are supported is another story)
Now, if you want to show that link in a view, you just have to add one line the to handler and - of course - view code. The handler becomes:

Assuming you are using Razor for your views the bar.cshtml view can simply be:

There you have it. Just use Nancy.Linker the same as when returning data, point to the view from the handler and use the generated link as any other string passed to a view.

This is the approach I'd recommend, but in the next post I will show how to use IResourceLinker in Razor code.

Saturday, July 5, 2014



Nancy.Linker is a small library for creating URIs for named routes in Nancy application that I released to NuGet the other day.

Purpose of Nancy.Linker

The problem Nancy.Linker solves is to allow your application code to create URIs pointing to endpoints in your Nancy application without hardcoding the URI. Instead you refer to the endpoint by its route name and provide values for whatever route parameters the route expects. The library then returns you a suitable System.Uri.


Let's consider a Nancy application with this module in it:

The module does nothing interesting, but bear with me. The thing to notice is that FooModule has all sorts of routes - a constant one, one with a simple parameter, one with a constraint on a parameter, one with a regex segment with a captured parameter, one with an optional parameter and one with a default value for an optional parameter. To read up on Nancy routing check out the docs.

Now let's assume another module needs to put links to endpoints in FooModule in its own response. It can do so by taking a dependency on IResoureLinker from Nancy.Linker and asking it to create the URIs:

which will produce a response containing a bunch of links back to the FooModule. For instance the call 

results in this string (assuming your application runs on

Getting Started

Just install Nancy.Linker from NuGet:

Nancy.Linker will take care of registering the IResourceLinker with your container, so modules can just go ahead a take a dependency on IResourceLinker.

Monday, June 9, 2014

Software Architecture Open Space 2014

The fourth annual Software Architecture Open Space Conference is taking shape. The date is set to October 2nd. The registration has opened. The venue is booked. The announcements and invitations are being sent out.

This years conference will follow the lead of last years conference and be a 1-day event in Copenhagen. The day will be all about in-depth discussions, sharing knowledge, learning together and making connections.The team behind the conference is also the same as the team last year: Jeppe Cramon, Jakob Bendsen, Nikola Schou and myself.
The one thing changed compared to last year is that the price has gone up. The event is still non-profit - just as it has always been - but it turned out we lost money last year, so this year the price has gone up some in the hope that we hit the zero.

As has been the case all the three previous years the day is centered around around a series of Open Space sessions. The Open Space format allows attendees to shape the conference to be about exactly the subjects they want: Anybody can propose a subject and anybody can contribute to the discussion around that subject. More than that actually. Not only can attendees participate. They are expected to do so. They are expected to share the knowledge they have, to actively take part in discussions, and to propose subjects. This format has worked very well the previous years. I have personally learned a whole lot as well as grown my network substantially at previous Software Architecture Open Space Conferences.

Hope to see you there! Now go register :)