SlideShare a Scribd company logo
UNITY FRAMEWORK
- KRANTISINH DESHMUKH
WHAT IS IT ?
• THE UNITY FRAMEWORK OR UNITY APPLICATION BLOCK IS A LIGHTWEIGHT EXTENSIBLE
DEPENDENCY INJECTION CONTAINER WITH SUPPORT FOR CONSTRUCTOR, PROPERTY, AND
METHOD CALL INJECTION.

• IT’S A VERY GOOD WAY TO ACHIEVE LOOSE COUPLING IN THE APPLICATION. LOOSELY
COUPLED APPLICATIONS ARE VERY EASY TO MAINTAIN AND TEST.
• IT PROVIDES INVERSION OF CONTROL (IOC) FUNCTIONALITY BY ALLOWING INJECTION OF
PRECONFIGURED OBJECTS INTO CLASSES BUILT BY THE APPLICATION BLOCK.
WHY IOC ?

• ASSUME THERE IS A CLASS CALLED "KIDS.CS". THE PURPOSE OF THIS CLASS IS TO MAINTAIN
THE NAME AND AGE OF THE CHILDREN OF A SPECIFIC PERSON.
• NOW THE REQUIREMENT IS THAT EACH PERSON HAS KIDS. SO AT THE TIME OF CREATION OF A
PERSON, THE ASSOCIATED KIDS SHOULD ALSO BE CREATED. SO THIS MAY BE DONE BY THE
FOLLOWING CODE.
WHY IOC ?
• WHEN AN OBJECT NEEDS ANOTHER OBJECT THEN IT IS SAID THAT THE OBJECT IS DEPENDENT ON THE
OTHER OBJECT. IN THIS CASE, KID’S CLASS IS DEPENDENT ON PERSON’S CLASS.

PROBLEMS IN THE ABOVE APPROACH:
• HERE THE KIDS OBJECT HAS BEEN CREATED INSIDE THE CONSTRUCTOR OF THE PERSON CLASS. SO, HERE
COUPLING IS VERY HIGH OR TIGHT.

• IF DUE TO ANY REASON THE CREATION OF THE KIDS OBJECT FAILS THEN THE PERSON CLASS ALSO
CANNOT BE INSTANTIATED IN ITS CONSTRUCTOR ITSELF.
• IF THE PERSON OBJECT CLASS IS KILLED THEN BY DEFAULT THE OBJECT OF THE KIDS CLASS IS ALSO KILLED.
• IF A NEW TYPE OF KIDS HAS BEEN CREATED OR A NEW PROPERTY IS BEING ADDED IN THE KIDS CLASS
THEN IT NEEDS CODE MODIFICATION IN THE PERSON CLASS ALSO.
IOC
• THE PREVIOUS PROBLEM CAN BE SOLVED IF WE ASSIGN THE TASK OF OBJECT CREATION TO A
THIRD PARTY.
• SO, ASSIGNING THE TASK OF OBJECT CREATION TO A THIRD-PARTY IS SOMEHOW INVERTING
CONTROL TO THE THIRD-PARTY. AND THIS IS CALLED "INVERSION OF CONTROL" (IOC).
• IN OTHER WORDS, THE INVERSION OF CONTROL DESIGN PATTERN COULD BE DEFINED AS
DELEGATING THE TASK OF OBJECT CREATION TO A THIRD-PARTY, TO DO LOW COUPLING
AMONG OBJECTS AND TO MINIMIZE DEPENDENCY AMONG OBJECTS.
THE ACTUAL PROCESS

Person Class

Pass object to
Person

Inversion of
Control
Container
[ A Third Party
Class ]

Create object of
Kids Class

Kids Class
IOC
SO IOC SAYS:
• THE MAIN CLASS (PESRON.CS) COMPOSES ANOTHER CLASS THAT SHOULD NOT DIRECTLY
DEPEND ON THE IMPLEMENTATION OF THE OTHER CLASS (KIDS.CS).
• THERE SHOULD BE AN ABSTRACTION AMONG CLASSES AND THE CLASSES SHOULD FULLY
DEPEND UPON THAT ABSTRACTION.
• ABSTRACTION COULD BE EITHER AN INTERFACE OR AN ABSTRACT CLASS.
DEPENDENCY INJECTION
DEPENDENCY INJECTION IS THE WAY TO IMPLEMENT IOC.
IT PROVIDES FOLLOWING BENEFITS:

• ELIMINATES TIGHT COUPLING AMONG OBJECTS.
• MAKES THE OBJECT AND THE APPLICATION MORE FLEXIBLE.
• FACILITATES CREATION OF MORE LOOSELY COUPLED OBJECTS AND THEIR DEPENDENCIES.
• ISOLATES IMPLEMENTATION OF AN OBJECT FROM THE CONSTRUCTION OF THE OBJECT ON WHICH
IT DEPENDS.
Dependency Injection

Constructor
Injection

Setter
Injection

Method Call
Injection
CONSTRUCTOR INJECTION
• HERE AN OBJECT REFERENCE WOULD BE PASSED TO THE CONSTRUCTOR OF THE BUSINESS
CLASS PERSON.
• IN THIS CASE, SINCE THE PERSON CLASS DEPENDS ON THE KIDS CLASS, SO THE REFERENCE OF
THE KIDS CLASS WILL BE PASSED TO THE CONSTRUCTOR OF THE PERSON CLASS.
• SO, AT THE TIME OF OBJECT CREATION OF THE PERSON CLASS, THE KIDS CLASS WILL BE
INSTANTIATED.
• THE FOLLOWING IS THE PROCEDURE TO IMPLEMENT CONSTRUCTOR INJECTION.
CONSTRUCTOR INJECTION
• STEP 1: CREATE AN INTERFACE IBUSINESSLOGIC.CS

THIS INTERFACE WOULD BE IMPLEMENTED BY A BUSINESS LOGIC CLASS. HERE THE KIDS CLASS IS
A BUSINESS LOGIC CLASS.
ONLY THE METHODS OF THE INTERFACE WILL BE EXPOSED TO THE BUSINESS LOGIC CLASS
(PERSON).
{
}

}

• STEP 2: IMPLEMENT AN INTERFACE TO THE KIDS CLASS. AN OBJECT OF THE KIDS CLASS WILL
BE REFERENCED BY THE PERSON CLASS. SO THIS CLASS NEEDS TO IMPLEMENT THE INTERFACE.
• STEP 3: MAKE A REFERENCE OF THE INTERFACE IN THE PERSON CLASS.
• STEP 4: NOW TO CREATE A THIRD-PARTY CLASS WHERE THE CREATION OF THE OBJECT WILL BE
DONE. IN THE CODE BELOW IS A FACTORYMETHOD() METHOD WHERE THE OBJECT IS GETTING
CREATED.
• STEP 5: NOW TO USE A THIRD-PARTY CLASS AT THE CLIENT-SIDE.
THE IOC PROCESS IN ONE SHOT

Person Class

Pass object to
Person

IOC Class
Factory
Method

IBusinessLogic

Create object of
Kids Class

Kids Class
ACHIEVING IOC THROUGH UNITY FRAMEWORK IN
MVC4
I only have to
do all the
tasks….
Why did
God make
me Controller
??? 



Don’t
worry…
I’ll handle
the object
creation… U
take care of
the rest…



UNITY
MVC
CONTROLLER
WITHOUT
UNITY

MVC
CONTROLLER
WITH UNITY
PHASES OF OBJECT CREATION
• REGISTER - REGISTER THE TYPE OF THE OBJECT THAT HAS TO BE INSTANTIATED WITH
UNITY CONTAINER
• RESOLVE – LET UNITY CONTAINER KNOW THAT NOW IS THE TIME TO INSTANTIATE
THE OBJECT
• DISPOSE – GET RID OF THE OBJECT IF ITS ROLE IS OVER
ACHIEVING IOC THROUGH UNITY FRAMEWORK IN
MVC4
• WE CAN ACHIEVE IOC THROUGH UNITY FRAMEWORK IN 4 SIMPLE STEPS:
1. INSTALL UNITY THROUGH PACKAGE MANAGER CONSOLE.
2. CREATE UNITY CONTAINER IN BOOTSTARPPER .CS FILE. REGISTER THE DEPENDENCIES.
3. INJECT THE DEPENDENCY IN CONTROLLER THROUGH CONSTRUCTOR
4. IN GLOBAL.ASAX.CS , SET UP THE DEPENDENCY INJECTION THROUGH UNITY [CALL BOOTSTRAPPER
CLASS]
CREATE A NEW
ASP.NET MVC 4
APPLICATION
GETTING STARTED WITH UNITY FRAMEWORK
• UNITY 3.0 COMES UNDER NUGET PACKAGE IN VS2012. TO INSTALL, EXECUTE
BELOW COMMAND IN PACKAGE MANAGER CONSOLE:

• PM> INSTALL-PACKAGE UNITY.MVC4
ADDING REFERENCES
• REFERENCES TO THE PROJECT WILL GET
AUTOMATICALLY ADDED ONCE WE EXECUTE
PM> INSTALL-PACKAGE UNITY.MVC4 IN
PACKAGE MANAGER CONSOLE.
CREATE A REPOSITORY FOR DATA
PRODUCT CLASS

INTERFACE FOR PRODUCTREPOSITORY
IMPLEMENT
IPRODUCT
REPOSITORY
IN PRODUCT
REPOSITORY
CLASS
REGISTER THE
DEPENDENCY IN
BOOTSTRAPPER.CS FILE
INJECT DEPENDENCY
IN THE
CONSTRUCTOR OF
THE CONTROLLER
SETUP
DEPENDENCY
INJECTION WITH
UNITY IN
GLOBAL.ASAX.CS
FINALLY,
GENERATE THE
VIEW
OUTPUT
3 WHYS…
• WHY UNITY FRAMEWORK ?
 TO IMPLEMENT IOC THROUGH DEPENDENCY INJECTION

• WHY IMPLEMENT IOC?
 TO ACHIEVE LOOSE COUPLING IN THE APPLICATION

• WHY LOOSE COUPLING ?
 TO MAKE THE APPLICATION MORE MAINTAINABLE AND TESTABLE

• SO, USE OF UNITY FRAMEWORK IN OUR APPLICATION MEANS OUR APPLICATION IS MORE
MAINTAINABLE AND TESTABLE.
DON’T USE UNITY FRAMEWORK IN FOLLOWING
SCENARIOS
• YOUR OBJECTS AND CLASSES HAVE NO DEPENDENCIES ON OTHER OBJECTS OR
CLASSES.
• YOUR DEPENDENCIES ARE VERY SIMPLE AND DO NOT REQUIRE ABSTRACTION.
Thank You…

More Related Content

Similar to Unity Framework

Delta Beacon Time Capsule
Delta Beacon Time CapsuleDelta Beacon Time Capsule
Delta Beacon Time Capsule
Timø Ronan
 
Agile Methods - 2 day workshop
Agile Methods - 2 day workshopAgile Methods - 2 day workshop
Agile Methods - 2 day workshop
Evan Leybourn
 
Inside Lean Kanban (#lkuk14 keynote)
Inside Lean Kanban (#lkuk14 keynote)Inside Lean Kanban (#lkuk14 keynote)
Inside Lean Kanban (#lkuk14 keynote)
Mike Burrows
 
Oose unit 3 ppt
Oose unit 3 pptOose unit 3 ppt
Oose unit 3 ppt
Dr VISU P
 
ORACLE HRMS recruitment activities
ORACLE HRMS recruitment activitiesORACLE HRMS recruitment activities
ORACLE HRMS recruitment activities
yogitas1
 
HRMS recuritment act
HRMS recuritment actHRMS recuritment act
HRMS recuritment act
yogitas1
 
Operations management takira motors
Operations management takira motorsOperations management takira motors
Operations management takira motors
Shrey Agarwal
 
Question 1· (Part 1)· Using a 4.5 discount rate, calculat.docx
Question 1· (Part 1)· Using a 4.5 discount rate, calculat.docxQuestion 1· (Part 1)· Using a 4.5 discount rate, calculat.docx
Question 1· (Part 1)· Using a 4.5 discount rate, calculat.docx
makdul
 
Question 1· (Part 1)· Using a 4.5 discount rate, calculat.docx
Question 1· (Part 1)· Using a 4.5 discount rate, calculat.docxQuestion 1· (Part 1)· Using a 4.5 discount rate, calculat.docx
Question 1· (Part 1)· Using a 4.5 discount rate, calculat.docx
IRESH3
 
One Year Later: Reflections on Developing with Extbase and Fluid
One Year Later: Reflections on Developing with Extbase and FluidOne Year Later: Reflections on Developing with Extbase and Fluid
One Year Later: Reflections on Developing with Extbase and Fluid
zdavis
 
Open Assessments and OERs as Enablers in Competency-Based Education
Open Assessments and OERs as Enablers in Competency-Based Education Open Assessments and OERs as Enablers in Competency-Based Education
Open Assessments and OERs as Enablers in Competency-Based Education
Tom Caswell
 
Agility from First Principles
Agility from First PrinciplesAgility from First Principles
Agility from First Principles
Tathagat Varma
 
Project: Communicating the Instructional Design Process
Project: Communicating the Instructional Design ProcessProject: Communicating the Instructional Design Process
Project: Communicating the Instructional Design Process
Carson Wampler
 
Caveon Webinar Series - Will the Real Cloned Item Please Stand Up? final
Caveon Webinar Series -  Will the Real Cloned Item Please Stand Up? finalCaveon Webinar Series -  Will the Real Cloned Item Please Stand Up? final
Caveon Webinar Series - Will the Real Cloned Item Please Stand Up? final
Caveon Test Security
 
Iterate. Calculate. Communicate.
Iterate. Calculate. Communicate.Iterate. Calculate. Communicate.
Iterate. Calculate. Communicate.
Laure Parsons
 
Week08
Week08Week08
Week08hccit
 
A Proven Software Development Process for the Non Technical Founder
A Proven Software Development Process for the Non Technical FounderA Proven Software Development Process for the Non Technical Founder
A Proven Software Development Process for the Non Technical Founder
Founders Workshop
 
The evolution of agile development process
The evolution of agile development processThe evolution of agile development process
The evolution of agile development process
David Tzemach
 
Innovation at 50x 031616
Innovation at 50x 031616Innovation at 50x 031616
Innovation at 50x 031616
Stanford University
 
Presentation on "MICROSOFT"
Presentation on "MICROSOFT"Presentation on "MICROSOFT"
Presentation on "MICROSOFT"
DipankarChakraborty28
 

Similar to Unity Framework (20)

Delta Beacon Time Capsule
Delta Beacon Time CapsuleDelta Beacon Time Capsule
Delta Beacon Time Capsule
 
Agile Methods - 2 day workshop
Agile Methods - 2 day workshopAgile Methods - 2 day workshop
Agile Methods - 2 day workshop
 
Inside Lean Kanban (#lkuk14 keynote)
Inside Lean Kanban (#lkuk14 keynote)Inside Lean Kanban (#lkuk14 keynote)
Inside Lean Kanban (#lkuk14 keynote)
 
Oose unit 3 ppt
Oose unit 3 pptOose unit 3 ppt
Oose unit 3 ppt
 
ORACLE HRMS recruitment activities
ORACLE HRMS recruitment activitiesORACLE HRMS recruitment activities
ORACLE HRMS recruitment activities
 
HRMS recuritment act
HRMS recuritment actHRMS recuritment act
HRMS recuritment act
 
Operations management takira motors
Operations management takira motorsOperations management takira motors
Operations management takira motors
 
Question 1· (Part 1)· Using a 4.5 discount rate, calculat.docx
Question 1· (Part 1)· Using a 4.5 discount rate, calculat.docxQuestion 1· (Part 1)· Using a 4.5 discount rate, calculat.docx
Question 1· (Part 1)· Using a 4.5 discount rate, calculat.docx
 
Question 1· (Part 1)· Using a 4.5 discount rate, calculat.docx
Question 1· (Part 1)· Using a 4.5 discount rate, calculat.docxQuestion 1· (Part 1)· Using a 4.5 discount rate, calculat.docx
Question 1· (Part 1)· Using a 4.5 discount rate, calculat.docx
 
One Year Later: Reflections on Developing with Extbase and Fluid
One Year Later: Reflections on Developing with Extbase and FluidOne Year Later: Reflections on Developing with Extbase and Fluid
One Year Later: Reflections on Developing with Extbase and Fluid
 
Open Assessments and OERs as Enablers in Competency-Based Education
Open Assessments and OERs as Enablers in Competency-Based Education Open Assessments and OERs as Enablers in Competency-Based Education
Open Assessments and OERs as Enablers in Competency-Based Education
 
Agility from First Principles
Agility from First PrinciplesAgility from First Principles
Agility from First Principles
 
Project: Communicating the Instructional Design Process
Project: Communicating the Instructional Design ProcessProject: Communicating the Instructional Design Process
Project: Communicating the Instructional Design Process
 
Caveon Webinar Series - Will the Real Cloned Item Please Stand Up? final
Caveon Webinar Series -  Will the Real Cloned Item Please Stand Up? finalCaveon Webinar Series -  Will the Real Cloned Item Please Stand Up? final
Caveon Webinar Series - Will the Real Cloned Item Please Stand Up? final
 
Iterate. Calculate. Communicate.
Iterate. Calculate. Communicate.Iterate. Calculate. Communicate.
Iterate. Calculate. Communicate.
 
Week08
Week08Week08
Week08
 
A Proven Software Development Process for the Non Technical Founder
A Proven Software Development Process for the Non Technical FounderA Proven Software Development Process for the Non Technical Founder
A Proven Software Development Process for the Non Technical Founder
 
The evolution of agile development process
The evolution of agile development processThe evolution of agile development process
The evolution of agile development process
 
Innovation at 50x 031616
Innovation at 50x 031616Innovation at 50x 031616
Innovation at 50x 031616
 
Presentation on "MICROSOFT"
Presentation on "MICROSOFT"Presentation on "MICROSOFT"
Presentation on "MICROSOFT"
 

Recently uploaded

FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
ThomasParaiso2
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 

Recently uploaded (20)

FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 

Unity Framework

  • 2. WHAT IS IT ? • THE UNITY FRAMEWORK OR UNITY APPLICATION BLOCK IS A LIGHTWEIGHT EXTENSIBLE DEPENDENCY INJECTION CONTAINER WITH SUPPORT FOR CONSTRUCTOR, PROPERTY, AND METHOD CALL INJECTION. • IT’S A VERY GOOD WAY TO ACHIEVE LOOSE COUPLING IN THE APPLICATION. LOOSELY COUPLED APPLICATIONS ARE VERY EASY TO MAINTAIN AND TEST. • IT PROVIDES INVERSION OF CONTROL (IOC) FUNCTIONALITY BY ALLOWING INJECTION OF PRECONFIGURED OBJECTS INTO CLASSES BUILT BY THE APPLICATION BLOCK.
  • 3. WHY IOC ? • ASSUME THERE IS A CLASS CALLED "KIDS.CS". THE PURPOSE OF THIS CLASS IS TO MAINTAIN THE NAME AND AGE OF THE CHILDREN OF A SPECIFIC PERSON. • NOW THE REQUIREMENT IS THAT EACH PERSON HAS KIDS. SO AT THE TIME OF CREATION OF A PERSON, THE ASSOCIATED KIDS SHOULD ALSO BE CREATED. SO THIS MAY BE DONE BY THE FOLLOWING CODE.
  • 4.
  • 5.
  • 6. WHY IOC ? • WHEN AN OBJECT NEEDS ANOTHER OBJECT THEN IT IS SAID THAT THE OBJECT IS DEPENDENT ON THE OTHER OBJECT. IN THIS CASE, KID’S CLASS IS DEPENDENT ON PERSON’S CLASS. PROBLEMS IN THE ABOVE APPROACH: • HERE THE KIDS OBJECT HAS BEEN CREATED INSIDE THE CONSTRUCTOR OF THE PERSON CLASS. SO, HERE COUPLING IS VERY HIGH OR TIGHT. • IF DUE TO ANY REASON THE CREATION OF THE KIDS OBJECT FAILS THEN THE PERSON CLASS ALSO CANNOT BE INSTANTIATED IN ITS CONSTRUCTOR ITSELF. • IF THE PERSON OBJECT CLASS IS KILLED THEN BY DEFAULT THE OBJECT OF THE KIDS CLASS IS ALSO KILLED. • IF A NEW TYPE OF KIDS HAS BEEN CREATED OR A NEW PROPERTY IS BEING ADDED IN THE KIDS CLASS THEN IT NEEDS CODE MODIFICATION IN THE PERSON CLASS ALSO.
  • 7. IOC • THE PREVIOUS PROBLEM CAN BE SOLVED IF WE ASSIGN THE TASK OF OBJECT CREATION TO A THIRD PARTY. • SO, ASSIGNING THE TASK OF OBJECT CREATION TO A THIRD-PARTY IS SOMEHOW INVERTING CONTROL TO THE THIRD-PARTY. AND THIS IS CALLED "INVERSION OF CONTROL" (IOC). • IN OTHER WORDS, THE INVERSION OF CONTROL DESIGN PATTERN COULD BE DEFINED AS DELEGATING THE TASK OF OBJECT CREATION TO A THIRD-PARTY, TO DO LOW COUPLING AMONG OBJECTS AND TO MINIMIZE DEPENDENCY AMONG OBJECTS.
  • 8. THE ACTUAL PROCESS Person Class Pass object to Person Inversion of Control Container [ A Third Party Class ] Create object of Kids Class Kids Class
  • 9. IOC SO IOC SAYS: • THE MAIN CLASS (PESRON.CS) COMPOSES ANOTHER CLASS THAT SHOULD NOT DIRECTLY DEPEND ON THE IMPLEMENTATION OF THE OTHER CLASS (KIDS.CS). • THERE SHOULD BE AN ABSTRACTION AMONG CLASSES AND THE CLASSES SHOULD FULLY DEPEND UPON THAT ABSTRACTION. • ABSTRACTION COULD BE EITHER AN INTERFACE OR AN ABSTRACT CLASS.
  • 10. DEPENDENCY INJECTION DEPENDENCY INJECTION IS THE WAY TO IMPLEMENT IOC. IT PROVIDES FOLLOWING BENEFITS: • ELIMINATES TIGHT COUPLING AMONG OBJECTS. • MAKES THE OBJECT AND THE APPLICATION MORE FLEXIBLE. • FACILITATES CREATION OF MORE LOOSELY COUPLED OBJECTS AND THEIR DEPENDENCIES. • ISOLATES IMPLEMENTATION OF AN OBJECT FROM THE CONSTRUCTION OF THE OBJECT ON WHICH IT DEPENDS.
  • 12. CONSTRUCTOR INJECTION • HERE AN OBJECT REFERENCE WOULD BE PASSED TO THE CONSTRUCTOR OF THE BUSINESS CLASS PERSON. • IN THIS CASE, SINCE THE PERSON CLASS DEPENDS ON THE KIDS CLASS, SO THE REFERENCE OF THE KIDS CLASS WILL BE PASSED TO THE CONSTRUCTOR OF THE PERSON CLASS. • SO, AT THE TIME OF OBJECT CREATION OF THE PERSON CLASS, THE KIDS CLASS WILL BE INSTANTIATED. • THE FOLLOWING IS THE PROCEDURE TO IMPLEMENT CONSTRUCTOR INJECTION.
  • 13. CONSTRUCTOR INJECTION • STEP 1: CREATE AN INTERFACE IBUSINESSLOGIC.CS THIS INTERFACE WOULD BE IMPLEMENTED BY A BUSINESS LOGIC CLASS. HERE THE KIDS CLASS IS A BUSINESS LOGIC CLASS. ONLY THE METHODS OF THE INTERFACE WILL BE EXPOSED TO THE BUSINESS LOGIC CLASS (PERSON).
  • 14. { } } • STEP 2: IMPLEMENT AN INTERFACE TO THE KIDS CLASS. AN OBJECT OF THE KIDS CLASS WILL BE REFERENCED BY THE PERSON CLASS. SO THIS CLASS NEEDS TO IMPLEMENT THE INTERFACE.
  • 15. • STEP 3: MAKE A REFERENCE OF THE INTERFACE IN THE PERSON CLASS.
  • 16. • STEP 4: NOW TO CREATE A THIRD-PARTY CLASS WHERE THE CREATION OF THE OBJECT WILL BE DONE. IN THE CODE BELOW IS A FACTORYMETHOD() METHOD WHERE THE OBJECT IS GETTING CREATED.
  • 17. • STEP 5: NOW TO USE A THIRD-PARTY CLASS AT THE CLIENT-SIDE.
  • 18. THE IOC PROCESS IN ONE SHOT Person Class Pass object to Person IOC Class Factory Method IBusinessLogic Create object of Kids Class Kids Class
  • 19. ACHIEVING IOC THROUGH UNITY FRAMEWORK IN MVC4
  • 20. I only have to do all the tasks…. Why did God make me Controller ???   Don’t worry… I’ll handle the object creation… U take care of the rest…  UNITY MVC CONTROLLER WITHOUT UNITY MVC CONTROLLER WITH UNITY
  • 21. PHASES OF OBJECT CREATION • REGISTER - REGISTER THE TYPE OF THE OBJECT THAT HAS TO BE INSTANTIATED WITH UNITY CONTAINER • RESOLVE – LET UNITY CONTAINER KNOW THAT NOW IS THE TIME TO INSTANTIATE THE OBJECT • DISPOSE – GET RID OF THE OBJECT IF ITS ROLE IS OVER
  • 22. ACHIEVING IOC THROUGH UNITY FRAMEWORK IN MVC4 • WE CAN ACHIEVE IOC THROUGH UNITY FRAMEWORK IN 4 SIMPLE STEPS: 1. INSTALL UNITY THROUGH PACKAGE MANAGER CONSOLE. 2. CREATE UNITY CONTAINER IN BOOTSTARPPER .CS FILE. REGISTER THE DEPENDENCIES. 3. INJECT THE DEPENDENCY IN CONTROLLER THROUGH CONSTRUCTOR 4. IN GLOBAL.ASAX.CS , SET UP THE DEPENDENCY INJECTION THROUGH UNITY [CALL BOOTSTRAPPER CLASS]
  • 23. CREATE A NEW ASP.NET MVC 4 APPLICATION
  • 24. GETTING STARTED WITH UNITY FRAMEWORK • UNITY 3.0 COMES UNDER NUGET PACKAGE IN VS2012. TO INSTALL, EXECUTE BELOW COMMAND IN PACKAGE MANAGER CONSOLE: • PM> INSTALL-PACKAGE UNITY.MVC4
  • 25. ADDING REFERENCES • REFERENCES TO THE PROJECT WILL GET AUTOMATICALLY ADDED ONCE WE EXECUTE PM> INSTALL-PACKAGE UNITY.MVC4 IN PACKAGE MANAGER CONSOLE.
  • 26. CREATE A REPOSITORY FOR DATA PRODUCT CLASS INTERFACE FOR PRODUCTREPOSITORY
  • 33. 3 WHYS… • WHY UNITY FRAMEWORK ?  TO IMPLEMENT IOC THROUGH DEPENDENCY INJECTION • WHY IMPLEMENT IOC?  TO ACHIEVE LOOSE COUPLING IN THE APPLICATION • WHY LOOSE COUPLING ?  TO MAKE THE APPLICATION MORE MAINTAINABLE AND TESTABLE • SO, USE OF UNITY FRAMEWORK IN OUR APPLICATION MEANS OUR APPLICATION IS MORE MAINTAINABLE AND TESTABLE.
  • 34. DON’T USE UNITY FRAMEWORK IN FOLLOWING SCENARIOS • YOUR OBJECTS AND CLASSES HAVE NO DEPENDENCIES ON OTHER OBJECTS OR CLASSES. • YOUR DEPENDENCIES ARE VERY SIMPLE AND DO NOT REQUIRE ABSTRACTION.