Chris Sainty

A technical blog covering full-stack web development.

twitter | github | stackoverflow

Posts about - dotnet

, ,

Veil - Getting Started Standalone

In addition to integrating with Nancy, Veil can be used by itself in any project for advanced text templating.

To get started you simply need to install one of the Veil parsers for the syntax you prefer.

Read More

, , ,

Veil - Getting Started With Nancy

Nancy is a great framework for building websites and it has been an important goal for Veil to integrate seamlessly in to your Nancy projects.

To get started you will first need to install Veil's view engine wrapper for Nancy.

Install-Package Nancy.ViewEngines.Veil

Read More

, ,

Why Veil?

Recently I've been working away on a new project Veil.

Veil is my entry in to the .NET "view engine" / templates space.
There isn't exactly an urgent need for a new solution to this problem and most are perfectly happy with Razor. So why did I go ahead and spend my time writing one?

Read More

, , ,

Quick Tip - Windows Azure Mobile Services and Xamarin

Having trouble adding Azure Mobile Services to your Xamarin project?
Seeing the following compiler error?

Warning: The referenced library 'Microsoft.WindowsAzure.Mobile.Ext.dll' is not used from any code, skipping extraction of content resources. (FriendsFromWorkMobile)

How about this exception?

A Windows Azure Mobile Services assembly for the current platform was not found. Ensure that the current project references both Microsoft.WindowsAzure.Mobile and the following platform-specific assembly: Microsoft.WindowsAzure.Mobile.Ext.

Don't despair, you missed one simple line when skimming the Getting Started tutorials.

CurrentPlatform.Init();

Rejoice!

, , ,

OWIN - Am I missing something?

Time for some opinion. In the last few days I have taken my first serious look at OWIN and I can't help but feel the whole idea is being polluted by the Katana project.

Read More

, ,

ScriptCS for quick Mutex tests

I've been looking out for ways to use ScriptCS in my day-to-day work lately. Each time I do, I am impressed by how much time it saves me.

So today I found myself needing to write some code with a named Mutex in C#. ScriptCS to the rescue!

Read More

,

Wrapping synchronous code in a Task returning method

Imagine you have an interface.

public interface IAsyncCommand
{
  Task ExecuteAsync();
}

Read More

,

Interfaces again

In my recent post about interfaces I showed one approach to breaking up and consuming your interfaces that I am finding interesting at the moment. The idea was born out placing restrictions on myself and trying to be explicit about my dependencies. I wanted to structure the code in a way where I couldn’t get lazy and just start firing off database code from anywhere in the codebase.

Read More

, ,

Fun with Explicitly Implemented Interfaces

I’ve picked up a new coding technique recently.
I’ve always been a bit uncomfortable with the 1:1 relationship between class and interface. I’ve also been uncomfortable with large service classes like a repository.

When you take a dependency on a large service interface you are hiding all the details about what you are actually dependent on, which can cause you problems down the line with your tests and refactorings.
Repositories in particular quickly escalate to large numbers of functions. If I am working on tests for a piece of code that takes a dependency on that repository I have no option other than to read the code to see what methods it is calling. Tedious.

Read More

, , ,

Node.js Background Workers on AppHarbor

Today AppHarbor announced beta support for Background Workers, I have been eagerly awaiting this announcement as it is something I need all the time when hosting sites.

Read More

, , , , , , , ,

Getting deeper into Open Source

It’s about 8 months since my first contribution to an open source project. It was followed up minutes later by one to reverse all the accidental formatting changes I made. Damn you Visual Studio!

Read More

, , , , , ,

Tutorial: Nancy + MongoDb + AppHarbor

Time for a quick tutorial on how to get a site up and running on AppHarbor using Nancy and MongoDb.

Read More

, , , , , ,

Learn Something New: Nancy

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.

Read More

, , , ,

Using ServiceStack.Text for JSON processing on Windows Phone 7

I recently decided to switch gReadie away from JSON.Net to ServiceStack.Text for it’s heavy JSON processing of the Google Reader API.

While there was no WP7 dll available in the NuGet package the source was all on GitHub, so using my recently learned Git skills, I forked the project and added my own project file targeted at WP7.

Read More

, ,

WP7.5 Mango–Isolated Storage Explorer

One of the most useful new tools with the latest Windows Phone SDK is the Isolated Storage Explorer.

It is a command line tool used for downloading and uploading the contents of an application’s Isolated Storage folders to either the Emulator or a Device.

There are two times when this is invaluable.

Read More

, , , ,

Two lessons from a frustrating Mango submission

I thought I would share two quick lessons today. Learnt while submitting the latest gReadie update to the marketplace.

Read More

, , , , ,

Wp7.5 Mango–Background Agents

Late last year when I implemented the unread count Live Tile in gReadie I found myself stunned at just how complicated it was. It seemed to me that it would make a lot more sense if I could just whack a [LiveTileUpdater] attribute on a static method in a class and the phone would run that method occasionally.

I was therefore delighted when details about Mango were released as this is basically what Microsoft implemented.

Read More

, , , , ,

WP7.5 Mango–Compiled Queries

Over the last few weeks I have been doing a complete rewrite of gReadie, my Google Reader client for Windows Phone 7.

The original codebase for gReadie was really quite cluttered, and I wasn’t going to be able to take advantage of the new features Mango enables without pulling it all out and starting again.

With most of the rewrite behind me now, It is time to start putting together a few blog posts discussing the new features I am using and lessons learnt along the way.

Read More

, , , ,

ASP.NET MVC3 + Ninject + Moq + Unit Testing

I answered a question on StackOverflow yesterday which I am pretty happy with, so I thought I would share the link on here.

http://stackoverflow.com/questions/6646244/mvc-3-how-to-learn-how-to-test-with-nunit-ninject-and-moq/6646591#6646591

The question asks for general advice on how to write and test an ASP.NET MVC 3 website that correctly uses Inversion-of-Control, Unit Testing and Mocking.

, , , , ,

A RavenDb profiling plugin for Glimpse

Today my post is to announce the release of a small plugin I have been working on over the last few days. It is a plugin for the Glimpse client side debug tool that integrates profiling information from RavenDb.

Read More

, , , ,

RavenDB Profiling with ASP.NET MVC

I have recently been using (and occasionally contributing to) RavenDB, a NoSQL (or Document) database for .NET written by Oren Eini, aka ayende.

My biggest contribution yet has been to help with the basic "glue" to drive the new UI for profiling RavenDB requests in an ASP.NET MVC web application.

Read More

, , , ,

WP7 - Authenticated Push Notifications

This post is going to offer a few tips about changing your Windows Phone 7 push notification service from unauthenticated to authenticated.

Specifically it will focus on the challenges I ran into hosting a WCF service, in IIS7 on a cheap shared hosting account.

Read More

, , ,

Windows Phone 7–Asynchronous Programming

I am going to start putting together some posts on my experience writing our first Windows Phone 7 application, gReadie.

Read More

, , ,

WPF: MultiBinding and IMultiValueConverter

I came across the MultiBinding markup extension and IMultiValueConveter today when looking for a solution to a problem. Not sure how I missed it previously. If you didn’t I probably don’t have a lot to add, but if you have not heard of them then read on.

Read More

,

Repository vs Query

I’ve read a lot of blog posts about the Repository pattern. Whenever I have looked at implementing it, I always come away underwhelmed. It’s one of those things that displays nicely in a small example but in practice you end up with a huge number of methods that each query the data in a similar but slightly different manner, and for me it’s fault is with querying.

Read More

, ,

WPF + Strong Typing

I have been working with WPF recently, and one of the things that annoys me most is the usage of strings to reference object properties. This mainly affects Bindings, but also pops up in other places such as the IDataErrorInfo interface.

Read More

, , ,

Moq: Mocking GetEnumerator()

In my last post I made mention that it was easier not to use the Enumerators on HTTP context objects when you want to unit test with mocking. This is due to some annoyances with casting (as they predate generics) that can be avoided with simple for() loops instead of foreach().

Today however, I am going to look at mocking GetEnumerator() in a more general sense should you ever need it.

Read More

, , , , ,

ASP.NET MVC: Unit Test File Upload with Moq

Microsoft released the ASP.NET MVC Release Candidate yesterday (Link). One thing that pricked my ears in the release notes was a change to the ControllerContext that would apparently make it easier to use a mocking tool to unit test actions that needed to interact with the standard HTTP objects.

Read More

,

The 'yield' Keyword

I have recently been brushing up on my Computer Science training, implementing various data structures and algorithms, O(log n) searching, that sort of thing. While traversing a binary tree returning it's contents in sorted order, I really wanted to put the yield keyword to use.

Read More

, ,

LINQ to SQL: Generic Primary Key function

An issue I have seen blogged about a number of times with LINQ-to-SQL is that by strong typing queries, you lose the ability to create generic functions for processes such as fetching records by their Primary Key.

Read More

, ,

ASP.NET MVC Application Layout

I am slowly evolving my general layout for ASP.NET MVC applications as I come more and more to grips with the framework and they ways I am most comfortable using it.

This post is going to be a bit of an overview of how I am laying out my project at the moment in case it is of use to anyone.

Read More

, , ,

RenderComponent() or RenderUserControl()

One thing I have always needed to do in my web sites is break sections of pages out into a re-usable component. If you look at http://www.ht.com.au the "Featured Product Of The Month" panel displays three product "patches". This exact same patch is used on the Cart page and the Hub pages. It is a nice little class/template that you pass a product number to and it spits back the HTML for that patch, which you write out like any other expression in your template.

Read More

, , ,

ASP.NET MVC - Testing

I have been further exploring the concepts of Test Driven Development of late, in particular around the ASP.NET MVC framework.

One concept that is very new to me is mocking. I have been using Rhino Mocks. This is not going to be a post about mocking, I am far much of a novice to offer any useful advice on this front just yet. However, it is pretty cool stuff and worth a read.

Read More

,

LINQ to SQL: SQLMetal.exe

I have recently switched over to using SQLMetal to generate my LINQ-to-SQL DBML and Context class. There are two things I like about it, one is that it is far faster. I just click a script on my desktop rather than open up the designer and recreate each table that has changed. I also prefer some of its naming conventions, it deals with multiple relationships to a  single table better.

Consider the case where you have an Orders table and it has two fields holding Address keys (ie ShippingAddressID and InvoiceAddressID). The LINQ-to-SQL generator in Visual Studio will create 4 properties ShippingAddressIDInvoiceAddressID, Address, Address1. The last two being references to the Address entities. The problem being you cant work out which is which. SQLMetal will detect this and one of them will be named ShippingAddress, sadly the other will still be simply Address. There is hope though.

Read More

, ,

LINQ to SQL: Be careful of CreateDatabase()

I have recently started work on what will become our first production application using LINQ-to-SQL and had hoped to use the CreateDatabase() function that is found on the generated DataContext to simplify the process of setting up the database on the client machine.
Ideally I wanted a nice simple piece of code like this

Read More

,

Extension Methods

In this article I am going to look at Extension Methods. Although this is not a specific to LINQ post, Extension Methods are the compiler concept that LINQ was built on.

The basic premise is to allow the developer to add functionality to any class they like without the need to subclass it or wrap it in a wrapper class. This is a great new technique because it allows you to continue using a class like String or DateTime and not need to remember to use MyString and MyDateTime or fall back on static helper classes.

Read More

,

LINQ to SQL: Extending Data Classes

Next we are going to look at how you can use partial classes and partial methods to add functionality to your generated LINQ-to-SQL classes. One of the nice things about partial classes and the new partial methods is that you can extend the generated classes into a separate file that is not destroyed when you update the underlying data model. See my complaint here about other ways of changing the classes that does not have this benefit.
First things first is to create a new C# class file, I have called it AdventureWorks_Extra.cs to sort it below the AdventureWorks.dbml

Read More

,

LINQ to SQL: GroupBy()

One aspect of LINQ I have not covered yet is the equivalent of a GROUP BY in SQL. The GroupBy() function (which of course can be used from a LINQ expression as well as from the method syntax and I will show both) provides this functionality. One of the interesting things about grouping however is that there is a new interface introduced that you will want to understand, lets take a look at the method signature for GroupBy().

Read More

,

LINQ to SQL: Insert/Update/Delete

I have been looking at my web stats for the recent run of LINQ-to-SQL posts, and it seems a lot of people are making their way here from searches about some of the more standard features of LINQ-to-SQL. In the interest of addressing these visitors I am going to put together a post that covers the basics of data access.

Read More

,

LINQ to SQL: Aggregate Functions and more

In this post I am going to cover off how functions such as Count(), Average() and Sum() work, plus the different ways to call them. Then I will move onto some functions that are not from the domain of SQL but add great features.

Read More

,

LINQ to SQL: Lambda Expressions

At first glance, Lambda Expressions are bound to confuse most people. Myself included. However, a little digging and experimenting will show they are a simple enough concept. I will cover them now to try remove any confusion in later code snippets.

Read More

,

LINQ to SQL: Customisation

Before we proceed, this is a good time to see another feature of LINQ-to-SQL which allows you to change the property names of the generated classes to no longer match the underlying field names, this could be useful if you have a strange naming convention for your field names, or in our case with AdventureWorks we have instances like on the SalesOrderHeader class where it has two links to the Address table (BillTo and ShipTo) but these relationships get modeled Address and Address1.
This is obviously undesirable as there is no clear indication which one links to Address based on ShipToAddressID and which on BillToAddressID.

Luckily we have a solution close at hand.

Read More

,

LINQ to SQL: Custom Queries

Now I have some of the foundations out of the way, albeit in a rather brief overview that assumes a reasonable level of competency, it is time to move onto some of the more interesting code snippets.

One thing I never liked much about writing SQL in either FoxPro or with PassThrough technologies is how you piece together a complex query from a number of UI selections. The most common occurrence of this is in reporting. The number of ways you can usually slice and dice a sales report makes for some fairly nasty code to build a string based SQL statement.

Read More

,

LINQ to SQL: A Step Back

In this, my third article on LINQ-to-SQL, I am going to be taking a step away from the code and delve into a discussion about what I will think most people will miss when they first approach this new technology.

Read More

LINQ to SQL: Prep Work

There are a number of great articles and blogs online for LINQ-to-SQL already. A great place to start is Scott Guthrie’s blog However, I am going to wade into the discussion with my own thoughts.

Read More

,

LINQ to SQL: Getting Started

I am going to start by showing a few new language features that are important to LINQ (and hence LINQ-to-SQL) that you may not have come across yet if you are not already playing around with this stuff.

Read More

Updates..coming soon

So my blog has been a bit quiet lately. The usual mix of being lazy, busy and just generally lacking anything exciting to blog about has kept me quiet.

Read More

,

Microsoft Silverlight

I have recently been playing with Microsoft's new Silverlight technology, both version 1.0 and 1.1 This time it is a bit of a personal project, I'll keep you posted if it amounts to anything more than a bit of fun.

Read More

Fun with ASP.NET

I have spent the last few days setting up an internal wiki for the office. I started with a fairly simple and clean looking wiki I found on sourceforge called ProntoWiki
It is written in ASP.NET, C# and SQL Express 2005, so its a great little app to have a play with these new (for me atleast) technologies and get out of FoxPro for a moment.
Saturday was spent adding the ability to give pages a title that would show instead of the CamelCase key for the page, and writing a Flickr inspired control so we can just click the heading to edit it.
Now I need to go add a few more functions to the parsing routines, I just can't help but fiddle with new toys.