Monthly Archives: November 2017

4. C# tip – Always return Task or Task <T> for Async methods

C# offers two key words Async and await to provide simplified asynchronous programming model in .net framework to easily write asynchronous code using concise syntax. It is based on Task based asynchronous pattern. The core of async programming are Task and Task<T> objects, which model asynchronous operations. We can pattern Task based asynchronous code mostly for following two use… Read More »

3. C# tip – Named tuples (C# 7 feature)

C# methods usually a single object or value. To return multiple values, we usually resort to creating a class or use struct to carry multiple elements. Unfortunately, it’s more work to create and maintain those classes which simply exist to return multiple values with no value addition in domain model and obscure class design principles.… Read More »

2. C# tip – Useful ASP.Net classes,utilities providing HTTP request context (Url info)

ASP.Net developers are all too familiar with System.Web namespace. This assembly pretty much holds all of ASP.Net together. While we are interested in understanding incoming HTTP requests thrown at our website or webapp, we spent a lot of time around HttpContext or HttpRequest classes which encapsulate HTTP request raw values into typed object properties giving us… Read More »

1. C# tip – Use is operator and as operator

In C#, type casting is so common and important thing.  C# allows to cast between types in multiple ways. As shown below, simple and most common way to do casting in C# which poor programmers tend to use is direct cast which anyways, ends badly.  Direct cast indicates speculative code. Avoid such vulnerable coding at… Read More »

C# HttpClient utility class for calling Web API

Folks writing C# code for consuming resources from external apis or mostly http systems typically use bunch of networking classes. Especially, there are WebClient, HttpClient HttpWebRequest     These classes, however, there is a good dose of confusion around their usage, when to use and their good and bad parts. We’re not going to get into that… Read More »

ASP.Net MVC Core Action filter sample for parameter validation

Filters have a special place in ASP.Net MVC Framework. Filters are custom classes/middlware that provide declarative and programmatic means to add pre-action and post-action behavior to controller action methods . Filters run in the context of MVC action processing pipeline. ASP.Net MVC supports 4 different types of filters. Authorization filter – deals with authorization logic.… Read More »

ASP.Net Core In-memory cache manager code sample

Caching can significantly improve performance and scalability of an app by making a copy of generated content thereby having to avoid expensive round trips or processing power to generate content. Caching suits best for the data which rarely changes. Caching is a key component of any enterprise distributed applications across the globe for providing optimal… Read More »

Entity Framework Core performance improvement tips

Entity Framework is a popular ORM choice for data access needs in .Net world. It is superior and mature framework. Of course, ORM is an abstraction at the end of day, some times we may feel we are not enough juice out of it when compared with ADO.Net library. There is always a trade off.… Read More »

EF Core Power tools

Prior Incarnations of Entity Frameworks like EF 6, large section of developers enjoyed their Entity Framework Designer tools. However, puritans won. Code first approach, POCO classes took over the EF landscape. Well, POCO approach is well and good. But, EDMX approach a.k.a designer approach was engaging and a good starting point for novice programmers. Well,… Read More »

EF Core 2.0 improvements – LIKE Operator, Query filters

Entity Framework (EF) Core 2.0 comes with some cool nifty features. Improved LINQ translation to optimized SQL queries,  long pending feature request for LIKE LINQ operator is finally fulfilled. Other interesting feature is setting up Global Query filters which essentially allow you to set up global WHERE function at DbContext level and C# string interpolation… Read More »