Using a Markdown ViewEngine with Nancy

Whilst using stackoverflow.com and Github gists I’ve become a frequent user of Markdown.

For those of you that don’t know what Markdown is, its essentially a shorter/cleaner syntax that can be parsed to produce HTML. Below are a few examples:

1
2
3
4
5
#Hello World!
##You’re awesome!
The quick brown fox jumped over the lazy coder
What the **hell** is this?
This is an [example link](http://example.com/)
1
2
3
4
5
<h1>Hello World!</h1>
<h2>You’re awesome!</h2>
<p>The quick brown fox jumped over the lazy coder</p>
What the <strong>hell</strong> is this?
This is an <a href="http://example.com/"> example link</a>

You can see more examples in the earlier link.

When you’re writing a blog post or a lengthy page in your web app with lots of HTML it maybe easier to [...Read More...]

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...]

.gitignore not working – fixed!

This happens to me too often and I always end up googling the answer so this post is probably more of a location I know I can come to find the answer, although by writing it down hopefully it may sink in that I should stop getting too excited on a new project.

New project scenario

You’re all very excited about your new project and you think its about time you committed this to source control. Obviously you’re using Git so you initialise a new repository and commit your files. You then setup a remote repository at Github and it asks you whether you want it create a .gitignore file – you do. So now you have a repository remotely and locally. Easiest thing to do is pull from the remote, setup your remote and push to it. The other scenario might be you’ve committed locally and then realise you need to add a .gitignore file which you do and then commit.

In both cases you will now see the files in your standardised [...Read More...]

Simple .Net Twitter,Google,Facebook Authentication

Logging into websites is no longer a matter of typing in your username and password and clicking the login button. If you already have an account with the main social networks you can log into a site using your credentials from that website saving you having to register your details *again*. This obviously makes things a bit easier as you don’t have to remember another password. (Although you should all be using a password manager such as LastPass.)

Current Social Login Providers

There are currently providers out there that allow you to use their services to integrate into your website to provide authentication via the social networks. The main two that I know of are Janrain and DotNetOpenAuth. I’ve not worked with DotNetOpenAuth but I have with Janrain when building DinnerParty.

The process was reasonably easy but not as simple as it could be.

.Net Simple Social Authentication

I was made aware of an OSS project by @philliphaydon whilst keeping up to speed with the latest NancyFX goings on in Jabbr that aims to provide [...Read More...]

Is OSS good for your career?

Got your attention? Good.

Let me start by pointing out there are many opinions about the answer to this question. You will have yours and I have mine, that’s called freedom of speech. I would like to hear your opinions so leave it in the comments.

Let me explain that I have had 4 jobs in the last 10-11 years. 3 of those were via recruitment agents. They check your skills, tick them off and pass you over to the employer if they match and hopefully you get an interview. That process has happened to me in each of those 3 times.

If you have read my previous blog posts you’ll know I have spent the last year reading a lot of other peoples code and learning all the best practices I can in a bid to become a better software developer as well as give back to the developer community where I can.

After spending a couple of months porting NerdDinner over to NancyFX I realised that I had not looked at ASP.Net [...Read More...]

NancyFX, RavenDB, NerdDinner and Me

As I said in my first post, NancyFX was my first port of call in my OSS adventure.  The reason I had come across it was by following @squidge and @cranialstrain on Twitter.  At the time they were talking about it quite a bit so I thought I’d take a look.  I was also keeping track of lots of people talking about RavenDB.

What is NancyFX?

From the official docs this explains NancyFX:

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.

This means that everything in Nancy is setup to have sensible defaults and conventions, instead of making you jump through hoops and go through configuration hell just to get up and running. With Nancy you can go from zero to website in a matter of minutes. Literally.

When ASP.Net MVC was first introduced to the world I was hooked on the framework, it seemed so easy and logical in comparison [...Read More...]

I’ve started blogging. Why?

So here I am, Jonathan Channon, blogger.  I never saw the point of blogging before so why now?

I have read and spoken to many people regarding blogging who were all in favour of it.  I would always argue that I don’t have time, I have nothing to blog about or I’m not that insane to start blogging about stuff I barely understand just so the masses can come and hurl abuse at my ignorance.  However I recently read an article by Ben Dornis titled “How I learned to stop worrying and love my community”.  He outlined all the reasons why a lot of people don’t publish their code and don’t publish their thoughts online. I thought he was being modest, the man is clearly talented at what he does so he didn’t have to worry however, someone like me still had these fears.

Over the last year I have made an effort to start contributing to open source software and to take the forked road away from Microsoft.  I found lots of things and this increased [...Read More...]