Month: July 2012

Building your own IOC container – Part1

This article is about to get a good understanding of how an IOC containers works. In real life you don’t have to create IOC containers by yourself as there are many frameworks that can be used, such as Unity, Castle Windsor, Ninject etc. But as a developer understanding the mechanics of this is important.
First we’ll have a look at what is as IOC container is and how it can resolve dependencies. As an example I will be demonstrating the constructor injection.
In basic terms we can think of an IOC container as a framework for implementing dependency injection. This is the fundamental purpose of the IOC container. Apart from that it can manage the lifetime of an object, but here our focus is on the primary feature, i.e. to do the Dependency Injection automatically once we configured it. In the configuration you configure the dependencies so if you have an interface and when you ask for it the configuration will resolve it to the particular concrete type. Also you can use this concrete type to resolve to another type down the class hierarchy. The key concept here is you set up the dependencies and the container will automatically resolve it for you.
So if you ask for IPerson interface and the IOC container will resolve it to an Employee or Student concrete types. In this case any of the scenarios doesn’t know about the dependencies, only the IOC container knows about the dependencies.
Following is a high level visualisation of the implementation of the IOC container.


Hard delete or soft delete?

I have been working on some R&D work and came accross to delete records from the database. So I’ve been thinking that whether to do a soft delete or to do a hard delete. What do you think?
In my point of view, it all depends on the end user requirements. If the transactions are used in pattern analysis by the top management and especially in decision support systems, I think the soft delete would be appropriate. I’m sure that you all know what is meant by soft delete. In simplest of terms it is just using state variable to. When the user selects a record and confirms to delete the record will not get deleted from the database, but a deletion state will be changed to record and other related data appropriately.
But using a soft delete can also cause you more space, because you are keeping all the historical data. For that you could use a separate mechanism for archiving, for example a flat data structure which may use a trigger in the source entity and write the important data related to the transactions to the flat table. After that you can perform a hard delete by using a service or a daily SQL server job to clean up the data in your database with the specific deletion status.
As I mentioned earlier, there are other factors affecting this decision, such as business domain requirements, hardware such as storage and software requirements, cost, etc. Based on these conditions you could provide a better solution. In my case I thought of going with the soft delete and archive important data to a flat table. In this solution I have added an additional column to all tables in the database called “Deletion State”. After that to use a daily SQL Server job to clean up the data with the deletion status equals to an appropriate value.

Published via wordpress mobile

Asynchronous Programming model in .NET

I thought of writing this article because I used to be so frightened when I hear the word asynchronous programming because it’s too complicated. But I faced an issue during my recent development work where I had to write an application to listen to Twitter via GNIP web API. After getting some sample code and going through the API, I managed to get the application running. But the problem came when I was testing it. The requirement was to get the tweets send to our private stream and display on our side for further processing.
But when I start the application and send a tweet, it doesn’t display anything although the application is connected and listening to the stream. When the second message is sent to the app it displays the tweet, but unfortunately not the current message, but the first one.
For example when I tweet the message @SomeTweetHandle My test message 10001, the message didn’t appear on my screen. When I send the second message @SomeTweetHandle My Test message 10002, the @SomeTweetHandle My test message 10001 appeared. So when ever I send a message it always returned me the previous message I sent. This was not ideal to the requirement that I had.
So after doing some R&D I finally end up in .NET Asynchronous programming model, which indeed helped me to solve my issues. I used the following article as a resource for solving my problem.
Now my application is responding to the latest messages that I send to the stream. Also I ran the application continuously for longer hours, at one instance for 3 hours and the other was about 5 hours, and the connection stays on for all these time, which is great. The application is responding properly and all went good.
Next big challenge was put to me by my product owner to check the connectivity status and keep the stream listener alive. And above all the exception handling is not straight forward as the processes are executing in different threads. I’ll write more about it on my next article.


This article is for the developers who worship I used to be one of that group. But thanks to my current employer, I had a chance to look into as well after my academic years.
Initially I was in the impression that I would never go back to I was more of a java and C++ guy and I virtually hated the syntax. Having a good knowledge in java and C++ helped me ro learn c# very easily.
For me was not like a programing language but more like writing a paragraph.
It doesn’t have the cool syntax like c# or java. But with the requirements that I had recently and when I explore the language more, it became eaqually interesting as with the other languages. But I still don’t like the syntax though, what I felt was, you should know as well because you are a.Net developer.
Besides when you possess the knowledge of many different programming languages, you will be a better developer.

Uploaded from WordPress mobile.