Posts

Showing posts from 2017

Building Microservices with Asp.Net WebAPI, Owin, Ninject, NHibernate, and Azure

Image
We’ve been building microservices here for a while, so I thought I’d share how we do it. I’ll try to cover the basics of how we implement all our services without getting too complex. I’ll provide a high-level overview of the basic components that lay the foundation for our services and share some code snip-its. The goal is to provide you with a simple foundation to build your own microservices framework strategy upon. What’s a Microservice? There are a lot of opinions on the matter. When I use the term microservice in this article, I’m referring to a service that is independently deployable and encapsulates a single bounded context. Though the techniques in this article could be applied to any service, even large monoliths. Core Technology Stack Even though the benefit of microservices is “use what every you want”, we found that having a standard set of tools in the tool box keep our lives simple and allow us to produce services more quickly. If your shop does give developers...

The Async/Void Trap

Image
Example Code I’ll start by saying, you should ALWAYS avoid async/void. Now, I’m sure there are edge cases, but the reality is you can get into a lot of trouble with async/void. A good  article in MSDN Magazine  goes over some best practices when using async/await and asynchronous programming patterns. As the article points out, avoid async/void. However, it also states that an exception to that rule is event handlers where the delegate returns void. Even with those event handlers, you need to be extremely careful. Here’s why–await is actually not blocking. I know if feels like it is, but remember, async/await is just syntax sugar for ContinueWith() and context management. Let’s look at some code. Take some method Foo() that returns void and calls an async method Bar() async void Foo () { await Bar (); } Task Bar () { return Task . Delay ( 10000 ); } Now, if we call Foo(), it will return immediately, and Bar() will be executed in backgrou...