SlideShare une entreprise Scribd logo
1  sur  46
Télécharger pour lire hors ligne
‫استف‬ ‫با‬ ‫وابستگی‬ ‫تزریق‬‫از‬ ‫اده‬
‫دگر‬۲
‫عباس‬‫اویس‬‫ی‬
http://abbas.oveissi.ir
‫شرکت‬‫هارمس‬
@abbas_oveissi
‫سوال‬
•‫وابستگی‬ ‫تزریق‬ ‫مقدمه‬
•‫دگر‬ ‫با‬ ‫آشنایی‬۲
•‫دامنه‬‫ها‬(Scopes)
•‫توصیه‬‫ها‬
‫فهرست‬
•‫وابستگی‬ ‫تزریق‬ ‫مقدمه‬
•‫دگر‬ ‫با‬ ‫آشنایی‬۲
•‫دامنه‬‫ها‬(Scopes)
•‫توصیه‬‫ها‬
‫فهرست‬
‫چیس‬ ‫وابستگی‬‫ت؟‬
‫وابستگی‬ ‫تزریق‬ ‫مقدمه‬
‫کالس‬A‫کالس‬ ‫به‬B‫است‬ ‫وابسته‬.
‫چیس‬ ‫وابستگی‬‫ت؟‬
‫وابستگی‬ ‫تزریق‬ ‫مقدمه‬
‫کالس‬A‫کالس‬ ‫به‬B‫است‬ ‫وابسته‬.
• Data Provider -> Database
• Image Loader -> HTTP
• REST -> HTTP
• REST -> Deserializer
‫وابستگی‬ ‫تزریق‬(DI)‫چیست؟‬
‫وابستگی‬ ‫تزریق‬ ‫مقدمه‬
ِ‫ق‬‫تزری‬‫وابستگی‬‫در‬‫‌نویسی‬‫ه‬‫برنام‬،‫شیءگرا‬‫الگوی‬‫طراحیست‬‫با‬‫قاعده‬‫‌ی‬ِ‫ی‬‫اصل‬
‌ِ‫ن‬‫جداکرد‬‫رفتار‬‫از‬‌ِ‫ل‬‫تحلی‬‫نیازمندی‬‫فنی‬‫برای‬ِ‫ن‬‫‌کرد‬‫ه‬‫تجزی‬‌ِ‫ی‬‫‌ها‬‫ه‬‫مؤلف‬‫بس‬‫یار‬‌ِ‫ل‬‫مستق‬
‫‌افزاری‬‫م‬‫نر‬.–‫ویکیپدیا‬‫فارسی‬
‫وابستگی‬ ‫تزریق‬(DI)‫چیست؟‬
‫وابستگی‬ ‫تزریق‬ ‫مقدمه‬
‫وابستگی‬ ‫تزریق‬ ‫مقدمه‬
Vs.
‫معکوس‬ ‫وابستگی‬ ‫اصل‬(DIP)‫چیست؟‬
‫وابستگی‬ ‫تزریق‬ ‫مقدمه‬
DIP
‫وابستگی‬ ‫تزریق‬ ‫مقدمه‬
•‫گذاشتن‬ ‫اشتراک‬ ‫به‬‫وابستگی‬‫ها‬
•‫بین‬ ‫اتصال‬ ‫شدن‬ ‫سست‬‫بخش‬‫های‬‫کد‬ ‫مختلف‬(loosely coupled)
•‫قابلیت‬ ‫بردن‬ ‫باال‬‫تست‬‫پذیری‬
‫الگوی‬ ‫از‬ ‫استفاده‬ ‫دالیل‬DI
‫وابستگی‬ ‫تزریق‬ ‫مقدمه‬
•‫بصورت‬‫دستی‬
•‫یادگیری‬ ‫به‬ ‫نیاز‬‫فریم‬‫ورک‬‫نیست‬
•‫بصورت‬‫از‬ ‫استفاده‬ ‫با‬ ‫خودکار‬‫فریم‬‫ورک‬‫ها‬
•‫کمتر‬ ‫نوشتن‬ ‫کد‬
•‫در‬ ‫یکپارچگی‬‫پیاده‬‫سازی‬
‫پیاده‬‫سازی‬‫الگوی‬DI
•‫وابستگی‬ ‫تزریق‬ ‫مقدمه‬
•‫دگر‬ ‫با‬ ‫آشنایی‬۲
•‫دامنه‬‫ها‬(Scopes)
•‫توصیه‬‫ها‬
‫فهرست‬
‫دگر‬ ‫مفاهیم‬ ‫با‬ ‫آشنایی‬۲
•‫دگر‬ ‫تفاوت‬۱‫دگر‬ ‫با‬۲
•‫دگر‬ ‫مزایای‬۲
•‫از‬ ‫نکردن‬ ‫استفاده‬reflection
•‫کد‬ ‫تولید‬‫باال‬ ‫خوانایی‬ ‫قابلیت‬ ‫با‬
•‫زمان‬ ‫در‬ ‫خطا‬ ‫تشخیص‬ ‫امکان‬‫کامپایل‬
‫فریم‬‫ورک‬‫دگر‬۲
‫دگر‬ ‫مفاهیم‬ ‫با‬ ‫آشنایی‬۲
•‫لیست‬ ‫دریافت‬‫فیلم‬‫ها‬‫سرور‬ ‫از‬
•‫کردن‬ ‫ذخیره‬‫لیست‬‫ها‬‫کش‬ ‫در‬
•‫س‬ ‫به‬ ‫نسبت‬ ‫کش‬ ‫از‬ ‫لیست‬ ‫دریافت‬ ‫داشتن‬ ‫اولویت‬‫رور‬
‫مثال‬:‫اپلیکیشن‬‫لیست‬ ‫نمایش‬‫فیلم‬‫ه‬‫ا‬
‫دگر‬ ‫مفاهیم‬ ‫با‬ ‫آشنایی‬۲
.‫شناسایی‬ ۱‫وابستگی‬‫ها‬‫آنها‬ ‫کردن‬ ‫فراهم‬ ‫و‬
•‫از‬ ‫استفاده‬@Module‫و‬@Provide
.‫در‬ ‫وابستگی‬ ‫درخواست‬ ۲‫کالس‬‫های‬‫وابسته‬
•‫از‬ ‫استفاده‬@Inject
.‫تزریق‬ 3‫وابستگی‬‫ها‬
•‫از‬ ‫استفاده‬@Component
‫دگر‬ ‫از‬ ‫استفاده‬ ‫مراحل‬۲
‫دگر‬ ‫مفاهیم‬ ‫با‬ ‫آشنایی‬۲
•‫کالس‬ ‫ساخت‬‫ماژول‬‫کردن‬ ‫فراهم‬ ‫برای‬‫وابستگی‬‫ها‬
•‫از‬ ‫استفاده‬@Module‫کالس‬ ‫برای‬
•‫از‬ ‫استفاده‬@Provides‫برای‬‫متد‬‫ها‬
‫مرحله‬‫ی‬‫اول‬-‫شناسایی‬‫وابستگی‬‫ها‬‫و‬‫آنها‬ ‫کردن‬ ‫فراهم‬
‫دگر‬ ‫مفاهیم‬ ‫با‬ ‫آشنایی‬۲
‫دگر‬ ‫مفاهیم‬ ‫با‬ ‫آشنایی‬۲
‫دگر‬ ‫مفاهیم‬ ‫با‬ ‫آشنایی‬۲
‫دگر‬ ‫مفاهیم‬ ‫با‬ ‫آشنایی‬۲
‫دگر‬ ‫مفاهیم‬ ‫با‬ ‫آشنایی‬۲
‫دگر‬ ‫مفاهیم‬ ‫با‬ ‫آشنایی‬۲
•‫سازنده‬ ‫تزریق‬
•‫فیلد‬ ‫تزریق‬
•‫متد‬ ‫تزریق‬*
‫مرحله‬‫ی‬‫دوم‬-‫در‬ ‫وابستگی‬ ‫درخواست‬‫کالس‬‫های‬‫وابسته‬
‫دگر‬ ‫مفاهیم‬ ‫با‬ ‫آشنایی‬۲
•‫سازنده‬ ‫تزریق‬
•‫باشد‬ ‫کالس‬ ‫کد‬ ‫به‬ ‫دسترسی‬ ‫امکان‬ ‫باید‬
‫دگر‬ ‫مفاهیم‬ ‫با‬ ‫آشنایی‬۲
•‫فیلد‬ ‫تزریق‬
‫دگر‬ ‫مفاهیم‬ ‫با‬ ‫آشنایی‬۲
•‫ساخت‬‫اینترفیس‬‫کامپوننت‬
•‫بین‬ ‫پل‬‫ماژول‬‫ها‬‫و‬‫کالس‬‫های‬‫وابسته‬
•‫کننده‬ ‫تزریق‬
•‫کننده‬ ‫مدیریت‬‫دامنه‬‫ها‬
‫مرحله‬‫ی‬‫سوم‬-‫تزریق‬‫وابستگی‬‫ها‬
‫دگر‬ ‫مفاهیم‬ ‫با‬ ‫آشنایی‬۲
‫دگر‬ ‫مفاهیم‬ ‫با‬ ‫آشنایی‬۲
‫دگر‬ ‫مفاهیم‬ ‫با‬ ‫آشنایی‬۲
•‫وابستگی‬ ‫تزریق‬ ‫مقدمه‬
•‫دگر‬ ‫با‬ ‫آشنایی‬۲
•‫دامنه‬‫ها‬(Scopes)
•‫توصیه‬‫ها‬
‫فهرست‬
‫دامنه‬‫ها‬(Scopes)
‫دامنه‬‫ها‬(Scopes)
‫دامنه‬‫ها‬(Scopes)
•‫ماهیت‬ ‫بودن‬ ‫یکسان‬@Singleton‫با‬‫دامنه‬‫های‬‫سفارشی‬
•‫کاربرد‬‫دامنه‬‫های‬‫در‬ ‫سفارشی‬‫صحت‬‫سنجی‬‫کد‬
•‫دامنه‬‫ی‬@Reusable
‫دامنه‬‫ها‬(Scopes)
•‫از‬ ‫استفاده‬@Singleton
‫دامنه‬‫ها‬(Scopes)
•‫دامنه‬‫های‬‫سفارشی‬
‫دامنه‬‫ها‬(Scopes)
•‫بین‬ ‫اتصال‬‫دامنه‬‫های‬‫مختلف‬
•‫بین‬ ‫وابستگی‬ ‫از‬ ‫استفاده‬‫کامپوننت‬‫ها‬
•‫از‬ ‫استفاده‬SubComponent
‫دامنه‬‫ها‬(Scopes)
•‫بین‬ ‫وابستگی‬ ‫از‬ ‫استفاده‬‫کامپونن‬‫ت‬‫ها‬
‫دامنه‬‫ها‬(Scopes)
•‫بین‬ ‫وابستگی‬ ‫از‬ ‫استفاده‬‫کامپونن‬‫ت‬‫ها‬
‫دامنه‬‫ها‬(Scopes)
•‫از‬ ‫استفاده‬SubComponent
‫دامنه‬‫ها‬(Scopes)
•‫از‬ ‫استفاده‬SubComponent
•‫وابستگی‬ ‫تزریق‬ ‫مقدمه‬
•‫دگر‬ ‫با‬ ‫آشنایی‬۲
•‫دامنه‬‫ها‬(Scopes)
•‫توصیه‬‫ها‬
‫فهرست‬
‫توصیه‬‫ها‬
•‫از‬ ‫استفاده‬‫متد‬‫های‬‫استاتیک‬‫به‬‫جای‬‫متد‬‫های‬‫معمولی‬
•‫تعداد‬ ‫تشخیص‬ ‫چگونگی‬‫ماژول‬‫ها‬‫و‬‫کامپوننت‬‫ها‬
•‫نحوه‬‫ی‬‫از‬ ‫استفاده‬ ‫بین‬ ‫انتخاب‬@Subcomponent‫وابستگی‬ ‫و‬
‫کامپوننتی‬
‫توصیه‬‫ها‬
•‫از‬ ‫استفاده‬@Binds
‫توصیه‬‫ها‬
•‫پکیج‬dagger.android
•‫از‬ ‫استفاده‬@BindInstance
‫سوال‬

Contenu connexe

En vedette

Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationErica Santiago
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellSaba Software
 

En vedette (20)

Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
 

Dependency Injection with Dagger 2