C#
Using AutoMapper
AutoMapper is an incredibly useful little tool – it uses conventions and a fluent API to configure and perform mappings between objects. This is especially useful when using view models – you often end up having to write boilerplate code simply to map between 2 types of objects.
My Favourite ReSharper Shortcuts
ReSharper is an awesome tool. If you’re using it you probably agree and if you aren’t you should be. The productivity gains are incredible. The moment you see another developer step effortlessly through the code you’ll agree. (If you have no idea what I’m talking about, it’s a Visual Studio plugin)
Convention-Based Templating in MVC 3
Today I’m going to explore the templating options available in MVC and try to create a framework to allow you to easily view multiple types of objects. I’ve never really used the templating options in MVC and I’ve been really impressed with the options available, although some of the lesser-used features are a little counter-intuitive.
Generating Test Data with AutoPoco
I often run into a scenario where I want to use test data – either for unit testing, integration testing, or simply to have some data for manually testing an application. Writing classes to generate this testing data can be rather time-consuming, so when someone on twitter mentioned AutoPoco I thought I would take a look.
Using and Testing HTML Helpers in MVC
If you’ve done any amount of development with MVC you are probably aware that it’s pretty easy to end up with a lot of clutter in your views. Today I’m going to illustrate how we can use custom helpers to neaten views and also show how we can write unit tests for those helpers.
ASP.NET MVC 3 Released
On Thursday ASP.NET MVC 3 was released. This was certainly not an unexpected event – the community previews have been available since around July last year, so many of the features have been discussed for quite a while.
Authentication with OpenId–Part 2
I my last post I created a very simple example of how to authenticate users with OpenId. In that example the user needed to enter the full URL to their OpenId provider. Today I’m going to modify that example to make the authentication process a little easier on the user. To give you an idea of what I’m going on about, take a look at the login form for StackOverflow.
Authentication with OpenId
A few weeks ago I blogged about the basics of storing web passwords. I mentioned that the best solution is to avoid storing web passwords and use OpenId to manage user authentication. I had the chance to play around with OpenId authentication and found the examples to be rather confusing, so today I’m going to write a very simple example of how to use an OpenId provider for user authentication.
Uploading a File with Asp.Net MVC
I’ve had to write the code for uploading a file to an MVC application quite a few times and every time I seem to struggle to find a decent example. So, future self, look no further – here is a straightforward example of how to upload a file with MVC.
Using Linq-to-Sql with Sqlite
I was recently working on a little example project (to illustrate using OpenID) and I realized that I needed a datastore. I didn’t really want to go through the hassle of creating a database in Sql Server, so I thought I would try and use Linq-to-Sql with Sqlite as the provider.
Google Interview Questions and Answers
I came across a very interesting article this morning regarding common Google Interview questions. While I don’t plan on working for Google (not saying I wouldn’t like to – I just don’t think I’ve got the kind of experience they’re after) I do enjoy challenging interview questions and I thought I would see how I fare with them.
Why is there no string.Format Extension Method?
Why is there no built-in extension method like this?
Using log4net for logging and monitoring
I was recently involved in a discussion around logging and the best way of implementing it in an application. I was once again reminded of how many applications choose to implement their own logging solutions rather than use a logging framework. It’s the most common occurrence of ‘not-invented-here’ syndrome that I’ve come across.
Sharpy performance testing
I recently introduced Sharpy – a view engine designed to allow developers and designers to work together. Today I’m going to take a look at the performance of the view engine when compared to the default view engine.
How to extend Sharpy
I recently introduced Sharpy – a view engine designed to allow developers and designers to work together. Today I’m going to show how you can extend Sharpy with your own functions and variable modifiers.
Master pages and partial views in Sharpy
I recently introduced Sharpy – a view engine designed to allow developers and designers to work together. Today I’m going to take a look at how master pages and partial views are used with this new view engine.
Expressions in Sharpy
I recently introduced Sharpy – a view engine designed to allow developers and designers to work together. Today I’m going to take a look at how expressions work in Sharpy.
Sharpy functions and modifiers
In my last post I introduced Sharpy – a view engine designed to allow developers and designers to work together. Today I’m going to list all the different functions and modifiers available and give a short description of how each works.
Introducing Sharpy
Several months ago I blogged about my search for a better view engine for ASP.NET MVC. I mentioned that the current selection of view engines don’t allow developers and designers to work together – none of the engines are restrictive enough in their syntax. Today I would like to present my solution to this problem.
Writing your own filters with LINQ
I recently read an article by Mark Needham on how we tend to duplicate LINQ filters in our code. He makes a good point – for example, you might see the following code in your application.
Implementing a custom LINQ provider
I recently read an interesting article that describes how the LINQ to SQL provider was implemented. The article gave a pretty good description of expression trees and how they relate to IQueryable and LINQ. I thought it might be interesting to try and implement my own LINQ provider to gain a better understanding of the LINQ technology.
Permission-based access in ASP.NET MVC
I recently read an interesting blog about implementing Role-based access in MVC using custom attributes. I have implemented a similar strategy for Permission-based access by using the session object.
How to use View Models
I’ve had quite a few discussions around view models and the different patterns around using them in MVC. A while back I read an interesting article by Steve Michelotti about the subject and I would like to expand on his arguments.
Use View Models instead of FormCollection
I have recently been spending quite a bit of time on StackOverflow and I noticed that quite a few of the MVC-related answers make use of the FormCollection class. If you’re unfamiliar with this class, here is an example of how it gets used:
Multithreading example in C#
There is a certain pattern I tend to lean on when performing multithreading operations. C# exposes some very useful functionality for dealing with multithreading problems – in this example I’m going to take a look at the ThreadPool class.
How to Debug Fitnesse Fixtures
I was recently discussing the advantages and disadvantages of Fitnesse with a colleague and he mentioned that one of the biggest drawbacks is that you can’t debug fixtures. I have managed to debug fixtures using the technique I’m going to outline here. I haven’t actually seen this technique mentioned anywhere so if you are aware of a better way of doing this please let me know using the comment section below.
Unit Testing – Why I didn’t like it at first
When introducing a fellow software developer to the concept of unit testing you will very rarely be met with optimism. In fact, most developers will quickly point out that writing both the code and the unit tests will effectively double the amount of work that needs to be done and therefore increase timelines. This is especially the case if you’re working in an environment where looming deadlines are the norm, rather than the exception.
So you want to learn MVC
I was recently requested to compile a list of resources on ASP.NET MVC to serve as introduction for newcomers to the MVC framework. I have recompiled the list here for future reference.
Retrieve Views and Submit Forms with Ajax, JQuery and MVC
In my previous post I was using Ajax to retrieve Json data and update the DOM using JavaScript. While this is pretty useful you will often find your application quickly becomes JavaScript-heavy and difficult to maintain. I’m going to illustrate using JQuery and the MVC Ajax libraries to simplify this process.
Ajax with JQuery and MVC
I recently had to explain to a colleague how to do Ajax with JQuery and ASP.NET MVC. I thought I might put my example here for future reference.
Configuring StructureMap using web.config
For the project I am currently working on I chose StructureMap as the dependency injection framework. The configuration for StructureMap is pretty easy – in my case it looked something like this.
Testing Asynchronous Code
Today I was trying to apply TDD to a piece of code that executes on a separate thread. The code in question basically creates a new thread and specifies a delegate to be executed on the background thread.
Authentication using LDAP
I recently had to rewrite a legacy library for authenticating users against Active Directory (AD). Having almost no previous knowledge of this type of authentication I turned to Google – assuming that samples and examples would be readily available.
Re-throwing Exceptions
This is one of my favourite interview questions – I’m often surprised by the number of candidates who get this wrong. Let’s see how you do.
Exceptions in a Distributed Environment
In my previous post I covered some of the basics around throwing and handling exceptions. In this post I’m going to take a look at what happens when an exception occurs during a remoting call.
Exceptions should be Exceptional
One of the common mistakes I see in beginner programmers is a lack of understanding around exceptions and how to handle them. Two years ago I started working on a project where every single server-side method (accessed via a remoting call) was surrounded by a try-catch block. When I discussed this with the project leader I was told that this was a done to “prevent the application from crashing when an exception occurs”. If you have seen code like this or you are simply unsure of when to handle exceptions, read on.
Evaluating an If Statement with Dynamic LINQ
In my previous post I described the basics for a new ASP.NET MVC View Engine that I’ve started working on, based on the popular Smarty PHP View Engine.
Building a Bug-tracking website with Windows Workflow Foundation – Part 3
In my previous post I designed the Bug-tracking workflow and created a custom activity for updating and persisting bugs. In this post I’m going to try and put it all together.
Building a Bug-tracking website with Windows Workflow Foundation – Part 2
In my previous post I created the outline for the website and introduced Unity as the dependency injection framework. In this post I’m going to design the actual workflow and show how to manage the persistence of the workflow as well as the domain objects.
Building a Bug-tracking website with Windows Workflow Foundation – Part 1
In the past week or so I have been trying to come to grips with Windows Workflow Foundation (WF). I have read numerous articles (the good ones are few and far between) and I think I’m finally getting the hang of it. To this end I’m going to create a Bug-tracking application as an example of creating a workflow-based website.
Running a Windows Service inside a Console Application
I pretty much always use the same snippet of code when working with a Windows Service. The main problem with a Windows Service is that it actually needs to be installed before you can run it. While this works fine when deploying an application, we need to be able to debug and run the service without installing it during development.
XPath with Xml Namespaces
I spent a very frustrating hour this afternoon trying to modify an XPath query to work with namespaces. I’m going to recreate this scenario and illustrate how we execute an XPath query against an Xml document without namespaces and then select the same data on an Xml Document with namespaces.
Common Error – The difference between explicit and safe casts
In this post I’m going to cover a mistake I’ve seen quite often and which can lead to those ugly ‘Object reference not set to an instance of an object’ exceptions.