Simple way to understand or explain dependency injection

Recently, I have been trying to learn about anjular.js and mean while i am reading this tutorial (!/lessons/a-simple-app) i saw a great answer about describing what is dependency injection. This was the great and simple answer i have ever read. Some one has asked

How to explain dependency injection to a 5-year old?

and simple answer given by John Munsch was

When you go and get things out of the refrigerator for yourself, you can cause problems. You might leave the door open, you might get something Mommy or Daddy doesn’t want you to have. You might even be looking for something we don’t even have or which has expired.

What you should be doing is stating a need, “I need something to drink with lunch,” and then we will make sure you have something when you sit down to eat.

Wow that is great answer isn’t it?

What is jsPlumb

jsPlumb is a data visualization library available for most popular JavaScript libraries like jQuery, MooTools,Vanilla JS, YUI3. There are lot of features available on jsPlumb and has lots of examples over internet and they have a good documentation.

jsPlumb provides a means for a developer to visually connect elements on their web pages. It uses SVG or Canvas in modern browsers, and VML on IE 8 and below. The latest version is 1.6.4.


The project started out life on Google Code and was hosted there up until April 30, 2013. From May 1st, 2013, jsPlumb lives on GitHub only.


If you’re new to jsPlumb, please do take the time to read the documentation. There are a few integration issues that you should be aware of: z-index needs special attention, for example.

You can find running demos in here ( and licensed under the MIT license.

Browser Compatibility

jsPlumb runs on everything from IE6 up. There are some caveats, though, because of various browser/library bugs:

  • jQuery 1.6.x and 1.7.x have a bug in their SVG implementation for IE9 that causes hover events to not get fired.
  • jQuery 2.0 does not support IE 6,7 or 8.
  • Safari 5.1 has an SVG bug that prevents mouse events from being passed through the transparent area of an SVG element (Safari 6.x does not seem to have the same problem)
  • MooTools has a bug when using SVG in Firefox 11


Go ahead and try this awesome library for one of your projects





Develop high quality software using NDepend

I just tried this tool and it looks pretty powerful, I still have to dig further in it.It has lots of features like

  • Code Rule and Code Query over LINQ (CQLinq)
  • Trend Monitoring
  • Harness Test Coverage Data
  • Code Quality, 82 Code Metrics
  • Explore Existing Architecture
  • Detect Dependency Cycles
  • Compare Builds and Code Diff
  • Compare Builds and Code Diff
  • Complexity and Diagrams
  • Continuous Integration Reporting
  • Warnings on Build Process Health
  • NDepend.API and Power Tools
  • Real-World Proof

If you are really interested to increase the quality of your product, you better to try this tool. NDepend offers a wide range of features to let the user analyze a code base.
It is often described as a Swiss Army Knife for .NET developers.


Reveal js

Reveal js is very good framework for build web based presentations. It is very pretty and works in most of popular applications. It has lot of features like you don’t want any programming skills to design the presentation. The site says

reveal.js is a framework for easily creating beautiful presentations using HTML. You’ll need a browser with support for CSS 3D transforms to see it in its full glory.

Slides can be nested inside of other slides and there is a zoom feature also in the framework. It support themes and background colors. Go to Reveal js website

Green Budget – An android application to track your budget

Hi all… I am planning to create a new free and open source android application called it “Green Budget”. Here i have provided sample user interfaces and i like to gain your suggestions about these interfaces. Based on that i can modify these colors and interfaces. This project already available on GitHub and if you want to download this application with source codes you can see on here. Application is still on the initial step and only the UI is being implemented by myself.

How to insert data into MySQL using PHP (Ajax)

Here i have provided a simple example for beginners to understand how to insert values into MySQL database using PHP. Here i have used NetBeans IDE for develop my simple application. Project structure looks like below.


In here i have categorized my modules display as below and

1) Data Access Layer used to access the data base

2) Common layer for keep commonly execute methods

3) DB to store connection class and any other related classes

4) JS for keep java script files

I am going to store employee data in a MySQL database and i will use ajax to send data into database without refreshing the page and get response message and display in a label. My user interface looks like below


Here i am going to explain important parts of the source code and you can download the project and view the source later. Here is my employee class.

 -- Author : damith
 -- Date :March-16-2013


require 'db/Connection.php';
require_once 'common/Messages.php';
$connection =  new createConnection();
$response =  array();

class EmployeeDetals
     * @global createConnection $connection
     * @param type $firstName
     * @param type $lastName
     * @param type $age
     * @return type
    public function addNewEmployee($firstName,$lastName,$age)
        global $connection;

        try {
            $insertQuery = "INSERT INTO emp_personal_details(emp_personal_details.First_Name,emp_personal_details.Last_Name,emp_personal_details.Age) VALUES ('$firstName','$lastName','$age')";
            $availableQuery ="SELECT * FROM emp_personal_details e WHERE e.First_Name='$firstName' AND e.Last_Name='$lastName' AND e.Age='$age'";
            $availableResult= mysql_query($availableQuery);

        if(mysql_num_rows($availableResult)>0){ // checking wether records are already available inthe sysyem
                $response[0] = $firstName.' alredy registered in the system';
                $response[1]= Message::Warning;
                if (!mysql_query($insertQuery)){
                    $response[0]= 'Error occured while inserting data';
                    $response[1]= Message::Error;
                    $connection->closeConnection(); // closing the connection
                    $response[0]= 'Successfully added to the database';
                    $response[1]= Message::Success;
                    $connection->closeConnection(); // closing the connection

            return $response;
        } catch (Exception $exc) {
                    $response[0]= $exc->getTraceAsString();
                    $response[1]= Message::Error;
                    $connection->closeConnection(); // closing the connection
                    return $response;



And my user interface with JavaScript function looks like below

        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script src="js/jquery-1.9.1.min.js" type="text/javascript"></script>
        <form action="" name="frmAddEmp" id="frmAddEmp">
                    <td>First Name</td>
                    <td><input type="text" name="txtFirstName" /> </td>
                    <td>Last Name</td>
                    <td><input type="text" name="txtLastName" /> </td>
                    <td><input type="text" name="txtAge" /> </td>
                    <td><input type="button" name="btnSubmit" value="Save" id="btnSubmit" /> </td>

        <div id="response">

    <script type="text/javascript">
        $("#btnSubmit").click(function() {
            var url = "addEmployee.php"; // the script where you handle the form input.
                   type: "POST",
                   url: url,
                   data: $("#frmAddEmp").serialize(), // serializes the form's elements.
                   success: function(data)
                       $('#response').append(data); // show response from the php script.

        return false; // avoid to execute the actual submit of the form.

and this is the page which call from the interface using ajax and retrieve the result.

 -- Author : damith
 -- Date :March-16-2013


require 'DAL/EmployeeData.php';

$response =  array();
$emp = new EmployeeDetals();

    if(isset($_REQUEST['txtFirstName']) && isset($_REQUEST['txtLastName']) && isset($_REQUEST['txtAge'])){

        $firstName = mysql_real_escape_string($_REQUEST['txtFirstName']);
        $lastName = mysql_real_escape_string($_REQUEST['txtLastName']);
        $age = mysql_real_escape_string($_REQUEST['txtAge']);

        $response = $emp->addNewEmployee($firstName, $lastName,$age);
        echo $response[0];


If the user enter same values again application will prevent the save duplicate values. Overall process of the application has illustrated as below.


1)  User Interface – This file has the user interface code of the application and also java script function which used to post the form data into second layer.

2) Second layer can be used to catch data sent from the User Interface and pass to the third layer.

3) Third layer or the DAL (Data Access Layer) is only the layer which contract with the connection class and the database. All the required queries are wrote in here.

4) Database and the connection class.

This is the basic way to develop application with well managed way. Hope it clear to you. You can download the complete project below with database script.