Why use NancyFX?

When a new project comes along why should you automatically choose ASP.NET MVC? Yes, its Microsoft based so you may have more of your peers fluent already in that architecture but is there an alternative, a better alternative?

I believe so and its called NancyFX. Your first reaction, what is so special about Nancy? I also believe you’ll ask what is wrong with ASP.NET MVC but maybe you should look at it differently and ask what is right with Nancy?

What is Nancy?

Nancy is a lightweight framework for building websites / services without getting in your way. It’s heavily inspired by a Ruby project called Sinatra, which happens to identify itself as not being a framework, since it doesn’t include all the plumbing of things such as an ORM, lots of configuration, etc.

Does it implement MVC?

Nancy does not force you to adhere to the model-view-controller pattern, or any other pattern. It’s nothing more than a service endpoint responding to HTTP verbs. Making it ideal for building Websites, Web Services and APIs.

That doesn’t mean [...Read More...]

Easily publish a NuGet package

I recently published WebAPI.Testing on Nuget but found it a bit tricky to build a package ready for NuGet.

There is documentation about how to do it but I found it hard to follow so I thought I’d document how I finally got my package ready.

The easiest way I thought was to have something built into Visual Studio. I spoke to David Fowler and he told me you can edit your *.csproj file and add <BuildPackage>true</BuildPackage> to it.

When you build your project a *.nupkg is created ready for publishing with NuGet.

However if you have no AssemblyInfo.cs or *.nuspec file then that package won’t contain anything that useful about your package.

So the easiest thing to do is amend your AssemblyInfo.cs file with information about your package if you have an AssemblyInfo.cs file. If you don’t have one its not a problem.

Build your project, open the *.nupkg file that was created with Nuget Package Explorer and edit the metadata adding any extra information you want about your project.

Note: If your solution has NuGet restore turned on the [...Read More...]

ASP.NET Web API Testing

As the need arose to implement some kind of Web Service/HTTP API I thought I would evaluate NancyFX, ASP.NET Web API and ServiceStack.

Suffice to say all performed as expected and I was actually surprised to find that implementing ASP.NET Web API was easier than ServiceStack (I know that might be a bit of a statement to make to the ServiceStack followers, sorry). I found Nancy easiest to implement. The very simple API demos can be found on my Github page.

When it came to testing ASP.NET Web API I found it to be wanting slightly in comparison to Nancy. With WebAPI I could make direct calls to the controller methods to make sure data was returned correctly and I could mock a repository and test that the methods in the repository were being called but there was nothing I could see to test the HTTP response I would get.

I found that you could configure a lot of stuff to get a HttpResponseMessage back as shown below however in my opinion it wasn’t particularly easy [...Read More...]