Skip to content

Quick Dev Notes Posts

Setup a virtual environment for Python Development on Windows

Introduction Earlier, I wrote an article on how to set up a virtual environment for Python development on Ubuntu. This article, as the title suggests, focuses on setting up a virtual environment on Windows. I’m using Windows 8, and everything we will do here should work on other versions of Windows as well.   Installing and Running Python Installing Python, or any other software, for…

Setup a virtual environment for Python Development on Ubuntu

Introduction In this article, we will start off by installing Python 3.6 and later, we will set up various virtual environments to work on different projects that require different versions of Python (say 2.7 and 3.6). Just for a change (honestly, I’m bored working on Windows), I will be doing everything on a system running Ubuntu 16.04. If you are interested to install Ubuntu alongside…

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 to do the same over and over again. In this article, we will use a different…

Using HttpContext outside a Controller in .Net Core 2.1

  Introduction Last Friday, while working on a web application based on ASP.Net Core 2.1, I came across a scenario where I had to put some data into memory. While that’s not a problem, the catch is that the data has to be unique for each Http Session. Consider it as keeping a key that is to be used across different views to display some…

Breaking Circular Dependency between Components

Introduction Couple of days ago, I came across a piece of code that was not just tightly coupled but also formed a circular dependency among the components. In the following code, I’ve tried to give you a gist of it (may not be the best though). The below code has two key components, DataProvider and DataValidator. The DataProvider “new” DataValidator and passes in its own instance, which is then used…

Introduction to Software Design Patterns

Ever since software engineering has come to life, software engineers have repeatedly faced situations wherein they have to solve similar problems over and over again. And being a software engineer I can tell you that it is very annoying. So, what can we do about it? How do we solve our similar software problems? Well, the answer to these questions is, by using Software Design…

Composed Relationship Types Func<Owned<T>>

We often end up in situations where injecting a service using simple relationship types like Func<T>, Lazy<T>, Owned<T> and others, doesn’t serve the purpose. For instance, there can be a scenario where we want to control the lifetime of a component and yet the initialization of the component takes place at run time. Now, for such a scenario, injecting the service as either Func<T> or…

Func <T> – Dynamic Instantiation

Think of a scenario where we want more than one instance of a given service, or the decision, whether to instantiate a component is made at run time. For such scenarios injecting a service as a Direct or Lazy dependency will not be enough. However, injecting the service dependency as a Func do.   Using Func <T> Consider the following example, where we have a PaymentProcessor…

Owned<T> – Controlled Lifetime with Autofac

In general, Autofac controls the lifetime of components. It automatically disposes off all the disposable components at the end of lifetime scope. However, that may mean a component is held onto for too long. Generally speaking, an owned dependency corresponds to some unit of work performed by the dependent component.   Releasing an Owned<T> We use an owned dependency when we want to control the disposal…