October 16, 2020
  66
Memory problems in a big .NET application are a silent killer of sorts. Kind of like high blood pressure. You can eat junk food for a long time ignoring it until one day you face a serious problem. In the case of a .NET program, that serious problem can be high memory consumption, major performance issues, and outright crashes. In this post, you'll see how to keep our application's blood pressure at healthy levels.
October 14, 2020
  97
The Null Object Pattern is a pattern that uses objects with null behavior instead of performing null checks throughout the codebase. ILogger and ILoggerFactory are dependencies that often require a lot of null checking, so they are perfect candidates for the null object pattern. Suppose your classes take ILogger or ILoggerFactory as a dependency, and you are not using the null object pattern. In that case, you will probably find that your code is either subject to NullReferenceExceptions, or forcing implementors to supply loggers as arguments. Use the null object pattern to avoid both these problems. This article teaches you how in C#. Null object might be confusing for some people because it seems to imply that the object reference might be null. However, the opposite is true. The object will never be a null reference. Null refers to the behavior of the object - not the reference itself. I think that a better name for the pattern would be Dummy Object Pattern since the objects you will use are shells with no behavior.  Why Use the Null Object Pattern? If you inject dependencies into your classes, you need to validate against null or perform null checking throughout your code. The null conditional operator ?. helps, but it is still very easy to miss one. Every single missed question mark is a bug in the code. The null object pattern gives you a third option of using a dummy object instead. This reduces the number of code paths and therefore decreases the chance of NullReferenceExceptions while still allowing the implementor to instantiate the class without creating an instance of the dependency. In the case of ILogger, it is quite onerous to create an implementation. Simply put, you shouldn't do it. If you want to implement logging, you should use an existing logging library. It becomes even more onerous if the dependency is ILoggerFactory. The implementor needs to pull in external dependencies or create a cascading set of classes that they may have no idea how to implement. It gets much worse when you try to mock ILogger or ILoggerFactory dependencies. Although it is still important to verify that logging gets called. You can read about that here.  The Basics The good news is that the Microsoft.Extensions.Logging.Abstractions namespace comes with null objects right out of the box. All you need to do is use NullLogger.Instance and NullLoggerFactory.Instance as default instances in your constructor. That's it. Your class can now depend on these instances, as though there is a real instance.  This example guarantees that the logger will never be null without forcing the code to supply a logger. The readonly modifier ensures that the instance cannot be set to null after construction. The code does not throw a NullReferenceException: using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using System; namespace ConsoleApp { class Program { static void Main(string[] args) { new Example().Print(Hello World!); } } public class Example { readonly ILogger _logger; public Example(ILogger logger = null) { _logger = logger ?? NullLogger.Instance; } public void Print(string message) { _logger.LogTrace(Logged message: {message}, message); Console.WriteLine(message); } } } In some cases, your class should take an ILoggerFactory instance because it may need to pass loggers to child dependencies in the future. You can use the same approach. namespace ConsoleApp { class Program { static void Main(string[] args) { new Example().Print(Hello World!); } } public class Example { readonly ILogger _logger; readonly ILoggerFactory _loggerFactory; public Example(ILoggerFactory loggerFactory = null) { _loggerFactory = loggerFactory ?? NullLoggerFactory.Instance; _logger = _loggerFactory.CreateLogger<Example>(); } public void Print(string message) { _logger.LogTrace(Logged message: {message}, message); Console.WriteLine(message); } } } Notice that we use the static property instance of both classes. We could create new instances of these objects in each case, but this would consume extra memory CPU to construct. The static instances only instantiate once i...
October 13, 2020
  74
Sometimes Blazor needs a nudge to render
October 12, 2020
  73
Launching .NET for game development that runs on a wide variety of platform using purpose built gaming engines. Develop games on Windows, Linux, or mcaOS.
October 06, 2020
  87
The post describes JetBrains Rider as an alternate to Visual Studio and how Rider can help mitigate some of the Visual Studio pain-points.
October 05, 2020
  89
I have been a developer for the past 7 years. I’ve gone through a lot of code reviews during that time. I have devoted my time to learn good software engineering practices through C#. Last ye…
October 04, 2020
  206
In this video, learn about Azure best practices on how to add a custom domain to your web app and how to secure your custom domain with an App Service Manage...
October 04, 2020
  165
This week, James is joined by Leomaris Reyes, Microsoft MVP, who walks us through building beautiful user interface step-by-step with Xamarin.Forms! **Show L...
October 04, 2020
  87
Microsoft's .NET Core team admits it needs to be better at supporting contributors to its open-source projects.
October 02, 2020
  560
403 Forbidden403 Forbiddennginx

Hot Vacancies

Middle / Senior Full-Stack .NET developer

Springdel
.NET Core

The project aims to change the shape of the healthcare market making it easier to find affordable services.

Middle .NET Developer

MyCredit
.NET Core

MyCredit is a space with a huge soul and a pleasant atmosphere. We are a product company, a leader in the microcredit market with 4 years of experience! We are included in the Top 3 FinTech and e-commerce projects of the country! We believe in the potential of each person, in his talent and desire to develop, and we also believe in respect and support. Therefore, we have assembled a team of guys who share our faith and go forward with us. If all this is about you, be sure to read it to the end! Our team of professionals is rapidly gaining momentum, and now we are looking for a Middle .NET Developer who will be interested in working with BPM Corezoid.

Lead .NET Developer

MyCredit
.NET Core

MyCredit is a space with a huge soul and a pleasant atmosphere. We are a product company, a leader in the microcredit market with 4 years of experience! We are entering the Top 3 FinTech and e-commerce projects of the country! We believe in the potential of each person, in his desire to develop, and we also believe in respect and support. Therefore, we have assembled a team of guys who share our faith and go forward with us. If all this is about you, be sure to read it to the end! Our team of professionals is rapidly gaining momentum, and now we are looking for a Lead .NET Developer to work on a high-load project.

Backend Developer

Oneview Healthcare
.NET Core

Oneview Healthcare is a global company, working with hospitals and senior care facilities around the world.

Senior .NET Developer

.NET Core

We are looking for Senior .Net Developer to join Kiev team. You will be part of a team of strong, result-oriented professionals developing new generation tasks management, people management, learning platform.