Paramore Brighter: DRY with Custom Decorated Command Handlers

The Blog of Colin Angus Mackay

You may wish to add similar functionality to many (or all) command handlers. The typical example is logging. You can decorate a command handler in a similar way to the policies I showed in previous posts to add common functionality. I’ve used this technique to guard the handler from invalid command arguments/parameters (essentially a validator), and for ensuring that we ping our APM (Application Performance Management) tool when a command completes. I’ll use the latter to demonstrate creating a custom decorator and handler to initiate this common code.

Paramore Brighter Command Processor will look for any attributes derived from RequestHandlerAttribute that are added to the Handle method on your command handler class. It will then use them to build a pipeline for your command.

So, in the example here, our attribute class looks like this:

 public class HeartbeatAttribute : RequestHandlerAttribute { public HeartbeatAttribute(int step, HandlerTiming timing = HandlerTiming.After) : base(step…

View original post 413 more words


Implementing Simple Neural Network in C#

Rubik's Code

Code that accompanies this article can be downloaded here.

Sometime in the last few weeks, while I was writing the explanations for the way in which neural networks learn and backpropagation algorithmI realized how I never tried to implement these algorithms in one of the programming languages. Then it struck me that I’ve never tried to implement the whole Artificial Neural Network from scratch. I was always using some libraries that were hiding that implementation from me so I could focus on the mathematical model and the problem I was trying to solve. One thing led to another and the decision to implement my own Neural Network from scratch without using third-party libraries was made. Also, I decided to use object-oriented programming language I prefer – C#.

This means that a more OO approach was taken and not the usual scripting point of view like we would have by…

View original post 1,725 more words

Serverless .Net Core(2.0) application with AWS Lambda: Step by step guide

Neel Bhatt

aws15Note – You can find the source code of my sample application here.

Amazon has recently announced the .NET Core 2.0 AWS Lambda runtime.

In this post, we will see how to create Server less .Net Core 2.0 application using AWS Lambda.

Let us first see what is Serverless computing?

  • Serverless computing allows you to build and run applications and services without thinking about servers
  • Serverless applications don’t require you to provision, scale, and manage any servers
  • You can build them for nearly any type of application or backend service, and everything required to run and scale your application with high availability is handled for you
  • Building serverless applications means that your developers can focus on their core product instead of worrying about managing and operating servers or runtimes, either in the cloud or on-premises.

Let us start Step by step guide.


View original post 466 more words

Best practices on Rest API client in Dotnet ecosystem

Howdy Readers,

Today I’m going to write something about HttpClient inspired by ASP.NET community standup. The popularities of microservices and REST API’s are on it’s highest peak. Which makes us using HttpClient the most. While you are calling rest API using HttpClient, you need to be aware of few most important things.

  1. Do not create a new instance of HttpClient class for each request. Creating new object will create two problems.
    • Each time the new connection will create a new connection pool for each request and it is a very costly operation as it includes 3-way handshake(HTTP) or even costlier TLS handshake(HTTPS)
    • The second issue with this is it may lead to socket exhaustion because in whichever operating system environment you are in, you have limited sockets. You may think that you will dispose the object of HTTP client and you might not have parallel users equivalent to no of sockets(64K) but there is a catch here. Once you dispose of the object, socket does not get freed up immediately. The different operating system takes the different amount of time to free up the sockets(say 3-5 seconds). Hence this may lead you to reach handle limit.
  2.  Do not create a single instance(static or singleton) of HttpClient. If you read the point one, you may conclude on creating the single instance of HttpClient because of it is thread-safe. This is said to be a more efficient way of creating HttpClient but it also has a serious issue. It will keep the connection open for a very long time. This has issue like
    • It may lead to not respecting load balancing. What I mean by this is if your connection is opened with server X then all requests from your application will go to the same server and other servers might be in idle state. This may be a big problem when you are one of the highest load generator client of that API.
    • The bigger problem comes when API uses things like Online-Offline (Blue-Green) deployment. On the toggle of API, Open connection with server keeps sending a request to it although it might have become an offline server.
    • You might have some default header which you might not want to share between different clients.

This Leads to a conclusion that keeping either single or transient connection can cause many issues. It is always recommended to create connections smartly, some of the examples might be to create client per request kind and also keep refreshing the connection over a period of time. There can be many such solutions but use it smartly according to your need.

Image detection bot using Microsoft Vision API : Step by step guide

Neel Bhatt

bot9Note – You can find the source code of my sample application here.

In my previous post about Bots, I have explained how to use FormFlow to create attractive selection box in bots which you can find here.

In this post, I will explain how to create Image detection bot using Microsoft Vision API.

Let us see how to create Image detection Bot application using Visual Studio 2017.


Also if you want to have Bot Application as a template then as a workaround just download this  (download would start once you click on the link) project and put the extracted folder into below location:

C:UsersYourNameDocumentsVisual Studio 2015TemplatesProjectTemplatesVisual C#

Once this is done, you can see Bot Application template as shown below:

bot1Click on Bot Application and then it will create a sample project…

View original post 1,130 more words

Terraform, VPC, and why you want a tfstate file per env

Hey kids!  If you’ve been following along at home, you may have seen my earlier posts on getting started with terraform and figuring out what AWS network topology to use.  You can think of this one as like if those two posts got drunk and hooked up and had a bastard hell child.

Some context: our terraform config had been pretty stable for a few weeks.  After I got it set up, I hardly ever needed to touch it.  This was an explicit goal of mine.  (I have strong feelings about delegation of authority and not using your orchestration layer for configuration, but that’s for another day.)

And then one day I decided to test drive Aurora in staging, and everything exploded.

Trigger warning: rants and scary stories about computers ahead.  The first half of this is basically a post mortem, plus some tips I learned about debugging terraform outages.  The second half is about why you should…

View original post 2,162 more words

Optimizing Identity Tokens for size

Generally speaking, you want to keep your (identity) tokens small. They often need to be transferred via length constrained transport mechanisms – especially the browser URL which might have limitations (e.g. 2 KB in IE). You also need to somehow store the identity token for the length of a session if you want to use the post logout redirect feature at logout time.

Therefore the OpenID Connect specification suggests the following (in section 5.4):

The Claims requested by the profile, email, address, and phone scope values are returned from the UserInfo Endpoint, as described in Section 5.3.2, when a response_type value is used that results in an Access Token being issued. However, when no Access Token is issued (which is the case for the response_type value id_token), the resulting Claims are returned in the ID Token.

IOW – if only an identity token is requested, put all claims into the token. If however…

View original post 210 more words