.Net Core

A better approach to use HttpContext outside a Controller in .Net Core 2.1

Introduction In my previous post we discussed an approach to access the HttpContext.Session in RequestHandler. However, there was a problem. For every single component where we need to access the session, we have to inject a dependency of IHttpContextAccessor. While for one or two components it’s not a problem, it can be very daunting if we have Read more…

By Gaurav Gahlot, ago
.Net Core

Null Object Pattern

Almost every method that we write, irrespective of the programming language, we always have checks like the following one: [crayon-5c685202f08d4578559135/] We end up adding so many null checks in our methods, that it gets almost hard to figure out what we are supposed to do in our method. This makes our Read more…

By Gaurav Gahlot, ago
.Net Core

Anonymous Types in C#

Generally, for an object to encapsulate some properties, the type of the object has to be defined first. On the contrary, anonymous types provide a convenient way for an object to encapsulate readonly properties without explicitly defining the type first. The type of each property is deduced by the compiler. Read more…

By Gaurav Gahlot, ago