A reference guide of basics of Regular Expressions (Regex) in JavaScript

16 July, 2019.

Welcome back, future Jon. Congratulations, you have successfully forgotten how to regex again. As a reminder to yourself, you have attempted to learn regex many times over the years, and at times you have gotten pretty good at it. Unfortunately, however, it has probably been a while since you last wrote a regex, and you have completely forgotten how to do ANYTHING and EVERYTHING, even the absolute fundamentals. Fear not, I have you covered. Once you read the following guide it will all start…

Continue reading

How to configure Webpack Hot Module Reloading (HMR) using Node.js API

04 April, 2019.

You recently had some reason, probably work related, to configure Webpack from scratch using the Node API. This is because of reasons (for example, you are moving your Webpack configuration into an NPM package), and you found the documentation somewhat lacking!! You quickly became frustrated and decided to search for a tutorial, and now, you are here. Welcome friend!! I too have felt your pain. The Webpack documentation is lacking at best so it is up to community members like myself to fill in…

Continue reading

How to connect to MongoDB Atlas using Mongoose and Node

24 February, 2019.

MongoDB Atlas is a fully managed service that has a fantastic free tier available for developers learning how to build document databases. MongoDB has a long-established history, is battle hardened, and is often used as part of the M.E.A.N (Mongo, Express, Angular, Node) stack (as well as other variants). There is no better time than now to learn and start using MongoDB in production environments to improve the performance of your web applications. TL;DR All source code is available on GitHub…

Continue reading

The Practical React Developer: Learn By Doing Not-So-Mini-Series

28 January, 2019.

The best way to learn is hands on. This not-so-mini-series will teach you all the basics of building a React Web application through hands-on practical exposure. Introducing ‘Property Finder’, a property listings website This tutorial will teach you, hands-on, all the best and most commonly used features of React and the tooling around it. See a preview of the finished website; What is included in this mini series? What is React, and why use it? How to set up your development environment for…

Continue reading

Adding the finishing touches to 'Property Finder'

27 January, 2019.

At the beginning of this project, we created two components. Those components were designed to display key information about a single property and its location. These components were and . Currently, these components are hard coded and not very useful. In fact, they show the exact same information for every property. Not useful at all! Let’s rectify that. The single best way to learn anything is repeated exposure. For this post we will not be learning anything new, but instead utilising the…

Continue reading

Add advanced filtering to a React app using React Context API

27 January, 2019.

In the previous tutorial, we started building out our home page. We looked at React Context API, where we added some code to fetch data from our static web server, and then we used that data to build (and display) a list of properties that are currently available for sale. Next, we need to ensure that we are in-line with the specification set out by the CTO. The end-user must be able to filter the property listings by ‘price’, ‘postcode’ and ‘sort order’. The page must not reload, the changes…

Continue reading

Build a complete property listings page with React.js

26 January, 2019.

As promised, we will now get down to business and really start fleshing out our home page. This post is all about getting our hands dirty by spending time building components, getting our business logic in place, and generally getting some hands-on experience. The approach taken to building out a React application is the same approach you may take when building a real-world production ready application. Take your time, get a good cup of Earl Grey tea, this is going to be a long one. Note for…

Continue reading

How to add routing to a React app using @reach/router

25 January, 2019.

We are building a property listings website, called Premium Property Finder, using React. Our website is a Single Page Application (SPA), designed to load fast and dynamically update based on user interaction or network changes. Traditionally, a user navigates a website by clicking a link (or some other form of interaction) which redirects them to the next page. This process of navigating causes the entire next web-page (including all of its CSS, JavaScript etc) to be (re-)requested and (re…

Continue reading

How to export your React project from CodeSandbox to your desktop with Parcel.js

24 January, 2019.

CodeSandbox is great for getting up and running quickly with no setup. However, CodeSandbox is not usually how I choose to bootstrap my projects and typically the companies I work for do not use an approach like this either (maybe they should, but that is a different post!). You will find that a high percentage of companies today are using Webpack as their preferred front-end build tool. If you would like to learn more about Webpack, I have a comprehensive mini-series, starting with Webpack…

Continue reading

Get started quickly with React using CodeSandbox

23 January, 2019.

To get up and running quickly developing a React web application, you can use CodeSandbox, a fantastic browser-based development environment. Head over to CodeSandbox and if you do not already have an account, I highly recommend creating one so that you can easily save your work and refer back to it later. We will create a couple of components and then migrate our code from CodeSandbox to our local machine in the next post in this series. Note for clarification as this is also a standalone post…

Continue reading

How to set up your development environment for success

22 January, 2019.

How you set up your development environment can be a very contentious topic, a religious argument in which there may not be one single unified answer, but rather many correct answers. In this post I will discuss exactly how I configure my coding environment. Throughout this post I dicuss tools like ESLint and Prettier several times. Should you like to learn about these tools in more detail, I have written a separate, more detailed, blog post on the topic. How I use ESLint and Prettier for a…

Continue reading

What is React.js, and why use it?

21 January, 2019.

React is a tool for building dynamic and interactive user interfaces. React promotes building small pieces, called components, (which are often JavaScript functions or classes), that are assembled to form a UI. Notice that we have not used the word “web” or “page” here, because React itself is view-layer agnostic, meaning a separate view renderer is used to create a UI for the user to consume. React is not a framework, like Angular. React is an unopinionated library that, when combined with a…

Continue reading

How I use ESLint and Prettier for a consistent coding environment

03 January, 2019.

I work independently, as part of small teams, and as part of teams that consist of hundreds of individuals. Many developers will have a different idea of how they want to format their code, and what standards they would like to adhere to. Some teams might not have any guidelines in place at all, which will often lead to preventable problems further down the road. Tooling today exists that can make enforcing coding style and standards a breeze. I just used the word enforcing, but tools like…

Continue reading

How to get started quickly with React

02 January, 2019.

This post explores 3 separate ways to get a React application up and running quickly. TL;DR To get start quickly with React, you have three choices; CodeSandbox Create React App Parcel.js How to get started with React using CodeSandbox CodeSandbox is one of the most useful tools on the web today. CodeSandbox enables you to forget all about the complexities of setting up a development environment and enables you to just start coding. CodeSandbox is truly a breath of fresh air and a pleasure to…

Continue reading

Build a React web app with Parcel.js lightning fast

01 January, 2019.

I have been using Webpack for quite some time now, and I have found it to be slow, frustrating to configure and debug, tedious to change and upgrade (and do not even get me started on the documentation!). I have had the exact opposite experience with Parcel.js. I have found Parcel.js to be fast, easy to configure and the documentation has been excellent so far. Build a React app with Parcel.js from scratch We can create a React app from scratch with Parcel with minimal effort. To get started…

Continue reading

How to add Hot Module Reloading (HMR) to a React app

31 December, 2018.

Before we can add Hot Module Reloading to our React project, we need some React code! Let’s do that first. Create a simple React application We are not trying to win any awards here, we only need to get React rendering out something so we can move on. This is not a tutorial about how to build a useful React website, after all. Start by installing React, and ReactDOM. Both are required to render a React browser-based web application. Note: These are runtime dependencies, so we use instead of…

Continue reading

Getting started with Webpack Dev Server

31 December, 2018.

So far, our application writes out to the console, which is not terribly helpful. Let’s get something up and running in the browser before we configure our React code. To get our website up and running, we will need Webpack Dev Server, which is a simple HTTP server. We will also need a couple of plugins to make everything work properly. Start by creating an file in and add the following code; Now we need to configure Webpack to inject the path to our JavaScript bundle directly into the HTML…

Continue reading

How to configure SCSS modules for Webpack

31 December, 2018.

Your website will look pretty plain without some styles. SCSS is a popular choice for styling and is fairly straightforward to configure. Please note, this post assumes that you already have an existing project built using React, and that you want to add support for SCSS modules. If you need help getting started, check out my post; Webpack 4 from absolute scratch. If you do not already have this line in your Webpack configuration file, go ahead and add it; This is used to optimize your bundles…

Continue reading

How to create a production ready Webpack config

31 December, 2018.

We have seen the basics of a Webpack config, but let’s take a few steps to make the config more production ready and useful for development. First, we need to set a Webpack . We have touched on this a couple of times so far as part of this tutorial. The will determine if Webpack minifies/compresses our code, or not. This is important to get right because it makes a huge difference to the resulting bundle. Set the wrong , and you will not be able to debug your code in the browser, or worse…

Continue reading

How to process images with Webpack

31 December, 2018.

With a couple of small Webpack plugins we can add the ability to be able to import images directly in our JavaScript files, and also process those images (compress them). Run the following command in your terminal to install the required plugins; What are these packages for? resolves your s and copies the file to the output directory (usually with a randomly generated name, for cache busting) processes the images using another package called Note that takes many options. For a more…

Continue reading

Webpack 4 from absolute scratch

31 December, 2018.

Writing your own Webpack 4 configuration from absolute scratch is not strictly necessary. You could go online, find a basic Webpack configuration file and fork it/copy it to your project and use that as your starting point. Whilst using a starter project is good for getting started quickly, it is better to have a more indepth understanding of what is happening, to help with customisations and debugging later. We will configure Webpack to do the following; Build our JavaScript, use Babel and…

Continue reading

How to use AWS Cognito with .NET Core

09 December, 2018.

I never would have believed just a couple of years ago that I would be typing these words. With just a few lines of code you can add authentication and authorisation to your cross platform .NET web application in a secure way using Amazon Web Services (AWS) Cognito API. You can either call the API directly with requests, or take advantage of the built in user interface. As an added bonus, Cognito supports federated identities, allowing you to use external identity providers such as Google and…

Continue reading

Microservices on the front-end - Building front-end apps that scale

21 November, 2018.

Overview This post details a presentation I gave at my local Manchester Web Meetup on 21st November 2018 at The Hut Group in Media City, Salford, UK. Below are the accompanying notes I wrote that acted as a rough speaking guide, and may or may not have been spoken during the event itself. Who am I? Developer at RC, this is where I have learnt about frontend microservice architecture I like to experiment with new ideas, and I make available what I can through my public GitHub repo I have decided…

Continue reading

Managing state in modern React web applications

16 October, 2018.

Overview This post details a presentation I gave at my local JavaScript North-West Meetup on 16th October 2018 at Dept Digital Agency in Manchester, UK. Below are the accompanying notes I wrote that acted as a rough speaking guide, and may or may not have been spoken during the event itself. Assumptions Throughout this talk I will assume that you have at least a working to intermediate knowledge of JavaScript and React concepts, and that you have at least worked with React in some capacity in…

Continue reading

A bare bones React boilerplate, featuring Webpack 4, React, Redux, Jest, and Babel 7

22 September, 2018.

I love template projects. In fact, I use them all the time. Template projects, seed projects, starter projects, whatever you want to call them, they are fantastic. Starter templates help you get up and running very quickly and can be very useful and powerful when learning something new. Many template projects I see around the web are bloated with every feature under the sun. Having a long list of features can be amazing, however, some projects have grown significantly… which can increase…

Continue reading

A high level look at Angular 2

03 September, 2016.

Developed by Google, Angular 2 is the newest version of the popular Single Page Application (SPA) framework. Angular 2 is a step in a new direction compared to previous versions, but has keep all the best characteristics and “lessons learnt” to deliver a fast, fully featured and rich ecosystem. About Angular 2 Angular 2 impacts your whole application, or at the least, a section of it, rather than specific pages. Angular 2 is best suited to new (“greenfield”) development, as it can be relatively…

Continue reading

Angular 2 server side paging using ng2-pagination

31 March, 2016.

Angular 2 is not quite out of beta yet (Beta 12 at the time of writing) but I’m in the full flow of developing with it for production use. A common feature, for good or bad, is to have lists/tables of data that the user can navigate through page by page, or even filter, to help find something useful. Angular 2 doesn’t come with any out of the box functionality to support this, so we have to implement it ourselves. And of course what the means today is to use a third party package! To make this…

Continue reading

Create a RESTful API with authentication using Web API and Jwt

15 March, 2016.

Web API is a feature of the ASP .NET framework that dramatically simplifies building RESTful (REST like) HTTP services that are cross platform and device and browser agnostic. With Web API, you can create endpoints that can be accessed using a combination of descriptive URLs and HTTP verbs. Those endpoints can serve data back to the caller as either JSON or XML that is standards compliant. With JSON Web Tokens (Jwt), which are typically stateless, you can add an authentication and authorization…

Continue reading

How to debug websites on your mobile device using Google Chrome

31 January, 2016.

I can’t believe I have survived this long as a web developer without knowing you can debug websites (JavaScript, CSS, HTML, TypeScript etc.) directly on your mobile device using Google Chrome developer tools. If you are currently using emulators/simulators or testing solutions such as Browser Stack, you will love this easy and free solution. Be warned, however, you will be expected to download 6+ gigabytes of stuff before the magic begins. I’ve only tested this on my Samsung Galaxy S6 Edge…

Continue reading

TypeScript beginners guide

02 October, 2015.

TypeScript is a tool that enables you to write better JavaScript. You may have heard that TypeScript is a superset of JavaScript, but what does that mean? TypeScript is JavaScript. If you know JavaScript already, then you already know JavaScript. You can convert an existing JavaScript file to TypeScript simply by changing the file extension. TypeScript has a very low barrier to entry (you can easily write it using Notepad) and has a small learning curve. TypeScript has a transpiler, called tsc…

Continue reading

Writing AngularJS 1.x with TypeScript

24 September, 2015.

AngularJS 1.x is a front end JavaScript framework that has gained huge traction and popularity in the development community. AngularJS greatly simplifies previously hard tasks like two-way data binding, templating, the MVC design pattern, despendency injection and more. Using TypeScript, we can create more robust and scalable AngularJS code to deliver the ultimate user experience whilst avoiding the traditional spaghetti code nightmare that JavaScript applications can often descend into…

Continue reading

Using ES6 features with TypeScript

18 September, 2015.

TypeScript is a transpiler The TypeScript compiler converts your code from TypeScript, which is a subset of JavaScript, to TypeScript. Compiler vs. Transpiler There is some confusion about the difference between a compiler and a transpiler. A compiler takes your code and turns it into something very different, a whole new language. A good example is with a high level language such as C# or Visual Basic. When you write code and build it, the compiler (either csc.exe C# compiler or vbc.exe Visual…

Continue reading

Getting started with TypeScript

11 September, 2015.

This is the 101 tutorial which describes getting started with TypeScript using either the TypeScript Playground, Node.js or VS Code. At its simplest, TypeScript is a programming language that provides optional static typing for JavaScript. TypeScript is JavaScript. Any valid JavaScript is valid TypeScript. The beauty of TypeScript is that you can define types for your JavaScript variables and functions, and get compile time error checking and error reporting. This tutorial focuses on getting…

Continue reading

TypeScript Tips and Tricks

28 August, 2015.

Automatically compile TypeScript files when using VS Code If you’re writing TypeScript using Visual Studio, your files are automatically compiled when you save (assuming you haven’t turned this off…the feature is found in the Project Properties > TypeScript Build screen). If you don’t use Visual Studio, and instead are using a lightweight IDE such as VS Code or Sublime Text, you don’t get this feature. Manual compilation First things first, how would you normally compile a TypeScript file to…

Continue reading

ASP .NET 5 (vNext), first thoughts

21 August, 2015.

Microsoft ASP .NET 5 is a major shift from traditional ASP .NET methodologies. Whilst I am not actively developing ASP .NET 5 applications at the minute, .NET has always been my bread and butter technology. When I look at industry trends here in the UK, all I see is .NET .NET .NET, therefore it is important to have one eye on the future. I’ve watched all the introduction videos on the ASP .NET website, but I also wanted to take a look at what ASP .NET 5 means to me. This is not meant to be a…

Continue reading

Using Gulp-SASS with VS Code task runner

07 August, 2015.

With the task runner built in to VS Code, you can set up Gulp to automatically compile your SASS files to CSS with a simple key press. VS Code task runner prerequisites To be able to get this working, you need the following prerequisites Windows, Linux or Mac VS Code Node.js and NPM Gulp.js To install Gulp run the following command; or To install into your development environment. I’d generally recommend installing gulp globally as you will likely be using it a lot. You will probably want to…

Continue reading

Why Visual Studio 2015 has changed my life

24 July, 2015.

I’ve been using Visual Studio on an almost daily basis since 2002. Before that, my development tool of choice was Visual Basic 6 (Visual Studio 6). The shift between those two versions felt like using a whole new product at the time. Since then, changes to Visual Studio have been incremental. Microsoft have released a new version every 2-3 years. Visual Studio 2015, however, feels like another significant paradigm shift. The point of this post is not to outline all the shiny new features, there…

Continue reading

What I learnt from using TypeScript "for real"

25 May, 2015.

I completed my first commercial Greenfield project using TypeScript over plain old JavaScript throughout, and there were some frustrations along the way. TL;DR TypeScript is awesome, for sure, but there needs to be improvements to tooling to streamline the experience. TypeScript is strongly typed of course, but it doesn’t force you to code in this manner, which can result in shoddy code. Tweaking is required to make bundling work properly. Tooling Frustrations When I started the project, I was…

Continue reading

WCF custom authentication using ServiceCredentials

03 April, 2015.

The generally accepted way of authenticating a user with WCF is with a User Name and Password with the UserNamePasswordValidator class. So common that even MSDN has a tutorial, and the MSDN documentation for WCF is seriously lacking at best. The username/password approach does what it says on the tin, you pass along a username and password credential from the client to the server, do your authentication, and only if there is a problem then you throw an exception. It’s a primitive approach, but…

Continue reading

.NET developers, utilize Git better using the command prompt

14 September, 2014.

I’ve been using Git in Visual Studio for quite some time now (since not long after it was released) and I’ve really grown to like it. I particularly like the speed and general ease of use. I find TFS/TFVC (weather that be a local instance or TFS online) to be slow and unreliable and it really has poor command line support (sorry guys!). It’s fair to say that I’ve been a little bit intimidated by Git and have rarely (OK never!) strayed away from the UI available through Visual Studio. Until now…

Continue reading

Quick tip - Avoid 'async void'

30 August, 2014.

When developing a Web API application recently with an AngularJS front end, I made a basic mistake and then lost 2 hours of my life trying to figure out what was causing the problem … async void. Its pretty common nowadays to use tasks to improve performance/scalability when writing a Web API controller. Take the following code: At a high level, when is executed the call will be moved off onto another thread and the execution of the method will only continue once the operation is complete (when…

Continue reading

5 AutoMapper tips and tricks

23 August, 2014.

AutoMapper is a productivity tool designed to help you write less repetitive code mapping code. AutoMapper maps objects to objects, using both convention and configuration. AutoMapper is flexible enough that it can be overridden so that it will work with even the oldest legacy systems. This post demonstrates what I have found to be 5 of the most useful, lesser known features. Tip: I wrote unit tests to demonstrate each of the basic concepts. If you would like to learn more about unit testing…

Continue reading

How to create your own ASP .NET MVC model binder

11 August, 2014.

Model binding is the process of converting POST data or data present in the Url into a .NET object(s). ASP .NET MVC makes this very simple by providing the DefaultModelBinder. You’ve probably seen this in action many times (even if you didn’t realise it!), but did you know you can easily write your own? A typical ASP .NET MVC Controller You’ve probably written or seen code like this many hundreds of times; Where did Id come from? It probably came from one of three sources; the Url (), the query…

Continue reading

Easy WCF Security and authorization of users

19 July, 2014.

There are several steps involved in making your WCF service secure, and ensure that clients consuming your service are properly authenticated. WCF uses BasicHttpBinding out-of-the-box, which generates SOAP envelopes (messages) for each request. works over standard HTTP, which is great for completely open general purpose services, but not good if you are sending sensitive data over the internet (as HTTP traffic can easily be intercepted). This post discusses how to take a basic WCF service…

Continue reading

Entity Framework - Use a Guid as the primary key

13 July, 2014.

Using a Guid as your tables primary key, when using Entity Framework, requires a little more effort than when using a integer. The setup process is straightforward, after you’ve read/been shown how to do it. The process is slightly different for the Code First and Database First approaches. This post discusses both techniques. Code First Using a Guid as the primary key when taking the code first approach is simple. When creating your entity, add the DatabaseGenerated attribute to your primary…

Continue reading

How to create a RESTful web service using WCF (Part 3 of 3)

04 April, 2014.

RESTful (Representational State Transfer) web services use HTTP verbs to map CRUD operations to HTTP methods. RESTful web services expose either a collection resource (representational of a list) or an element resource (representational of a single item in the list). Other parts in this series: How to create a RESTful web service using WCF (Part 1 of 3) How to create a RESTful web service using WCF (Part 2 of 3) Testing the WCF service using Fiddler If you haven’t come across Fiddler before, its…

Continue reading

How to create a RESTful web service using WCF (Part 2 of 3)

03 April, 2014.

RESTful (Representational State Transfer) web services use HTTP verbs to map CRUD operations to HTTP methods. RESTful web services expose either a collection resource (representational of a list) or an element resource (representational of a single item in the list). Create the WCF service contract Every WCF service begins with a service contract. A service contract defines what operations are supported/provided by the service. An operation contract is the definition of a method that can be…

Continue reading

How to create a RESTful web service using WCF (Part 1 of 3)

02 April, 2014.

RESTful (Representational State Transfer) web services use HTTP verbs to map CRUD operations to HTTP methods. RESTful web services expose either a collection resource (representational of a list) or an element resource (representational of a single item in the list).HTTP verbs are used as follows; Create (POST) > create a new resource. Read (GET) > retrieve one or many resources. Update (PUT) > update an existing resourπce. Delete (DELETE) > delete an existing resource. This tutorial…

Continue reading

How to add SignalR to the telephone directory sample application

15 March, 2014.

As part of a recent mini series we created a very simple telephone directory web page that showed some features of Bootstrap, KnockoutJS, jQuery, Web API and the Entity Framework. Just for fun, I figured it would be cool to add SignalR so that we could see how simple it is to add full duplex, real time communications to your website. The first parts of the mini series can be found here; /.net/create-a-telephone-directory-with-bootstrap-knockoutjs-jquery-web-api-and-entity-framework-part-1-of-…

Continue reading

Create a telephone directory with Bootstrap, KnockoutJS, jQuery, Web API and Entity Framework (Part 2 of 2)

12 March, 2014.

I find that the best way to learn any new technology, or technology that are unfamiliar with, is to sit down and practice. The purpose of this very simple tutorial is to learn the basics of creating a single page website that can be used to capture peoples names and telephone numbers. By following this tutorial you will learn; How to use Bootstrap to create a simple UI How to use KnockoutJS for binding to/displaying of your data How to use jQuery to asynchronously retrieve data from a web…

Continue reading

Create a telephone directory with Bootstrap, KnockoutJS, jQuery, Web API and Entity Framework (Part 1 of 2)

08 March, 2014.

I find that the best way to learn any new technology, or technology that are unfamiliar with, is to sit down and practice. The purpose of this very simple tutorial is to learn the basics of creating a single page website that can be used to capture peoples names and telephone numbers. By following this tutorial you will learn; How to use Bootstrap to create a simple UI How to use KnockoutJS for binding to/displaying of your data How to use jQuery to asynchronously retrieve data from a web…

Continue reading

How to connect to a SQL Azure database using SQL Server Management Studio

01 March, 2014.

If you are writing a website that will be deployed to Windows Azure, or indeed you are using SQL Azure as the backend for some other endeavour, chances are you will want to connect to that database with a management tool and query its data. You can achieve this in one of two ways; using Visual Studio or using SQL Server Management Studio. Using Visual Studio is fine, but I have been using SQL Server Management Studio for many years and I have grown accustomed to it, so it is my preferred tool…

Continue reading

Quick look - Add indexes to tables with Entity Framework 6.1 Beta 1

26 February, 2014.

At the time of writing, beta 1 of Entity Framework 6.1 has recently been released. This is mostly a maintenance release, however, there are several new feature of note, including the ability to add indexes using a new data annotation when developing using the code first approach. Add indexes using the Index attribute To add an index, simply add the Index attribute as required; A quick look in SQL Server Management studio reveals that the index has been added for us. The key created was non…

Continue reading

Create custom C# attributes

22 February, 2014.

You have probably added various attributes to your ASP .NET MVC applications, desktop applications, or basically any software you have developed using C# recently. Attributes allow you to provide meta data to the consuming code, but have you ever created and consumed your own attributes? This very quick tutorial shows how to create your own attribute, apply it to your classes, and then read out its value. Sample Project To demonstrate this concept, I have created a Console application and added…

Continue reading

Use T4 Templates to create enumerations from your database lookup tables

15 February, 2014.

T4 (Text Template Transformation Toolkit) has been around for a while now… its been a part of Visual Studio since the 2005 release. In case you don’t know, T4 can be used to automatically generate files based on templates. You create a text template, which is then transformed (interpreted) by Visual Studio into a working file. T4 can be used to create C# code files, and indeed it forms the basis of the current scaffolding templates you have probably used when creating ASP .NET web applications…

Continue reading

Publish your website to an IIS staging environment using Microsoft Web Deploy

08 February, 2014.

One of the simplest and quickest ways to publish your website to a staging environment is, at least in my opinion, using Microsoft Web Deploy. This post is about how you approach this, a future article will discuss why you probably shouldn’t do this. Key points; The remote server should be running Internet Information Services (IIS) 7.0 or later. You can use the Microsoft Web Platform Installer to install all the extra bits you need to make this work. You need to set appropriate permissions to…

Continue reading

Resilient Connection for Entity Framework 6

05 February, 2014.

Disclaimer: I cannot take a shred of credit for the code you are about to see. I simply went over to the Entity Framework source code repository on CodePlex, copied some code, butchered it, hammered it, and rolled it until it fitted nicely into the slot that was my requirements. Please direct your thanks to the Entity Framework team. I had a requirement whereby I needed a resilient Entity Framework connection, and by that I mean a connection that could retry a certain number of times…

Continue reading

5 easy security enhancements for your ASP .NET application

26 January, 2014.

Protecting web applications against unauthorised access is somewhat of a dark art, but there are simple steps you can take to ensure that you are protected against the most common security risks. Cross Site Request Forgery (CSRF / XSRF) Problem: Cross site request forgery (CSRF / XSRF) is the process of tricking a legitimate user of your website into posting data to the web server without their knowledge. This type of attack is typically executed using a malicious link in an email, or by social…

Continue reading

Check TFS Online service status using C#

10 January, 2014.

If you use TFS Online you may have experienced some unexpected downtime over the last few months. Whilst the service is getting better and better all the time, downtime is still an issue. I have written a little screen scraping tool based on the HTML Agility Pack that will scrape the service status page and report back the current status. Add the following class to your project; The usage for this code is as follows; I hope you find this little helper useful. Please leave a comment below.

Continue reading

C# Create a custom XML configuration section

21 December, 2013.

It is common when developing either Desktop or Web based applications to need to persist settings in an easily updateable location. Developers often choose to add normal application settings in the form of key value pairs, as shown below, and this is a great approach when you only have a small number of settings. However, as your applications configuration becomes more complicated, this approach soon becomes hard for the developer and end user alike. This blog post looks at how you can create a…

Continue reading

How to create a new Outlook 2013 Email using C# in 3 simple steps

14 December, 2013.

It has traditionally been quite painful to interact with any part of the Microsoft Office product family from a C# application, but thanks to the introduction of dynamics and optional parameters over recent years, the process has dramatically improved. Step 1 - Prerequisites and Assembly References Before doing anything, it is important to note that you must have Microsoft Office 2013 installed for this to work. Seems obvious, but, its still worth mentioning. You also need two references; The…

Continue reading

In the spotlight - Demystifying IQueryable (Entity Framework 6)

24 November, 2013.

I’m not afraid to admit it. I can’t be the only one who has been confused by IQueryable when working with Entity Framework or LINQ to SQL. When using the web to research the topic, I have seen many conflicting blog posts and contradicting answers on StackOverflow. I have read various posts on MSDN about the subject, and I find them difficult to understand and incomplete. I seek to at least attempt to clarify the subject a little with this post. Entity Framework has become such a powerful object…

Continue reading

Exploring logging in Entity Framework 6

13 November, 2013.

A project I am working on at the minute was recently upgraded to use Entity Framework 6.0.1. There were many reasons why we wanted to do this, but one of the most compelling reasons was the new logging (SQL Interception) functionality that ships out of the box. A colleague demonstrated this new functionality and I immediately noticed a problem (limitation if you will) that I foresaw becoming a bigger issue when the time comes to performance tune the application. Implementing simple logging Take…

Continue reading

Effectively debugging WPF MVVM applications

13 September, 2013.

Being able to effectively debug any application is key to the success of an application. Every developer, no matter how good they are or how long they have been writing code, introduces bugs. Debugging is the process of identifying bugs and removing them. WPF applications can be particularly hard to debug, if you are not using the correct tools. This post attempts to help you utilise various free tools to help simplify the debugging process. Binding Errors Binding errors are very common in all…

Continue reading

How to fix 'Project failed to build' error when adding an Entity Framework migration (add-migration)

06 September, 2013.

I recently spent several hours tearing my hair out try to figure out why Entity Framework was preventing me from adding a migration to my project. I made some very simple changes to my existing model (I’m developing using the Entity Framework Code First approach) and when trying to add a migration, I was presented with the following error message; But how can this be? For you see, my project does build… My project not only builds, but it runs and works just fine … (up until the point where…

Continue reading

C# Writing unit tests with NUnit and Moq

30 August, 2013.

I’m assuming that you have seen the light, and that you are sold on the benefits (and indeed the drawbacks) of unit testing. I have read literally dozens of blog posts, watched many videos, and read several books about unit testing and the various approaches and frameworks. I have worked with several of these frameworks in both small and enterprise level applications, and I have found that (in my opinion at least) NUnit and Moq are great for helping to get simple tests written quickly and to a…

Continue reading

How to write more efficient and maintainable C# code

23 August, 2013.

When you are writing your C# applications, you are aware that you want to make your applications as efficient, maintainable, and as scalable as possible. These are some great keywords that look great on blog posts like this, but how do you actually set about achieving this goal? We will look at some simply guidelines which try to make this goal more achievable. Write single purpose methods Your methods should have a single purpose… a single task to perform. For example, a single method should…

Continue reading

WPF Entity Framework Code First migrations

16 August, 2013.

Recently I wrote a WPF application using Entity Framework Code First and released it into the wild. Shortly after, the business requirements changed and I had to make changes to the model. Thus, I was introduced to Code First migrations. I did a lot of research on Code First migrations and could only really find the most simple of examples, and almost robotic documentation on MSDN that provided minimal help. This post aims to provide a clearer view on migrations, and how to properly create them…

Continue reading

Using StructureMap setter injection to inject repositories into your View Model

09 August, 2013.

This short post is a follow on from an earlier series of posts that discussed how to achieve MVVM purity in WPF using Structure Map. You may want to check out those posts first before reading this post. However, if you just generally want to know how to do setter injection using Structure Map, you are in the right place! A Scenario It is very common in modern applications to have a repository that does the job of retrieving and saving data from/to your database. Your repository may look like…

Continue reading

Getting started with SQLite and C#

07 August, 2013.

SQLite is a powerful, extremely light-weight transactional SQL database provider. SQLite is free and open source, and it does not require any server processes to handle it. SQLite is cross platform and runs on multiple architectures, making it ideal for use on the major operating systems such as Windows, Mac OS, Linux, and even lower powered devices such as PDAs, MP3 players etc. Prerequisites It is possible to get up and running with SQLite quickly in C#, by adding the System.Data.SQLite…

Continue reading

WPF MVVM IoC containers - Part 2 of 2

02 August, 2013.

The ultimate goal of MVVM is to achieve true separation of concerns, meaning that the various elements of your project know nothing about each other. It’s virtually impossible to achieve this in an elegant way in WPF without some outside help. You are reading the second part of this blog post where we will discuss how to use an IoC container properly in a WPF MVVM application. It is assumed you have either read the first post, or are familiar with the concept of IoC/dependency injection with…

Continue reading

Redefine where NuGet packages get installed

31 July, 2013.

If, like me, you are working on multiple projects that reference the same packages (StructureMap is a great example) you may have noticed that each project has its own version of each package. In this bite sized post, we will look at how to redefine where your packages get installed. Root source control folder Here was my root source control folder before making any changes. When I dive into each folder, I see a packages folder, which contains each of my packages. Generally I use the same…

Continue reading

Consuming a WCF service without adding a Service Reference

29 July, 2013.

A problem I have had with WCF since I first discovered it a few years ago is related to Service References. The fact that I have to rely on the ServiceModel Metadata Utility Tool (Svcutil.exe) to generate a proxy class on my behalf left a sour taste in my mouth. A good solution would be for me to be able to write code myself to take this pain away. A Simple Approach One approach to do this is to take over the responsibility of creating bindings and endpoints yourself in your consuming…

Continue reading

WPF MVVM IoC containers - Part 1 of 2

26 July, 2013.

The ultimate goal of MVVM is to achieve true separation of concerns, meaning that the various elements of your project know nothing about each other. It’s virtually impossible to achieve this in an elegant way in WPF without some outside help. For example, how to you tie the view model to a view? Here are some ideas that spring to mind; 1) You could set the data context directly in the view; You could set the data context in the views code behind file; Or you could set the data context when the…

Continue reading

Making NuGet work for your company

19 July, 2013.

NuGet is a package manager tool for the .NET Framework. NuGet is free, open source, and is supported by Microsoft Visual Studio, as well as several other environments. NuGet allows you to add packages to your projects, either from the public package gallery or from your own private package gallery. The latter is, in my opinion at least, somewhat under-utilised and misunderstood in the business world. This post aims to try to shed some light on how NuGet can work for your company. Public Gallery…

Continue reading

Entity Framework Code First In 15 Minutes

12 July, 2013.

Entity Framework is an Object Relational Mapper (ORM), created by Microsoft and built on top of the popular ADO.NET framework. Entity framework was first released in the second half of 2008. In 2011, with the release of version 4.1, a new feature was introduced… known as “Code First”. Code first allows us to write code without having to care (to a certain extent) about the make-up of the database, its tables and their relationships. The idea is that Entity Framework figures all this out for us…

Continue reading

WPF MVVM For WinForms Devs - Part 5/5

06 July, 2013.

The purpose of this series of tutorials is to introduce the Model-View-ViewModel (MVVM) design pattern, and look at how to quickly and simply implement it in a Windows Presentation Foundation (WPF) application. This series is targeted at developers of all levels, but especially at developers who are looking to make the transition from Windows Forms to WPF. This final part of the series assumes you have at least read the previous parts, or have a good working knowledge of WPF and the MVVM design…

Continue reading

WPF MVVM For WinForms Devs - Part 4/5

29 June, 2013.

The purpose of this series of tutorials is to introduce the Model-View-ViewModel (MVVM) design pattern, and look at how to correctly implement it in an Windows Presentation Foundation (WPF) application. This series is targeted at developers of all levels, but especially at developers who are looking to make the transition from Windows Forms to WPF. Events in Windows Forms applications Assuming you have come from a Windows Forms background, regardless of what design patterns (if any?) you used…

Continue reading

WPF MVVM For WinForms Devs - Part 3/5

22 June, 2013.

The purpose of this series of tutorials is to introduce the Model-View-ViewModel (MVVM) design pattern, and look at how to correctly implement it in a Windows Presentation Foundation (WPF) application. This series is targeted at developers of all levels, but especially at developers who are looking to make the transition from Windows Forms to WPF. Capturing user input In the previous walkthrough we; set up our view model, bound it to the view, and added a property for our model class. We then…

Continue reading

WPF MVVM For WinForms Devs - Part 2/5

15 June, 2013.

The purpose of this series of tutorials is to introduce the WPF MVVM (Model-View-ViewModel) design pattern, and look at how to correctly implement it in an Windows Presentation Foundation (WPF) application. This series is targeted at developers of all levels, but especially at developers who are looking to make the transition from Windows Forms to WPF. How to quickly implement MVVM in your C# WPF application Start by firing up an instance of your favourite version of Visual Studio (free or paid…

Continue reading

WPF MVVM For WinForms Devs - Part 1/5

08 June, 2013.

The purpose of this series of tutorials is to introduce the WPF MVVM (Model-View-ViewModel) design pattern, and look at how to quickly and simply implement it in a Windows Presentation Foundation (WPF) application. This series is targeted at developers of all levels, but especially at developers who are looking to make the transition from Windows Forms to WPF. The first part of this series will focus on; What exactly is MVVM, and why should I care? What problem does the MVVM design pattern…

Continue reading