Csharp

Live reload in .NET Core

This week I was looking for a way to do live reloading in ASP.NET Core projects.

Don’t judge me, but I actually never cared that much about live reloading, I lived life in a constant state of stopping and starting applications every after a few changes. What changed is that after working with React for a few months I really liked the idea of reflecting changes from your code in the application instantly (well, almost).

Omegle clone using SignalR

A few days ago I was looking through SignalR and I had the idea to build an Omegle clone. The Omegle one-on-one random chat have a good fit with SignalR, so I decided to try it.

Talking about my implementation in more detail, the two most important parts of my application are the SignalR Hub call ChatHub and the chat.js file where I added SignalR hub client connection code.

In ChatHub the methods OnConnected and OnDisconnected were overridden from the Hub base class so I could add logic for when a new user connects to chat with someone or when disconnects (abruptly or not). Every connection is stored in a static variable Chats that are going to be deleted in case the application closes. I also created a Send method for when an user sends a message to the other user.

Bulk inserting data into SQL Server using C#

In the last few days I had a question: what is the most fastest method to bulk insert data into a SQL Server database using C#? I decided to gather up all methods that I could find and do a very simple performance test to decide which one is the fastest.

Here are my results for inserting 10000 rows over 500 iterations:

MethodTime
SqlBulkCopy class137.022 ms
bcp utility146.876 ms
Table-Valued Parameter150.900 ms
Simple.Data208.320 ms
XQuery235.490 ms

My configuration:

Quick tips for building a API using Nancy

Hello! I’m writing this brief post to help everyone that is using Nancy for the first time to not make the same mistakes that I did. I’m not even remotely interested in covering all possible aspects involved in developing a web application using Nancy, I just thought I’d share some of my mental notes gathered a few months ago. So, here we go.

Know how to properly use CORS

If you are using CORS avoid to use the wildcard in the Access-Control-Allow-Headers CORS header because he can have unpredictable behavior.

Defining cross cutting concerns using the MediatR library

Hello! A few months ago I did a freelance gig in which I found myself having trouble to define where exactly to put things like logging, authentication, persistence common logic and so on. These elements are somehow detached from the core business logic and are very similar or exact the same in every application. If you decide to insert them in all your methods you are going to have a lot of repeated and unmaintainable code very fast.

Using dependency injection in MongoDB CSharp Driver

Hello! So, it seems that I delayed once again new posts in here. Since I promise to no one that I need to post here on regular basis I don’t think that I need to apologize, hehe (just kidding). So, as the title says I here to talk a little about dependency injection and post a code snippet about using DI on MongoDB CSharp Driver basic classes.

Dependency Injection

If you don’t want to know or already know the concept behind dependency injection, just jump to the code. As you may know dependency injection helps us programmers to control code dependencies easier. When you use dependency injection (or DI) depending on the language that you are using you just need to use an attribute, annotation or something else that helps to inject (like the name says, doh!) the dependencies into your code without the need to instantiate or set the objects manually.

Null propagator operator on C# 6.0

Hello again! Today I’m going to talk briefly about a specific feature from the next version of C#: the not so new null propagator operator. Yes, its been awhile since C# 6 was announced but I want to talk about this, so you cant do anything to stop me! The main reason I’m talking about this it’s because since I saw the proposal for implementing the operator in C# I really liked and hoped that Microsoft implement, and he did it! In the latest Visual Studio 2014 CTP version the operator was there and of course I looked. Verdict: tested and approved!

Solve a simple problem during RabbitMQ setup in Windows

RabbitMQ

Hello! So, for you that don’t know what is exactly RabbitMQ, let me briefly explain before anything else: RabbitMQ is a framework that provides a messaging system based on the AMQP standard (click here to know more).

Considering my experience developing Microsoft solutions today I got interested in learn how to use EasyNetQ, a .NET API implementation for RabbitMQ. Before trying to do anything using EasyNetQ I start following the Quick Start Guide for EasyNetQ and had some problems. This post focus on those problems and describes a simple way to solve them.