<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>IOC</title>
        <link>http://geekswithblogs.net/rajeshpillai/category/10978.aspx</link>
        <description>IOC</description>
        <language>en-US</language>
        <copyright>Rajesh Pillai</copyright>
        <managingEditor>thinkrajesh@yahoo.com</managingEditor>
        <generator>Subtext Version 0.0.0.0</generator>
        <item>
            <title>Tech Mastery : Dependency Injection and IOC</title>
            <link>http://geekswithblogs.net/rajeshpillai/archive/2009/11/28/techmastdi.aspx</link>
            <description>&lt;p class="MsoNormal"&gt;&lt;span style="background-color: rgb(255, 255, 255);"&gt;&lt;span style="background: yellow none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; color: rgb(31, 73, 125);"&gt;Just to give  you a background to all those who newly following this post,we  will be publishing materials of this kind every week to gain some &lt;br /&gt;
insight into  upcoming technologies, to understand current technology better, to know more  about the latest development processes, best practices, build up &lt;br /&gt;
foundational  skills, RIA, certifications etc. etc.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="background-color: rgb(255, 255, 255);"&gt;&lt;span style="background: yellow none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; color: rgb(31, 73, 125);"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="background-color: rgb(255, 255, 255);"&gt;&lt;span style="background: yellow none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; color: rgb(31, 73, 125);"&gt;The intent  is very clear.   To get out of the routine work mode and build something for  ourselves, because the more the stronger we become in these said &lt;br /&gt;
areas the  better it is for our work.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;span style="color: rgb(31, 73, 125);"&gt;Let’s come to the point.   Today’s topic is &lt;/span&gt;&lt;span style="color: rgb(31, 73, 125); font-size: 16pt;"&gt;“Dependency Injection and  IOC”.&lt;/span&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;u&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;PREREQUSITE FOR THIS MATERIAL  :  The SOLID principle (Refer my earlier mail)&lt;/span&gt;&lt;/u&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;We all have come across this  term “Dependency Injection” at one point or other in our work life.  Let us all  try to nail it down.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;“Dependency Injection (DI)”  refers to the process of supplying an external dependency to a software  component.  It is a specific form of inversion of control (IOC) &lt;br /&gt;
where there  concern being inverted is the process of obtaining the needed dependency.  The  term was first coined by Martin Fowler to clearly describe the  mechanism.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="color: rgb(31, 73, 125);"&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;Wiki URL : &lt;a target="_blank" href="/exchweb/bin/redir.asp?URL=http://en.wikipedia.org/wiki/Dependency_injection"&gt;http://en.wikipedia.org/wiki/Dependency_injection&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;b&gt;&lt;u&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;NOTE: &lt;/span&gt;&lt;/u&gt;&lt;/b&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;i&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;“ IOC is a key part of what  makes a framework different from a library.  A library is essentially a set of  functions that you can call, these days usually organized &lt;br /&gt;
into classes.  Each  call does some work and returns control to the client.  &lt;/span&gt;&lt;/i&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;i&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/i&gt;&lt;i&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;A framework embodies some  abstract design, with more behavior built in.  In order to use it you need to  insert your behavior into various places in the framework &lt;br /&gt;
either by subclassing  or by plugging in your own classes.  The framework’s code then calls your code  at these points.  “&lt;/span&gt;&lt;/i&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="color: red;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;IOC is based on the “Hollywood  Principle”, “Do not call us, we will call you”.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;Two important principles of  IOC&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoListParagraph" style="text-indent: -0.25in;"&gt;&lt;span style="font-family: Symbol; color: rgb(31, 73, 125);"&gt;&lt;span&gt;·&lt;span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;"&gt;         &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;High level classes should not depend on the direct  implementation of low level classes or aggregated classes.  Both the classes  should depend on abstraction.  &lt;span style="background: yellow none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"&gt;&lt;br /&gt;
Remember the  SOLID (D – Dependency Inversion Principle)&lt;/span&gt;.  So, the Project class should  not depend directly on the Employee class.  Both should depend on a &lt;br /&gt;
abstraction  either using interface or abstract class.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoListParagraph" style="text-indent: -0.25in;"&gt;&lt;span style="font-family: Symbol; color: rgb(31, 73, 125);"&gt;&lt;span&gt;·&lt;span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;"&gt;         &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;Abstraction should not depend on details, details should  depend on abstraction.&lt;/span&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;Ok, let’s move on.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;First,  &lt;span style="background: yellow none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"&gt;“Every Solution needs a problem”.&lt;/span&gt;  Does this  statement rings in your ear?   So, what problems  are solved by Dependency  Injection?&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="color: rgb(31, 73, 125);"&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoListParagraph" style="text-indent: -0.25in;"&gt;&lt;span style="font-family: Symbol; color: rgb(31, 73, 125);"&gt;&lt;span&gt;·&lt;span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;"&gt;          &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;It makes your application truly loosely  coupled.&lt;/span&gt;&lt;span style="font-family: Symbol; color: rgb(31, 73, 125);"&gt;&lt;span&gt;·&lt;span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;"&gt;         &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;&lt;br /&gt;
It provides a way to extend your application (you can  inject your dependencies based on some configuration).&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Symbol; color: rgb(31, 73, 125);"&gt;&lt;span&gt;&lt;span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;It enable you to unit test your code (as you can easily  inject fake dependencies to test your core logic).&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoListParagraph" style="text-indent: -0.25in;"&gt;&lt;span style="font-family: Symbol; color: rgb(31, 73, 125);"&gt;&lt;span&gt;·&lt;span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;"&gt;         &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;It removes the rigidity out of your  application.&lt;/span&gt;&lt;span style="color: rgb(31, 73, 125);"&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;Take this example&lt;/span&gt;&lt;span style="color: rgb(31, 73, 125);"&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-family: Consolas; color: red; font-size: 10pt;"&gt;     &lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span style="font-family: Consolas; color: rgb(0, 176, 80); font-size: 10pt;"&gt;public class  Employee&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style="font-family: Consolas; color: rgb(0, 176, 80); font-size: 10pt;"&gt;     {&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style="font-family: Consolas; color: rgb(0, 176, 80); font-size: 10pt;"&gt;        public  Employee()&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style="font-family: Consolas; color: rgb(0, 176, 80); font-size: 10pt;"&gt;         {&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-family: Consolas; color: rgb(0, 176, 80); font-size: 10pt;"&gt;         }&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style="font-family: Consolas; color: rgb(0, 176, 80); font-size: 10pt;"&gt;     }&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-family: Consolas; color: rgb(0, 176, 80); font-size: 10pt;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span style="font-family: Consolas; color: rgb(0, 176, 80); font-size: 10pt;"&gt;    public class  Project&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style="font-family: Consolas; color: rgb(0, 176, 80); font-size: 10pt;"&gt;     {&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style="font-family: Consolas; color: rgb(0, 176, 80); font-size: 10pt;"&gt;        private  Employee _emp;   &lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style="font-family: Consolas; color: rgb(0, 176, 80); font-size: 10pt;"&gt;        public  Project()&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style="font-family: Consolas; color: rgb(0, 176, 80); font-size: 10pt;"&gt;         {&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style="font-family: Consolas; color: rgb(0, 176, 80); font-size: 10pt;"&gt;            _emp  = new Employee();       // 1. Aware of concrete classes.&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style="font-family: Consolas; color: rgb(0, 176, 80); font-size: 10pt;"&gt;         }&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style="font-family: Consolas; color: rgb(0, 176, 80); font-size: 10pt;"&gt;     }&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;The main problem with the above  class structure is that it is aware of its dependencies.  This awareness may  limit this object from being extensible.  We &lt;br /&gt;
have taken a rudimentary example  here as our main intent is to understand the DI/IOC.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;Have a look at this modified  classes.&lt;/span&gt;&lt;span style="color: rgb(31, 73, 125);"&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="color: rgb(0, 176, 80);"&gt;    public interface IEmployee {  };&lt;/span&gt;&lt;span style="color: rgb(0, 176, 80);"&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="color: rgb(0, 176, 80);"&gt;    public class Employee :  IEmployee&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(0, 176, 80);"&gt;    {&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(0, 176, 80);"&gt;        public  Employee()&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(0, 176, 80);"&gt;        {&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(0, 176, 80);"&gt;        }&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(0, 176, 80);"&gt;    }&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="color: rgb(0, 176, 80);"&gt;    public class  Project&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(0, 176, 80);"&gt;    {&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(0, 176, 80);"&gt;        private IEmployee  _emp;   &lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(0, 176, 80);"&gt;        public  Project()&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(0, 176, 80);"&gt;        {&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(0, 176, 80);"&gt;            this._emp = new  Employee();  // we still have a problem here as we are directly ref. concrete  object.&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(0, 176, 80);"&gt;        }&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(0, 176, 80);"&gt;    }&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;The dependencies to concrete  object Employee is now removed but the construction of Employee is still  directly done.  Now this construction has to be moved &lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(31, 73, 125);"&gt;away from project class  and has to be injected externally.&lt;/span&gt;&lt;span style="color: rgb(31, 73, 125);"&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;u&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;There are four ways to inject  this dependency, which is outlined below:&lt;/span&gt;&lt;/u&gt;&lt;/p&gt;
&lt;p class="MsoListParagraph" style="text-indent: -0.25in; margin-bottom: 12pt; margin-left: 0.75in; margin-right: 0in;"&gt;&lt;span style="font-family: Symbol; color: red; font-size: 10pt;"&gt;&lt;span&gt;·&lt;span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;"&gt;         &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;u&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;Constructor way&lt;/span&gt;&lt;/u&gt;&lt;/i&gt;&lt;/b&gt;&lt;/p&gt;
&lt;p class="MsoListParagraph" style="margin-bottom: 12pt; margin-left: 0.75in; margin-right: 0in;"&gt;&lt;u&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;The framework  code&lt;/span&gt;&lt;/u&gt;&lt;/p&gt;
&lt;p class="MsoListParagraph" style="margin-left: 0.75in;"&gt;&lt;span style="font-family: Consolas; color: rgb(0, 176, 80); font-size: 10pt;"&gt;private IEmployee  _emp;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoListParagraph" style="margin-left: 0.75in;"&gt;&lt;span style="font-family: Consolas; color: rgb(0, 176, 80); font-size: 10pt;"&gt;public  Project(IEmployee emp)&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Consolas; color: rgb(0, 176, 80); font-size: 10pt;"&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Consolas; color: rgb(0, 176, 80); font-size: 10pt;"&gt;    this._emp =  emp;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Consolas; color: rgb(0, 176, 80); font-size: 10pt;"&gt;}&lt;span style="background: black none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"&gt;    &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoListParagraph" style="margin-left: 0.75in;"&gt;&lt;u&gt;&lt;span style="color: rgb(0, 176, 80);"&gt;&lt;span style="text-decoration: none;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/u&gt;&lt;u&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;The client code&lt;br /&gt;
&lt;/span&gt;&lt;/u&gt;&lt;span style="color: rgb(0, 176, 80);"&gt;public class Client&lt;br /&gt;
&lt;/span&gt;&lt;span style="color: rgb(0, 176, 80);"&gt; {&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(0, 176, 80);"&gt;        Project proj = new Project(new  Employee());&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(0, 176, 80);"&gt;}&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoListParagraph" style="text-indent: -0.25in; margin-left: 0.75in;"&gt;&lt;span style="font-family: Symbol; color: rgb(31, 73, 125);"&gt;&lt;span&gt;·&lt;span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;"&gt;         &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;u&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;&lt;br /&gt;
Setter and Getter&lt;/span&gt;&lt;/u&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoListParagraph" style="margin-left: 0.75in;"&gt;&lt;u&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;The framework code&lt;/span&gt;&lt;/u&gt;&lt;span style="color: rgb(0, 176, 80);"&gt;&lt;br /&gt;
public  IEmployee Employee&lt;/span&gt;&lt;span style="color: rgb(0, 176, 80);"&gt;&lt;br /&gt;
{&lt;/span&gt;&lt;span style="color: rgb(0, 176, 80);"&gt;&lt;br /&gt;
     get&lt;/span&gt;&lt;span style="color: rgb(0, 176, 80);"&gt;      {&lt;/span&gt;&lt;span style="color: rgb(0, 176, 80);"&gt;  return this._emp;&lt;/span&gt;&lt;span style="color: rgb(0, 176, 80);"&gt;      }&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(0, 176, 80);"&gt;     set&lt;/span&gt;&lt;span style="color: rgb(0, 176, 80);"&gt;      {&lt;/span&gt;&lt;span style="color: rgb(0, 176, 80);"&gt;  this._emp = value;&lt;/span&gt;&lt;span style="color: rgb(0, 176, 80);"&gt;    }&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(0, 176, 80);"&gt; }&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoListParagraph" style="margin-left: 0.75in;"&gt;&lt;u&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;The client code&lt;br /&gt;
&lt;/span&gt;&lt;/u&gt;&lt;span style="color: rgb(0, 176, 80);"&gt;public class Client&lt;/span&gt;&lt;span style="color: rgb(0, 176, 80);"&gt;&lt;br /&gt;
{&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(0, 176, 80);"&gt;      Project proj = new Project();&lt;/span&gt;&lt;span style="color: rgb(0, 176, 80);"&gt;&lt;br /&gt;
      proj.Employee = new Employee();&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoListParagraph" style="margin-left: 0.75in;"&gt;&lt;span style="color: rgb(0, 176, 80);"&gt; }&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoListParagraph" style="text-indent: -0.25in; margin-bottom: 12pt; margin-left: 0.75in; margin-right: 0in;"&gt;&lt;span style="font-family: Symbol; color: red;"&gt;&lt;span&gt;·&lt;span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;"&gt;         &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;u&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;The Interface method&lt;/span&gt;&lt;/u&gt;&lt;/i&gt;&lt;/b&gt;&lt;/p&gt;
&lt;p class="MsoListParagraph" style="margin-left: 0.75in;"&gt;&lt;u&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;The framework code&lt;/span&gt;&lt;/u&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;span style="color: rgb(0, 176, 80);"&gt;public  interface IEmployeeDI &lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(0, 176, 80);"&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(0, 176, 80);"&gt;       void SetEmployee(IEmployee emp);&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(0, 176, 80);"&gt;}&lt;/span&gt;&lt;span style="color: rgb(0, 176, 80);"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoListParagraph" style="margin-left: 0.75in;"&gt;&lt;span style="color: rgb(0, 176, 80);"&gt;public class Project : IEmployeeDI&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(0, 176, 80);"&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(0, 176, 80);"&gt;        private IEmployee _emp; &lt;br /&gt;
&lt;/span&gt;&lt;span style="color: rgb(0, 176, 80);"&gt;        public void SetEmployee(IEmployee emp)&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(0, 176, 80);"&gt;        {&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(0, 176, 80);"&gt;            _emp = emp;&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(0, 176, 80);"&gt;        }&lt;br /&gt;
}&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoListParagraph" style="margin-left: 0.75in;"&gt;&lt;span style="color: rgb(31, 73, 125);"&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoListParagraph" style="margin-left: 0.75in;"&gt;&lt;u&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;The client code&lt;/span&gt;&lt;/u&gt;&lt;/p&gt;
&lt;p class="MsoListParagraph" style="margin-left: 0.75in;"&gt;&lt;span style="color: rgb(0, 176, 80);"&gt;public class Client&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(0, 176, 80);"&gt; {&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(0, 176, 80);"&gt;        Project proj = new Project();&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(0, 176, 80);"&gt;        public Client()&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(0, 176, 80);"&gt;        {&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(0, 176, 80);"&gt;            proj.SetEmployee(new  Employee());&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(0, 176, 80);"&gt;        }&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(0, 176, 80);"&gt;}&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoListParagraph" style="margin-left: 0.75in;"&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;u&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;The Service Locator Pattern &lt;/span&gt;&lt;/u&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;:  The main class will use the Service Locator you  aggregate the child object (Employee in this case).  The Service Locator &lt;br /&gt;
does  not create instances of the Employee object, it provides a methodology to  register and find services which will help in creating objects.  We will look &lt;br /&gt;
at  this patter later on when we are dealing with enterprise patterns.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;                         &lt;/span&gt;&lt;u&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;The framework  code&lt;/span&gt;&lt;/u&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-left: 1in;"&gt;&lt;span style="color: rgb(0, 176, 80);"&gt;public  static class LocateEmployee&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(0, 176, 80);"&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(0, 176, 80);"&gt;       public static IEmployee GetEmployee()&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(0, 176, 80);"&gt;        {&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(0, 176, 80);"&gt;            // your method goes here....&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(0, 176, 80);"&gt;         }&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-left: 1in;"&gt;&lt;span style="color: rgb(0, 176, 80);"&gt;}&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-left: 1in;"&gt;&lt;span style="color: rgb(0, 176, 80);"&gt;public class Project &lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(0, 176, 80);"&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(0, 176, 80);"&gt;         private IEmployee _emp;&lt;/span&gt;&lt;span style="color: rgb(0, 176, 80);"&gt;&lt;br /&gt;
        public Project()&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(0, 176, 80);"&gt;         {&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(0, 176, 80);"&gt;            this._emp = LocateEmployee.GetEmployee();  //  Call the Employee Locator&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(0, 176, 80);"&gt;         }&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(0, 176, 80);"&gt;}&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="color: rgb(31, 73, 125);"&gt; &lt;/span&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;We  now have knowledge about how  to  inject the dependencies into our objects manually.  In the next series of  &lt;i&gt;technomails&lt;/i&gt;, we will specifically have a look at the well known &lt;br /&gt;
DI  frameworks/IOC containers like , Unity Block, StructureMap, Castle Windsor etc.  as time permits and also some of the design benefits and some  real world  scenarios.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="color: rgb(31, 73, 125);"&gt; &lt;/span&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;Hope you enjoyed this series.   Do definitely ponder over this.  Though this may seem very preliminary, but it  has a huge impact on the design.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="color: rgb(31, 73, 125);"&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;P.S:  Do feel free to correct  any mistakes if any or clear any ambiguity if any exist&lt;/span&gt;&lt;/p&gt; &lt;img src="http://geekswithblogs.net/rajeshpillai/aggbug/136578.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Rajesh Pillai</dc:creator>
            <guid>http://geekswithblogs.net/rajeshpillai/archive/2009/11/28/techmastdi.aspx</guid>
            <pubDate>Sat, 28 Nov 2009 05:36:27 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/rajeshpillai/comments/136578.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/rajeshpillai/archive/2009/11/28/techmastdi.aspx#feedback</comments>
            <slash:comments>3</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/rajeshpillai/comments/commentRss/136578.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/rajeshpillai/services/trackbacks/136578.aspx</trackback:ping>
        </item>
    </channel>
</rss>
