Skip to content

Author: Gaurav Gahlot

Dependency Injection – without DI Container

Now that we have the answer to our question, why loosely coupled code?, let’s try and solve the problems we found in a tightly coupled application. In this post, we will use constructor based dependency injection, however, we are not going to use any DI container for now.   Dependency Injection Dependency Injection (DI) is a technique that helps us achieve loose coupling between objects and…

Implicit vs Explicit Dependencies

If our class depends upon other classes to complete its operations, then these other classes are dependencies for our class. Our class can have these dependencies as implicit or explicit dependencies. What does this mean? What effect does it have on our application design? Let’s try to find answers to these questions.   Implicit Dependencies The dependencies are implicit for a class, if they exist only in the code within…

5 Reasons to write Loosely Coupled code

In the last post, we analyzed a tightly coupled application and listed out the problems we found with the same. In this post, we will explore, how writing loosely coupled code helps us keeping our applications easy to write, test and maintain.   Introduction A loosely coupled application has good isolation among its classes, modules and assemblies. Therefore, if we make a change to one part…

Pre/Post Build Events in Visual Studio

Introduction Pre/Post Build Events are useful when we wish to perform some operation before/after a project is build. These operations are nothing but the shell commands being used from the command line. Consider a scenario where we build our library project and its .dll is saved into the Project/bin/Release directory. For some reason we want all our library files in one common directory that we would refer…

Analyzing a Tightly Coupled Application

Dependency injection is a vast topic in itself. However, it is difficult to find everything we should know about it in one place. And so, I thought of creating my own series of learning about topic. In this part of the series we will look into a tightly coupled application and the problems related to it.   Introduction An application is said to be tightly…

Null Object Pattern

Almost every method that we write, irrespective of the programming language, we always have checks like the following one: if (objectVariable == null) return; // do some work with objectVariable 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 code look ugly and hard…

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.   Creating an Anonymous Type We can create an anonymous type using a new keyword along…

Entity Vs Model Vs ViewModel Vs DataModel

Different people define Entity, Model, ViewModel and DataModel in different ways. However, these terms may sometimes differ from their actual meaning, based upon the context. In this post I would like to share my understanding of these terms.   Entity An entity is the tabular representation of your domain class/object in the database and has an identity. In fact, an entity represents a single instance…

Understanding Relationship Between Objects

Introduction The relationship between objects defines how these objects will interact or collaborate to perform an operation in an application. In any application, objects of user interface classes interact with the business layer objects in order to perform an operation. And in the background, the business layer objects may interact with objects of some repository which in turn talks to some data source object or…