C# Design Patterns

Providing one instance for the whole application

Photo by Hitesh Choudhary on Unsplash

Design patterns are common coding practices defined to solve common software development problems.

The Singleton pattern was developed to provide a common way of providing a single instance of an object throughout the whole application lifetime. So, as long as the application is not restarted, this instance must be the same regardless of how many times you instantiate it.

Usage and Drawbacks

Some examples of singletons are objects that need to share resources between classes or threads, like:

  • Global state management
  • Logging service
  • .NET Core AppSettings
  • And others…

Sometimes, with poor implementation, the Singleton pattern can actually become an anti-pattern , the reasons…


ReactJS with Docker Containers

Using Docker containers to create a ReactJS application development and a production-ready image

Photo by Cameron Venti on Unsplash

In a previous article, I showed how to create a production-ready build for a .NET Core application. In this one, I will walk you through on how to use Docker to create an image for development and another image for production for a ReactJS application.

Requirements

Docker Windows requires Hyper-V to run and it is only shipped with the Pro version, so you are on a Windows that is not a Pro version you might have to use Docker Toolbox.

  • Your preferred IDE/Text Editor

You might want to add this Docker extension that adds syntax highlighting and other features…


.NET Core API and ReactJS with SignalR

Using SignalR to create a real-time application with .NET Core and ReactJS

Photo by James Harrison on Unsplash

WebSockets is a technology that enables your server and your client to keep a connection open and send requests to each other. This is widely used when you need to keep your clients synchronized or to send messages or notifications to all your clients.

Microsoft developed SignalR, which is its technology for developing real-time applications, which are applications where the server can push information to the client instantly. SignalR also has support for the implementation of WebSockets.

Here I’m going to walk you through the creation of a simple real-time chat by having a .NET …


Entity Framework Core

Let’s make it easy to understand relationships between entities with Entity Framework Core with Code First approach

Entity Framework is a very powerful Object Relational Mapper (ORM). It facilitates so much the life of a developer when it is needed to handle information coming from a database, even more after the powerful feature Code First was released.

Even being easy to configure, sometimes we face some configurations that can be a little bit tricky to understand. This is the case when handling entity relationships — one-to-one, one-to-many, many-to-many.

I would say that some situations can get some developers confused, more frequent when dealing with many-to-many relationships. …


.NET Core with Docker Containers

Let’s create a production build with Docker

Photo by Ishant Mishra on Unsplash

Hey guys!

Today I’m writing about creating a production build for a .NET Core application using Docker. These are super exciting technologies and see many people wanting to learn more about how to use them together.

For those that don’t know, Docker allows you to easily create, deploy, and run applications. You pack your app and all its dependencies together and then ship into a docker image. Then you can run a container with this image in any machine running docker and be assured that your application will work fine, regardless of the machine’s configurations.

Requirements

Docker…


.NET Core 3+ Global Error Handling

Handling all your exceptions with global exception handlers

Exception handling is a really important part of an application. This provides us the capability of intercepting system errors, predictable or unpredictable so that we can take actions based on what happened.

Normally when dealing with code that can potentially throw an exception you involve it in a try-catch block to catch exceptions that can be thrown and treat this exception in some required way and/or throw it again.

Here is an example of how you would do in a Controller method:

Example endpoint with try-catch

The problem with using just this approach is that you’ll probably need to add…


JavaScript and C# similarities

A closer look on how you can perform some array/list operations in both languages

I’ve always been a full stack developer and mostly using C# and JavaScript. With time I started to notice a lot of syntax similarities between both languages and I found that very interesting because it helped me so much when I needed to change context between back-end C# development and front-end JavaScript development.

Here I want to show you some of these similarities when working with arrays/lists in both languages.

JavaScript has many natives methods for manipulating arrays and C# has its LINQ queries, which is a built-in library, that make list manipulating a lot more fluent.

Iterating

We all know…


.NET Core Authentication and Authorization

Leveraging .NET Core Identity and JSON Web Tokens to make your API more secure

Hey guys!

Here I’m going to show you how to leverage from ASP.NET Core Identity to assist in management of users (Signup, Login, …) and how to secure your API by generating and validating JWT — JSON Web Tokens.

I had an issue while I was developing an application where I couldn’t find any information, articles or examples regarding how to make use of Identity with a multi-layer application, this led me to a lot of research to finally get on providing a good solution. Now I want to share this with you guys to help make your lives easier.

Requirements


Let’s build together a multi layer .NET Core API with the latest framework version and most used patterns

This is my first ever article written. I decided to write because I actually couldn’t find many articles explaining on how to separate your application in multiple layers. I hope you guys enjoy it. :)

Here we are building a nice API with basic CRUD (Create, Read, Update, Delete) operations. It will be an API for an app that stores which musics you like with its artists. We will call it MyMusic.

I will show you how to:

  • Create an application in separated projects to make it decoupled from each module.
  • Implement Repository and Unit of Work pattern.
  • Use Entity…

Andre Lopes

Full-stack developer and casual gamer

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