SlideShare a Scribd company logo
1 of 15
Download to read offline
Dependency Injection 
With Unity Container 
Presenter: Kaveri Saxena, Mindfire Solutions 
Date: 28/04/2014
KKaavveerrii SSaaxxeennaa 
WWoorrkkiinngg WWiitthh MMiinnddffiirree ssiinnccee JJuullyy 11,,22001133 
WWiinnddoowwss DDeesskkttoopp AApppplliiccaattiioonn DDeevveellooppeerr (CC##,, ..NNEETT)) 
SSkkyyppee:: mmffssii__kkaavveerriiss 
EEmmaaiill :: kkaavveerriiss@@mmiinnddffiirreessoolluuttiioonnss..ccoomm 
Presenter: Kaveri Saxena, Mindfire Solutions
Presenter: Kaveri Saxena, Mindfire Solutions 
AGENDA 
●Overview Of Dependency Injection 
●Why Dependency Injection? 
●Constructor Injection 
●Setter Injection 
●Interface Injection 
●Overview of DI Containers 
●Demo Implementing Dependency Injection with Unity Container 
●Q&A
Overview Of Dependency Injection 
Dependency injection is a software design pattern that allows 
the removal of hard-coded dependencies and makes it possible 
to change them,whether at run time or compile time. 
Dependency injection is a set of software design principles and 
Pattern that enable us to develop loosely coupled codes. 
- Mark Seeman 
Tight 
Coupling 
Form 
(Class) Repository 
Var repository = new Repository();
Why To Use DI????? 
●Extensibility 
●Testability 
●Late Binding 
●Parallel Development 
●Maintainability
Constructor Injection 
Pass dependency into dependent class via constructor 
var service = new SQLService(); 
Var form = new PersonForm(service); 
Application.Run(form); 
private IServiceRepository Repository; 
public PersonForm(IServiceRepository repository) 
{ 
Repository = repository; 
}
Setter Injection 
Create a setter on the dependent class and use that to set the 
dependency. 
var form = new PersonForm(); 
form.Repository = new CSVService(); 
Application.Run(form); 
private IServiceRepository Repository { get; set; }
Interface Injection 
Dependent class implements an interface and injector uses 
the interface to set the dependency. 
var service = new SQLService(); 
var form = new PersonForm(); 
((IInjectInterface)form).inject(service); 
Application.Run(form); 
public interface IInjectInterface 
{ 
void inject(IServiceRepository serviceRepo); 
}
public partial class PersonForm :Form,IInjectInterface 
{ 
public void inject(IServiceRepository serviceRepo) 
{ 
Repository = serviceRepo; 
} 
}
Overview Of DI Container 
●A framework for doing dependency Injection 
●Configure dependencies 
●Automatically resolves configured dependencies 
Eg. Unity,Ninject,,CastleWindsor,Autofac,structuremap, 
Spring.Net and many others. 
SqlService 
DI Container 
CSVService 
IService 
Person Form
Unity Container 
Unity comes from microsoft pattern and practice team, 
available as free download. 
For using Unity Container- 
●Download compatible version of unity in your bootstrapper 
Application 
● Register interface with concrete type 
●Call resolve method and unity will automatically find complex 
constructor of dependent class and use concrete type instead 
of interface. 
var container = new UnityContainer(); 
container.RegisterType<IServiceRepository, 
SQLService>(); 
var form = container.Resolve<PersonForm>(); 
Application.Run(form);
Question and 
Answer 
Presenter: Kaveri Saxena, Mindfire Solutions
Thank you 
Presenter: Kaveri Saxena, Mindfire Solutions
www.mindfiresolutions.com 
https://www.facebook.com/MindfireSolutions 
http://www.linkedin.com/company/mindfire-solutions 
http://twitter.com/mindfires
References: 
http://www.pluralsight.com/courses/dependency-injection-on-ramp

More Related Content

What's hot

Agile methodologies based on BDD and CI by Nikolai Shevchenko
Agile methodologies based on BDD and CI by Nikolai ShevchenkoAgile methodologies based on BDD and CI by Nikolai Shevchenko
Agile methodologies based on BDD and CI by Nikolai Shevchenko
Moldova ICT Summit
 
Design pattern proxy介紹 20130805
Design pattern proxy介紹 20130805Design pattern proxy介紹 20130805
Design pattern proxy介紹 20130805
LearningTech
 

What's hot (20)

MongoDB Stitch Tutorial
MongoDB Stitch TutorialMongoDB Stitch Tutorial
MongoDB Stitch Tutorial
 
Developing ASP.NET Applications Using the Model View Controller Pattern
Developing ASP.NET Applications Using the Model View Controller PatternDeveloping ASP.NET Applications Using the Model View Controller Pattern
Developing ASP.NET Applications Using the Model View Controller Pattern
 
Tdd,Ioc
Tdd,IocTdd,Ioc
Tdd,Ioc
 
Dependency Injection
Dependency InjectionDependency Injection
Dependency Injection
 
Vasyl Aleksashyn "How to Stop Shooting Yourself in the Foot"
Vasyl Aleksashyn "How to Stop Shooting Yourself in the Foot"Vasyl Aleksashyn "How to Stop Shooting Yourself in the Foot"
Vasyl Aleksashyn "How to Stop Shooting Yourself in the Foot"
 
Java Svet - Communication Between Android App Components
Java Svet - Communication Between Android App ComponentsJava Svet - Communication Between Android App Components
Java Svet - Communication Between Android App Components
 
Agile methodologies based on BDD and CI by Nikolai Shevchenko
Agile methodologies based on BDD and CI by Nikolai ShevchenkoAgile methodologies based on BDD and CI by Nikolai Shevchenko
Agile methodologies based on BDD and CI by Nikolai Shevchenko
 
Jasig Cas High Availability - Yale University
Jasig Cas High Availability -  Yale UniversityJasig Cas High Availability -  Yale University
Jasig Cas High Availability - Yale University
 
Distributing information on iOS
Distributing information on iOSDistributing information on iOS
Distributing information on iOS
 
Deployment
DeploymentDeployment
Deployment
 
Introduction to Spring MVC
Introduction to Spring MVCIntroduction to Spring MVC
Introduction to Spring MVC
 
Wiesław Kałkus: C# functional programming
Wiesław Kałkus: C# functional programmingWiesław Kałkus: C# functional programming
Wiesław Kałkus: C# functional programming
 
Ngrx meta reducers
Ngrx meta reducersNgrx meta reducers
Ngrx meta reducers
 
Proxy design pattern (Class Ambassador)
Proxy design pattern (Class Ambassador)Proxy design pattern (Class Ambassador)
Proxy design pattern (Class Ambassador)
 
Proxy design pattern
Proxy design patternProxy design pattern
Proxy design pattern
 
CDI @javaonehyderabad
CDI @javaonehyderabadCDI @javaonehyderabad
CDI @javaonehyderabad
 
Design pattern proxy介紹 20130805
Design pattern proxy介紹 20130805Design pattern proxy介紹 20130805
Design pattern proxy介紹 20130805
 
Functional programming in C#
Functional programming in C#Functional programming in C#
Functional programming in C#
 
Introduction to OO, Java and Eclipse/WebSphere
Introduction to OO, Java and Eclipse/WebSphereIntroduction to OO, Java and Eclipse/WebSphere
Introduction to OO, Java and Eclipse/WebSphere
 
Proxy Pattern
Proxy PatternProxy Pattern
Proxy Pattern
 

Viewers also liked

Viewers also liked (10)

Build Reusable Web Components using HTML5 Web cComponents
Build Reusable Web Components using HTML5 Web cComponentsBuild Reusable Web Components using HTML5 Web cComponents
Build Reusable Web Components using HTML5 Web cComponents
 
SOLID Principles Part 3
SOLID Principles Part 3SOLID Principles Part 3
SOLID Principles Part 3
 
Inversion of control
Inversion of controlInversion of control
Inversion of control
 
Introduction to SOLID Principles
Introduction to SOLID PrinciplesIntroduction to SOLID Principles
Introduction to SOLID Principles
 
Open Closed Principle kata
Open Closed Principle kataOpen Closed Principle kata
Open Closed Principle kata
 
IoC and Mapper in C#
IoC and Mapper in C#IoC and Mapper in C#
IoC and Mapper in C#
 
Dependency Inversion Principle
Dependency Inversion PrincipleDependency Inversion Principle
Dependency Inversion Principle
 
Inversion of Control in MVC
Inversion of Control in MVCInversion of Control in MVC
Inversion of Control in MVC
 
Architectural Patterns and Software Architectures: Client-Server, Multi-Tier,...
Architectural Patterns and Software Architectures: Client-Server, Multi-Tier,...Architectural Patterns and Software Architectures: Client-Server, Multi-Tier,...
Architectural Patterns and Software Architectures: Client-Server, Multi-Tier,...
 
SOLID - Principles of Object Oriented Design
SOLID - Principles of Object Oriented DesignSOLID - Principles of Object Oriented Design
SOLID - Principles of Object Oriented Design
 

Similar to Dependency Injection with Unity Container

Dependency Injection або Don’t call me, I’ll call you
Dependency Injection або Don’t call me, I’ll call youDependency Injection або Don’t call me, I’ll call you
Dependency Injection або Don’t call me, I’ll call you
Dmytro Mindra
 
JavaOne 2013 BOF 3861 - Mixing OAuth 2.0, Jersey and Guice to Build an Ecosys...
JavaOne 2013 BOF 3861 - Mixing OAuth 2.0, Jersey and Guice to Build an Ecosys...JavaOne 2013 BOF 3861 - Mixing OAuth 2.0, Jersey and Guice to Build an Ecosys...
JavaOne 2013 BOF 3861 - Mixing OAuth 2.0, Jersey and Guice to Build an Ecosys...
Matthias Miltz
 
Mixing OAuth 2.0, Jersey and Guice to Build an Ecosystem of Apps - JavaOne...
Mixing OAuth 2.0, Jersey and Guice to Build an Ecosystem of Apps - JavaOne...Mixing OAuth 2.0, Jersey and Guice to Build an Ecosystem of Apps - JavaOne...
Mixing OAuth 2.0, Jersey and Guice to Build an Ecosystem of Apps - JavaOne...
Hermann Burgmeier
 

Similar to Dependency Injection with Unity Container (20)

JavaCro'15 - Web UI best practice integration with Java EE 7 - Peter Lehto
JavaCro'15 - Web UI best practice integration with Java EE 7 - Peter LehtoJavaCro'15 - Web UI best practice integration with Java EE 7 - Peter Lehto
JavaCro'15 - Web UI best practice integration with Java EE 7 - Peter Lehto
 
Dependency Injection in Drupal 8
Dependency Injection in Drupal 8Dependency Injection in Drupal 8
Dependency Injection in Drupal 8
 
Spring Framework-II
Spring Framework-IISpring Framework-II
Spring Framework-II
 
Techlunch - Dependency Injection with Vaadin
Techlunch - Dependency Injection with VaadinTechlunch - Dependency Injection with Vaadin
Techlunch - Dependency Injection with Vaadin
 
Swiz DAO
Swiz DAOSwiz DAO
Swiz DAO
 
High Performance Cloud Native APIs Using Apache Geode
High Performance Cloud Native APIs Using Apache Geode High Performance Cloud Native APIs Using Apache Geode
High Performance Cloud Native APIs Using Apache Geode
 
MVVM Design Pattern NDC2009
MVVM Design Pattern NDC2009MVVM Design Pattern NDC2009
MVVM Design Pattern NDC2009
 
Dependency Injection або Don’t call me, I’ll call you
Dependency Injection або Don’t call me, I’ll call youDependency Injection або Don’t call me, I’ll call you
Dependency Injection або Don’t call me, I’ll call you
 
Critical Analysis of SW Development tool/methodology
Critical Analysis of SW Development tool/methodologyCritical Analysis of SW Development tool/methodology
Critical Analysis of SW Development tool/methodology
 
Leveraging Dependency Injection(DI) in Universal Applications - Tamir Dresher
Leveraging Dependency Injection(DI) in Universal Applications -  Tamir DresherLeveraging Dependency Injection(DI) in Universal Applications -  Tamir Dresher
Leveraging Dependency Injection(DI) in Universal Applications - Tamir Dresher
 
Angular Dependency Injection
Angular Dependency InjectionAngular Dependency Injection
Angular Dependency Injection
 
.NET Intro & Dependency Injection Workshop
.NET Intro & Dependency Injection Workshop.NET Intro & Dependency Injection Workshop
.NET Intro & Dependency Injection Workshop
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
FedScoop Public Sector Innovation Summit DOD Enterprise DevSecOps Initiative ...
FedScoop Public Sector Innovation Summit DOD Enterprise DevSecOps Initiative ...FedScoop Public Sector Innovation Summit DOD Enterprise DevSecOps Initiative ...
FedScoop Public Sector Innovation Summit DOD Enterprise DevSecOps Initiative ...
 
Angular Seminar-js
Angular Seminar-jsAngular Seminar-js
Angular Seminar-js
 
Resume
ResumeResume
Resume
 
The Quest for Continuous Delivery at Pluralsight
The Quest for Continuous Delivery at PluralsightThe Quest for Continuous Delivery at Pluralsight
The Quest for Continuous Delivery at Pluralsight
 
Iddd ch14
Iddd ch14Iddd ch14
Iddd ch14
 
JavaOne 2013 BOF 3861 - Mixing OAuth 2.0, Jersey and Guice to Build an Ecosys...
JavaOne 2013 BOF 3861 - Mixing OAuth 2.0, Jersey and Guice to Build an Ecosys...JavaOne 2013 BOF 3861 - Mixing OAuth 2.0, Jersey and Guice to Build an Ecosys...
JavaOne 2013 BOF 3861 - Mixing OAuth 2.0, Jersey and Guice to Build an Ecosys...
 
Mixing OAuth 2.0, Jersey and Guice to Build an Ecosystem of Apps - JavaOne...
Mixing OAuth 2.0, Jersey and Guice to Build an Ecosystem of Apps - JavaOne...Mixing OAuth 2.0, Jersey and Guice to Build an Ecosystem of Apps - JavaOne...
Mixing OAuth 2.0, Jersey and Guice to Build an Ecosystem of Apps - JavaOne...
 

More from Mindfire Solutions

More from Mindfire Solutions (20)

Physician Search and Review
Physician Search and ReviewPhysician Search and Review
Physician Search and Review
 
diet management app
diet management appdiet management app
diet management app
 
Business Technology Solution
Business Technology SolutionBusiness Technology Solution
Business Technology Solution
 
Remote Health Monitoring
Remote Health MonitoringRemote Health Monitoring
Remote Health Monitoring
 
Influencer Marketing Solution
Influencer Marketing SolutionInfluencer Marketing Solution
Influencer Marketing Solution
 
ELMAH
ELMAHELMAH
ELMAH
 
High Availability of Azure Applications
High Availability of Azure ApplicationsHigh Availability of Azure Applications
High Availability of Azure Applications
 
IOT Hands On
IOT Hands OnIOT Hands On
IOT Hands On
 
Glimpse of Loops Vs Set
Glimpse of Loops Vs SetGlimpse of Loops Vs Set
Glimpse of Loops Vs Set
 
Oracle Sql Developer-Getting Started
Oracle Sql Developer-Getting StartedOracle Sql Developer-Getting Started
Oracle Sql Developer-Getting Started
 
Adaptive Layout In iOS 8
Adaptive Layout In iOS 8Adaptive Layout In iOS 8
Adaptive Layout In iOS 8
 
Introduction to Auto-layout : iOS/Mac
Introduction to Auto-layout : iOS/MacIntroduction to Auto-layout : iOS/Mac
Introduction to Auto-layout : iOS/Mac
 
LINQPad - utility Tool
LINQPad - utility ToolLINQPad - utility Tool
LINQPad - utility Tool
 
Get started with watch kit development
Get started with watch kit developmentGet started with watch kit development
Get started with watch kit development
 
Swift vs Objective-C
Swift vs Objective-CSwift vs Objective-C
Swift vs Objective-C
 
Material Design in Android
Material Design in AndroidMaterial Design in Android
Material Design in Android
 
Introduction to OData
Introduction to ODataIntroduction to OData
Introduction to OData
 
Ext js Part 2- MVC
Ext js Part 2- MVCExt js Part 2- MVC
Ext js Part 2- MVC
 
ExtJs Basic Part-1
ExtJs Basic Part-1ExtJs Basic Part-1
ExtJs Basic Part-1
 
Spring Security Introduction
Spring Security IntroductionSpring Security Introduction
Spring Security Introduction
 

Recently uploaded

AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 

Recently uploaded (20)

10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 

Dependency Injection with Unity Container

  • 1. Dependency Injection With Unity Container Presenter: Kaveri Saxena, Mindfire Solutions Date: 28/04/2014
  • 2. KKaavveerrii SSaaxxeennaa WWoorrkkiinngg WWiitthh MMiinnddffiirree ssiinnccee JJuullyy 11,,22001133 WWiinnddoowwss DDeesskkttoopp AApppplliiccaattiioonn DDeevveellooppeerr (CC##,, ..NNEETT)) SSkkyyppee:: mmffssii__kkaavveerriiss EEmmaaiill :: kkaavveerriiss@@mmiinnddffiirreessoolluuttiioonnss..ccoomm Presenter: Kaveri Saxena, Mindfire Solutions
  • 3. Presenter: Kaveri Saxena, Mindfire Solutions AGENDA ●Overview Of Dependency Injection ●Why Dependency Injection? ●Constructor Injection ●Setter Injection ●Interface Injection ●Overview of DI Containers ●Demo Implementing Dependency Injection with Unity Container ●Q&A
  • 4. Overview Of Dependency Injection Dependency injection is a software design pattern that allows the removal of hard-coded dependencies and makes it possible to change them,whether at run time or compile time. Dependency injection is a set of software design principles and Pattern that enable us to develop loosely coupled codes. - Mark Seeman Tight Coupling Form (Class) Repository Var repository = new Repository();
  • 5. Why To Use DI????? ●Extensibility ●Testability ●Late Binding ●Parallel Development ●Maintainability
  • 6. Constructor Injection Pass dependency into dependent class via constructor var service = new SQLService(); Var form = new PersonForm(service); Application.Run(form); private IServiceRepository Repository; public PersonForm(IServiceRepository repository) { Repository = repository; }
  • 7. Setter Injection Create a setter on the dependent class and use that to set the dependency. var form = new PersonForm(); form.Repository = new CSVService(); Application.Run(form); private IServiceRepository Repository { get; set; }
  • 8. Interface Injection Dependent class implements an interface and injector uses the interface to set the dependency. var service = new SQLService(); var form = new PersonForm(); ((IInjectInterface)form).inject(service); Application.Run(form); public interface IInjectInterface { void inject(IServiceRepository serviceRepo); }
  • 9. public partial class PersonForm :Form,IInjectInterface { public void inject(IServiceRepository serviceRepo) { Repository = serviceRepo; } }
  • 10. Overview Of DI Container ●A framework for doing dependency Injection ●Configure dependencies ●Automatically resolves configured dependencies Eg. Unity,Ninject,,CastleWindsor,Autofac,structuremap, Spring.Net and many others. SqlService DI Container CSVService IService Person Form
  • 11. Unity Container Unity comes from microsoft pattern and practice team, available as free download. For using Unity Container- ●Download compatible version of unity in your bootstrapper Application ● Register interface with concrete type ●Call resolve method and unity will automatically find complex constructor of dependent class and use concrete type instead of interface. var container = new UnityContainer(); container.RegisterType<IServiceRepository, SQLService>(); var form = container.Resolve<PersonForm>(); Application.Run(form);
  • 12. Question and Answer Presenter: Kaveri Saxena, Mindfire Solutions
  • 13. Thank you Presenter: Kaveri Saxena, Mindfire Solutions