Today my toolset of choice for a quick learning session is Nancy.
Reading straight from the box “Nancy is a lightweight, low-ceremony, framework for building HTTP based services on .Net and Mono. The goal of the framework is to stay out of the way as much as possible and provide a super-duper-happy-path to all interactions”.
Got that? Think of it as a replacement for WebForms or ASP.NET MVC.
Nancy is available in NuGet or on GitHub if you want the source and docs. The docs are well worth a look over, and you are bound to need the aid of a sample project as you find your feet. Having said that, it is really quite simple so you should be up to speed in no time.
These posts are not supposed to be walkthroughs, so I won’t go into detail getting you started other than to say that you start with an “ASP.NET Empty Web Application”, add the Nancy bits from NuGet (grab the AspNet hosting package and Razor view engine as well for simplicity), create a subclass of NancyModule and away you go.
You can see my demo live at http://nancydemo-1.apphb.com/ and grab the source from https://github.com/csainty/NancyDemo.
Where I think Nancy really shines is writing an API / REST service. As the box says, there is so little ceremony that you never feel like you are fighting the framework to perform simple tasks. Even in ASP.NET MVC I find this sort of thing a little clunky feeling. As for WebForms, I did my best to avoid them altogether.
The interesting code in this project mainly lies in the Modules.
First we have a PageModule, which is serving requests for regular pages.
It really is as simple as that to catch requests to “/” and serve up a View in response.
Second we have the ApiModule, which is handling the API requests being made by AJAX.
Again, you can see that is very simple.
To demonstrate Dependency Injection using Ninject, there is a simple data store interface and an in memory implementation.
Here we are subclassing the Ninject bootstrapper, there are other implementations, and adding in the bindings we need.
Of course I have barely scratched the surface here on a very intriguing project. I am hoping to put it to real use in something very soon.