Dependency injection (DI) is a wonderful thing. Simply add your dependency as a parameter to the constructor (most commonly) of your class, register it with your DI container, and away you go — the DI container will manage the rest. Some of the key benefits of DI are: greater testability, greater maintainability, and greater reusability.

// without DI
public class OrderController : Controller
{
public ActionResult Post(Order order)
{
using (var dbContent = new MyDbContext())
{
dbContext.Orders.Add(order);
dbContent.SaveChanges();
return Ok();
}
}
public ActionResult Get()
{
using (var dbContext = new MyDbContext())
{
var orders = dbContext.Orders.ToList();
return new…


What is Primitive Obsession?

To start with, primitives are the basic data types available in most languages. These include data types such as strings, numbers (int, floats), and booleans.

Primitive obsession is a code smell in which primitive data types are used excessively to represent your data models. The problem with primitives is that they are very general. For example, a string could represent a name, an address, or even an ID. Why is this a problem?

  • They can’t contain any model-specific logic or behaviour, meaning that any logic must be stored in the containing class. …


Recently I’ve been learning how to write code in F#. For those who haven’t heard of it, F# is Microsoft’s/.NET’s answer to a functional-first programming language. My motivation was to learn a functional programming language that would make coding for scientific computing and data analysis more expressive, concise, and maintainable, all while fitting seamlessly into the .NET ecosystem that I already know and love. F# fits that bill perfectly.

Why Functional Programming?

For an object oriented programmer, the idea of functional programming can be a little foreign at first. We’re used to applications in which everything is an object and the application works…


Vue Draggable is a great library for Vue.js that makes it super simple to create interactive draggable components with virtually no effort. I have recently used it to create an interactive kanban board, in which tasks can be rearranged and moved between cards just by dragging.

So let’s start by creating some reorderable cards! P.S I’m using Vuetify as the UI framework, in case the tags look unfamiliar.

<template>
<v-container fluid>
<v-row>
<v-col class="text-right">
<v-btn color="primary" depressed @click="addCard"> Add Card </v-btn>
</v-col>
</v-row>
<v-row>
<v-col v-for="(card, i) in cards" :key="i" cols="12" sm="6" md="4">
<v-card outlined>
<v-card-title>
<v-text-field v-model="card.title"></v-text-field> …

I’m not ashamed to admit that for a long time I avoided writing tests for my code. I saw it as something that took up precious time that I could have spent on “real” coding. However, after experiencing first-hand the headache caused from having to maintain production code with little-to-no tests, I’ve been convinced that writing tests really are worth your time. Too many times have I been bitten by hidden bugs, that could have easily been identified if the appropriate tests were in place.

Test Driven Development

Test Driven Development (TDD) is a software development cycle that focusses on describing the behaviour…


I recently wrote a blog post introducing some of my favourite NuGet packages: My Top 4 NuGet Packages for ASP.NET Core. In that post, I briefly introduced a package called MediatR. Today, I will dedicate this post to revisiting MediatR in further detail.

What is MediatR?

MediatR is an implementation of the mediator pattern. It is a behavioural software design pattern that helps you to build simpler code by making all components communicate via a “mediator” object, instead of directly with each other. This helps the code to remain highly decoupled and reduces the number of complex dependencies between objects.

A good real-world…


In this article, I will teach you the basics of making your own web app, by creating a checklist app. ASP NET Core will be used to create a CRUD API and Vue will be used to create the frontend UI. Using the knowledge gained here, you should be able to apply it to start making your own web apps. You can find the complete solution in the GitHub repository.

We will first start with building the API and then move on to the Vue client.

Creating a checklist API

Start by creating a new ASP NET Core Web API project in Visual Studio.


When you think about database providers for ASP NET Core apps, you probably think about Entity Framework Core (EF Core), which handles interacting with SQL databases. But what about the NoSQL options? A popular option for NoSQL is MongoDB. So in this article we’re going to learn how to create a simple ASP NET Core CRUD API using MongoDB as the database provider.

I have created a GitHub repo for this project, so please feel free to clone it here.

Start by creating an ASP NET Core Web API project and then install the MongoDb C# Driver NuGet package:

MongoDB.Driver


Method overloading and overriding are two common forms of polymorphism ( the ability for a method or class to have multiple forms) in C# that are often confused because of their similar sounding names. In this article, we show the difference between the two with some practical code examples.

Overloading

Overloading is the ability to have multiple methods within the same class with the same name, but with different parameters. Each of these methods has their own implementation as well, meaning that they can behave differently depending on what is passed in.

Overloading is known as compile-time (or static) polymorphism because…


User authentication and authorization can be difficult and time consuming. Getting it wrong can also have disastrous consequences, such as malicious users accessing and stealing personal or sensitive information from your app.

Unless you are a large organisation that can afford to spend lots of time on developing a bespoke authentication/authorization system, it is often best to make use of existing solutions to streamline your development process and give you peace of mind.

Auth0

Auth0 is one such solution, and could be called Authentication as a Service (AaaS) or Identity as a Service (IDaaS). In short, it is a complete user…

Sam Walpole

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store