If you’ve spent time around C# and .NET, it’s likely that you will have come across LINQ (Language-Integrated Query), which allows you to use a range of powerful querying capabilities directly in the C# language.
The example below demonstrates a couple of common features of LINQ (note that I am using the extension method syntax rather than LINQ expressions). In the example, we have a list of people and want to obtain a list of names of the adults in that list. …
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())
dbContent.SaveChanges(); return Ok();
} public ActionResult Get()
using (var dbContext = new MyDbContext())
var orders = dbContext.Orders.ToList(); return new…
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?
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.
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.
<v-btn color="primary" depressed @click="addCard"> Add Card </v-btn>
<v-col v-for="(card, i) in cards" :key="i" cols="12" sm="6" md="4">
<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 (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.
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.
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.
Start by creating an ASP NET Core Web API project and then install the MongoDb C# Driver NuGet package:
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 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…