Service Fabric - Https and Http

There are several good resources to set up Service Fabric Https endpoints. I would reference here HTTP & HTTPS in Service Fabric Web API which describes all the necessary steps to set up Http and Https endpoints. Doing the work manually will result pretty similar, except for the last step, which can trick the usual developer:

new ServiceInstanceListener(serviceContext =>
new OwinCommunicationListener(Startup.ConfigureApp, serviceContext, ServiceEventSource.Current, endpoint));

When you add one ServiceInstanceListener (Http or Https) the endpoint will open, but adding multiple, the code above will fail to open any endpoints.

The key step here is an optional parameter in the constructor of ServiceInstanceListener. Unless the name specified we will not be able to open multiple endpoints. So one suggestion to correct the above code:

Find out more


Reading list

I have read a couple of books over the last years. Let me collect some of the books I liked the most:

  • CLR via C#, By: Jeffrey Richter

  • Algorithms in a Nutshell, By: George T. Heineman; Gary Pollice; Stanley Selkow

  • Clean Code, By: Robert C. Martin

  • The Clean Coder, By: Robert C. Martin

  • Dependency Injection in .NET, By: Mark Seemann

  • The Art of Unit Testing, By: Roy Osherove

  • Angular 2 Development with TypeScript, By: Yakov Fain and Anton Moiseev

Find out more


SingleOrDefault - Safe

On the other day I ran into a task to return the only one element of a list/enumeration if exists, and I had to do it in a performant way. The list or enumeration could have any number of not null items. Using FirstOrDefault is not an option as it does not restrict having multiple items in the list. SingleOrDefault could be a choice, but it throws an exception in the case of multiple items. Handling the exception was not an option.

One solution could be to call Count and only return the first item if the value is one. The problem with this solutions is enumerating through the items to get the count for enumerable types. A better solution is to write a new SingleOrDefault extension methods to handle list and enumeration types.

Implementation

The following method is an extension of IEnumerable<T>

Find out more