Featured

Service Fabric Handbook

Welcome!

This post is a handbook where you probably will find an answer to “How different things works in Azure Service Fabric?” question. Almost all of the information (around 90%) is from docs.microsoft.com, GitHub and etc., the rest of it are personal findings made during development of CoherentSolutions.Extensions.ServiceFabric.Hosting.

Where possible the information will be confirmed by reliable source (docs, issues or posts).

Continue reading “Service Fabric Handbook”

.NET R&D Digest (April, 2019)

There are a lot of good technical articles & books on Web. I see them all the time – when trying to find a solution, when investigating things or simply when reading new posts from my RSS Feed during breakfast.

Having all these knowledge only for myself was a bit selfish. That is why once a month or two I compose some of this content into a so called ‘digest’ for colleagues & friends.

After fourth issues (this one is the fourth) I though – maybe this can be interesting for my readers? So this is the Aprils issue of .NET R&D Digest.

Continue reading “.NET R&D Digest (April, 2019)”

Code Tip: How to work with asynchronous event handlers in C#?

Have you ever faced a need to raise an event in C#? I am almost certain the answer is “Yes, and I have no problems with it“. So did I, but as usual there are some cases when raising events can be tricky.

Imagine a Demo class with single DemoEvent event and Raise method:

public class Demo
{
  public event EventHandler DemoEvent;

  public void Raise()
  {
    this.DemoEvent?.Invoke(this, EventArgs.Empty);
    Console.WriteLine("All handlers have been executed!");
  }
}

In Program.Main create a new instance of Demo and subscribe for DemoEvent:

class Program
{
  static void Main(string[] args)
  {
    var instance = new Demo();
    instance.DemoEvent += (
      sender,
      eventArgs) =>
    {
      Console.WriteLine("Executed!");
    };
    instance.Raise();
  }
}

Application outputs:

Executed!
All handlers have been executed!

Everything is fine until someone replaces synchronous event handler with asynchronous one:

// class: Program / Main()
//...
instance.DemoEvent += async (
  sender,
  eventArgs) =>
{
  await Task.Delay(10);
  Console.WriteLine("Executed!");
};
//...

Outputs:

All handlers have been executed! 

Oh no! One more post about async-await and event handlers! I am out!

Disappointed reader

(Sound of clapping browser page)

Hey await! Just give me a moment! I am promising not to say anything about when you should or shouldn’t use async-await!

This post is about absolutely opposite thing. Here I want to share a way how you can update Demo class to support both synchronous and asynchronous event handlers.

(Sound of incoming HTTP GET)

Just want to see code? The complete sample (with all the improvements) is available as Gist.

Want to know more? Then let’s dig into.

Continue reading “Code Tip: How to work with asynchronous event handlers in C#?”

CoherentSolutions.Extensions.Configuration.AnyWhere Release 1.0.3

The new release of CoherentSolutions.Extensions.Configuration.AnyWherec is here!

The release 1.0.3 is available on NuGet.

The release notes can be found on project version page.

What’s new?

This release includes minor bug-fix, performance improvement and a new configuration adapter for Azure Key Vault.

Interested? Let’s see the details!

Continue reading “CoherentSolutions.Extensions.Configuration.AnyWhere Release 1.0.3”

“html-escape” – a contributor’s story about Visual Studio Code extension

Have you ever find yourself typing ‘Escape html online‘ in Google search?

I’ve had 🙂

Recently I got tired of these searches and decided to look for an extension to Visual Studio Code, which I use for writing. This is where I met html-escape by Raymond Camden.

I used it for quite awhile a come up with some ideas of how to make it better. The problem was, these improvements required significant design changes. This has made me decide to start contributing.

In this post I invite you to join me in making these design changes. We will take a look at existing application feature set, get acquainted with some of Visual Studio Code concepts and theory, discuss application requirements, create application design (no architectural diagrams) and then literally implement all existing application features fitting them into our design.

Interested? Then let’s start.

Continue reading ““html-escape” – a contributor’s story about Visual Studio Code extension”

CoherentSolutions.Extensions.Hosting.ServiceFabric Release v1.4.0

The new version of CoherentSolutions.Extensions.Hosting.ServiceFabric is released!

The version 1.4.0 is available on NuGet.

The release notes can be found on project version page.

What’s new?

This release brings support for configuration of custom implementation of ICommunicationListener.

Let’s see the details!

Continue reading “CoherentSolutions.Extensions.Hosting.ServiceFabric Release v1.4.0”

Release of CoherentSolutions.Extensions.Configuration.AnyWhere

Today I am announcing the first release of CoherentSolutions.Extensions.Configuration.AnyWhere!

The 1.0.2 version is available on NuGet.

What this project is about?

Writing extensible applications usually requires application to be able to change its behavior without code changes. This is mostly refer to execution of the application in different environment: on developers box, staging and production.

In traditional ASP.NET Core application environment management is handled somehow like this:

    WebHost.CreateDefaultBuilder(args)
      .UseStartup<Startup>()
      .Build()
      .Run();
    

The WebHost.CreateDefaultBuilder automatically includes appsettings.json and appsettings.{environment}.json configuration files allowing application to load configuration depending on the environment (the environment value is read from ASPNETCORE_ENVIRONMENT environment variable).

When you need something more sophisticated than different .json configuration file i.e to consume configuration from different configuration sources then traditional approach is to use IHostingEnvironment extension methods like: IsDevelopment, IsStaging or more generically IsEnvironment to configure additional configuration sources during startup:

    WebHost.CreateDefaultBuilder(args)
      .ConfigureAppConfiguration(
        (ctx, config) =>
        {
          if (ctx.HostingEnvironment.IsEnvironment("env"))
          {
            // register custom configuration source
          }
        })
      .UseStartup<Startup>()
      .Build()
      .Run();
    

While this works we still have strong relationship between our code and environments.

This is the part where CoherentSolutions.Extensions.Configuration.AnyWhere comes in.

Continue reading “Release of CoherentSolutions.Extensions.Configuration.AnyWhere”