SlideShare a Scribd company logo
1 of 16
.NET 6 & Power Platform
Workshops
Workshop 1
.NET Intro &
Dependency Injection
.NET Framework/Standard/Core/5-7x
.NET Core is a free, open source, released under the MIT license cross-platform
framework maybe used to create a variety of apps, including mobile, desktop, cloud, IoT,
games, etc.
 Modular framework distributed as NuGet packages
 Host-agnostic via Open Web Interface for .NET (OWIN) support
 A cloud-ready environment-based configuration system
 A light-weight and modular HTTP request pipeline
 Build and run cross-platform ASP.NET Core apps on Windows, Mac, and Linux
 In-built support for dependency injection, logging, caching, etc.
Intro
>> Features
.NET Framework/Standard/Core/5-7x
Release History
Version Release Date End of Support
.NET Core 1.0 2016-06-27 2019-06-27
.NET Core 1.1 2016-11-18 2019-06-27
.NET Core 2.0 2017-08-14 2018-10-01
.NET Core 2.1 2018-05-30 2021-08-21
.NET Core 2.2 2018-12-04 2019-12-23
.NET Core 3.0 2019-09-23 2020-03-03
.NET Core 3.1 2019-12-03 2022-12-03
.NET 5.0 2020-11-10 2022-05-08
.NET 6.0 2021-11-08 2024-11-08
.NET Framework/Standard/Core/5-7x
.NET Framework/Core Ecosystem
.NET Framework/Standard/Core/5-7x
.NET 5/6 Ecosystem
.NET Framework/Standard/Core/5-7x
.NET 6 Features
 Hot reload
 C# 10 features and new/modified project templates
 Performance improvements in FileStream, System.Text.Json
 Writeable DOM
 IAsyncEnumerable serialization/deserialization
 HTTP/3 preview support
 OpenTelemetry support
 NuGet package validation
.NET Framework/Standard/Core/5-7x
Frameworks Differences
Feature .NET Core .NET Framework
Open-Source Fully open-source
Includes certain open-sources
components
Cross-Platform Runs on Windows, Linux, macOS Runs only on Windows
Application
Models
Web, mobile, Windows Universal
App
WinForms, ASP.NET, WPF
Installation
Single package installation
independently of the underlying
OS
Single package installation for Windows
OS
Performance High performance and scalability
Less effective in terms of performance
and scalability
Packaging
Shipped as a collection of NuGet
packages
All the libraries are packaged and
shipped together
CLI Tools
Provides CLI tools for all supported
platforms
No CLI tools provided from out of the
box
.NET Framework/Standard/Core/5-7x
Prefer or Choose
 The project demands cross-platform integration
 The project requires the development of microservices
 Project relies heavily on CLI
 Working with Docker containers
 High-performance and scalable system needs
 You are running multiple .NET versions side-by-side
 Applications are already running on .NET Framework
 The Applications require technologies like ASP.NET WinForms, ASP.NET WebForms, WWF, or
WCF that are not present in .NET Core
 Applications are built to run on Windows alone
.NET Core/5-7
.NET Framework 4.x
.NET Dependency Injection
Inversion of Control is a principle in software engineering which transfers the control of
objects or portions of a program to a container or framework
Intro
Inversion of Control
Dependency Injection
Dependency Injection is a design pattern in software engineering in which an object
receives another object that it depends on
Dependency Inversion
Dependency Inversion is a design principle in software engineering which means we
should not depend on low-level implementations, but rather rely on high-level
abstractions
Service Locator
Service Locator is a design pattern used in software engineering to encapsulate the
processes involved in obtaining a service with a strong abstraction layer
.NET Dependency Injection
Types of Dependency Injection
Constructor Injection
Constructor injection is the process of using the constructor and its arguments to pass
the required dependencies into the dependent object
Property Injection
Property injection is the process of using the property and maybe an attribute to pass
the optional dependency into the dependent object
Method Injection
Method injection is the process of using the method and its arguments to pass
the dependencies into the dependent object
.NET Dependency Injection
IServiceProvider
IServiceScope
IServiceScopeFactory
The main interface, through which is able to retrieve the implementation of a service
registered with the container
A factory for creating instances of IServiceScope
Abstractions
Provides with a scoped container that will be disposed by the end of the request or
execution block
ServiceDescriptor
Describes a service with its service type, implementation, and lifetime
.NET Dependency Injection
Life Time Scopes
Scope Life Time Description Pros & Cons
Transient
Creates a new instance
every time
The service state could
be calculated on the fly
 Not memory
efficient
 No memory leaks
 Thread safety
Scoped
Create a single instance
per request and shares
it within the request
The service state
relates to the request
or context, and needs
to be shared between
depending services
 Maintains the state
beyond the request
Singleton
Creates a single
instance and shared it
across the application
The service state is a
global and could be
shared between all
services
 Memory leaks
 No thread safety
 Memory efficient
.NET Dependency Injection
Service Design
 Avoid stateful, static classes and members
 Avoid creating global state by designing apps to use singleton services instead
 Avoid direct instantiation of dependent classes within services
 async/await and Task based service resolution isn't supported. Because C#
doesn't support asynchronous constructors, use asynchronous methods after
synchronously resolving the service
 Avoid using the Service Locator pattern
 Disposable transient services are captured by the container for disposal. This can
turn into a memory leak if resolved from the top-level container
 Enable scope validation to make sure the app doesn't have singletons that capture
scoped services
.NET Dependency Injection
Unsupported Features
 Property injection
 Resolving a service with some associated metadata
 Defined Named/Keyed variants of a service
 Child containers
 Custom lifetime management
 Lazy initialization
 Dynamic instantiation
 Thread lifetime scope
 Wise validation
.NET Dependency Injection
Third Party Libraries
 Autofac
 DryIoc
 Grace
 LightInject
 Lamar
 Stashbox
 Unity
 Simple Injector

More Related Content

Similar to .NET Intro & Dependency Injection Workshop

Cloud compiler - Minor Project by students of CBPGEC
Cloud compiler - Minor Project by students of CBPGEC  Cloud compiler - Minor Project by students of CBPGEC
Cloud compiler - Minor Project by students of CBPGEC vipin kumar
 
Getting started with dotnet core Web APIs
Getting started with dotnet core Web APIsGetting started with dotnet core Web APIs
Getting started with dotnet core Web APIsKnoldus Inc.
 
PCF: Platform for a New Era - Kubernetes for the Enterprise - London
PCF: Platform for a New Era - Kubernetes for the Enterprise - LondonPCF: Platform for a New Era - Kubernetes for the Enterprise - London
PCF: Platform for a New Era - Kubernetes for the Enterprise - LondonVMware Tanzu
 
Syn framework 4.0 and sql server
Syn framework 4.0 and sql serverSyn framework 4.0 and sql server
Syn framework 4.0 and sql serverEduardo Castro
 
VMworld 2013: NSX PCI Reference Architecture Workshop Session 3 - Operational...
VMworld 2013: NSX PCI Reference Architecture Workshop Session 3 - Operational...VMworld 2013: NSX PCI Reference Architecture Workshop Session 3 - Operational...
VMworld 2013: NSX PCI Reference Architecture Workshop Session 3 - Operational...VMworld
 
2020-02-10 Java on Azure Solution Briefing
2020-02-10 Java on Azure Solution Briefing2020-02-10 Java on Azure Solution Briefing
2020-02-10 Java on Azure Solution BriefingEd Burns
 
Net Fundamentals
Net FundamentalsNet Fundamentals
Net FundamentalsAli Taki
 
Azure Service Fabric - Hamida Rebai - CCDays
Azure Service Fabric - Hamida Rebai - CCDaysAzure Service Fabric - Hamida Rebai - CCDays
Azure Service Fabric - Hamida Rebai - CCDaysCodeOps Technologies LLP
 
D22 Portlet Development With Open Source Frameworks
D22 Portlet Development With Open Source FrameworksD22 Portlet Development With Open Source Frameworks
D22 Portlet Development With Open Source FrameworksSunil Patil
 
D22 portlet development with open source frameworks
D22 portlet development with open source frameworksD22 portlet development with open source frameworks
D22 portlet development with open source frameworksSunil Patil
 
Service fabric and azure service fabric mesh
Service fabric and azure service fabric meshService fabric and azure service fabric mesh
Service fabric and azure service fabric meshMikkel Mørk Hegnhøj
 
Best of Microsoft Dev Camp 2015
Best of Microsoft Dev Camp 2015Best of Microsoft Dev Camp 2015
Best of Microsoft Dev Camp 2015Bluegrass Digital
 
Building and Deploying a Static Application using Jenkins and Docker in AWS
Building and Deploying a Static Application using Jenkins and Docker in AWSBuilding and Deploying a Static Application using Jenkins and Docker in AWS
Building and Deploying a Static Application using Jenkins and Docker in AWSijtsrd
 
Framework adoption for java enterprise application development
Framework adoption for java enterprise application developmentFramework adoption for java enterprise application development
Framework adoption for java enterprise application developmentClarence Ho
 
Exploring .NET Remoting and Distributed Applications in .NET Framework .pdf
Exploring .NET Remoting and Distributed Applications in .NET Framework .pdfExploring .NET Remoting and Distributed Applications in .NET Framework .pdf
Exploring .NET Remoting and Distributed Applications in .NET Framework .pdfTyrion Lannister
 
Comparison of Current Service Mesh Architectures
Comparison of Current Service Mesh ArchitecturesComparison of Current Service Mesh Architectures
Comparison of Current Service Mesh ArchitecturesMirantis
 
.Net: Introduction, trends and future
.Net: Introduction, trends and future.Net: Introduction, trends and future
.Net: Introduction, trends and futureBishnu Rawal
 
GIDS 2019: Developing Apps with Containers, Functions and Cloud Services
GIDS 2019: Developing Apps with Containers, Functions and Cloud ServicesGIDS 2019: Developing Apps with Containers, Functions and Cloud Services
GIDS 2019: Developing Apps with Containers, Functions and Cloud ServicesPatrick Chanezon
 

Similar to .NET Intro & Dependency Injection Workshop (20)

Cloud compiler - Minor Project by students of CBPGEC
Cloud compiler - Minor Project by students of CBPGEC  Cloud compiler - Minor Project by students of CBPGEC
Cloud compiler - Minor Project by students of CBPGEC
 
Getting started with dotnet core Web APIs
Getting started with dotnet core Web APIsGetting started with dotnet core Web APIs
Getting started with dotnet core Web APIs
 
PCF: Platform for a New Era - Kubernetes for the Enterprise - London
PCF: Platform for a New Era - Kubernetes for the Enterprise - LondonPCF: Platform for a New Era - Kubernetes for the Enterprise - London
PCF: Platform for a New Era - Kubernetes for the Enterprise - London
 
Syn framework 4.0 and sql server
Syn framework 4.0 and sql serverSyn framework 4.0 and sql server
Syn framework 4.0 and sql server
 
VMworld 2013: NSX PCI Reference Architecture Workshop Session 3 - Operational...
VMworld 2013: NSX PCI Reference Architecture Workshop Session 3 - Operational...VMworld 2013: NSX PCI Reference Architecture Workshop Session 3 - Operational...
VMworld 2013: NSX PCI Reference Architecture Workshop Session 3 - Operational...
 
.net Framework
.net Framework.net Framework
.net Framework
 
Struts Interceptors
Struts InterceptorsStruts Interceptors
Struts Interceptors
 
2020-02-10 Java on Azure Solution Briefing
2020-02-10 Java on Azure Solution Briefing2020-02-10 Java on Azure Solution Briefing
2020-02-10 Java on Azure Solution Briefing
 
Net Fundamentals
Net FundamentalsNet Fundamentals
Net Fundamentals
 
Azure Service Fabric - Hamida Rebai - CCDays
Azure Service Fabric - Hamida Rebai - CCDaysAzure Service Fabric - Hamida Rebai - CCDays
Azure Service Fabric - Hamida Rebai - CCDays
 
D22 Portlet Development With Open Source Frameworks
D22 Portlet Development With Open Source FrameworksD22 Portlet Development With Open Source Frameworks
D22 Portlet Development With Open Source Frameworks
 
D22 portlet development with open source frameworks
D22 portlet development with open source frameworksD22 portlet development with open source frameworks
D22 portlet development with open source frameworks
 
Service fabric and azure service fabric mesh
Service fabric and azure service fabric meshService fabric and azure service fabric mesh
Service fabric and azure service fabric mesh
 
Best of Microsoft Dev Camp 2015
Best of Microsoft Dev Camp 2015Best of Microsoft Dev Camp 2015
Best of Microsoft Dev Camp 2015
 
Building and Deploying a Static Application using Jenkins and Docker in AWS
Building and Deploying a Static Application using Jenkins and Docker in AWSBuilding and Deploying a Static Application using Jenkins and Docker in AWS
Building and Deploying a Static Application using Jenkins and Docker in AWS
 
Framework adoption for java enterprise application development
Framework adoption for java enterprise application developmentFramework adoption for java enterprise application development
Framework adoption for java enterprise application development
 
Exploring .NET Remoting and Distributed Applications in .NET Framework .pdf
Exploring .NET Remoting and Distributed Applications in .NET Framework .pdfExploring .NET Remoting and Distributed Applications in .NET Framework .pdf
Exploring .NET Remoting and Distributed Applications in .NET Framework .pdf
 
Comparison of Current Service Mesh Architectures
Comparison of Current Service Mesh ArchitecturesComparison of Current Service Mesh Architectures
Comparison of Current Service Mesh Architectures
 
.Net: Introduction, trends and future
.Net: Introduction, trends and future.Net: Introduction, trends and future
.Net: Introduction, trends and future
 
GIDS 2019: Developing Apps with Containers, Functions and Cloud Services
GIDS 2019: Developing Apps with Containers, Functions and Cloud ServicesGIDS 2019: Developing Apps with Containers, Functions and Cloud Services
GIDS 2019: Developing Apps with Containers, Functions and Cloud Services
 

Recently uploaded

Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 

Recently uploaded (20)

Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 

.NET Intro & Dependency Injection Workshop

  • 1. .NET 6 & Power Platform Workshops
  • 2. Workshop 1 .NET Intro & Dependency Injection
  • 3. .NET Framework/Standard/Core/5-7x .NET Core is a free, open source, released under the MIT license cross-platform framework maybe used to create a variety of apps, including mobile, desktop, cloud, IoT, games, etc.  Modular framework distributed as NuGet packages  Host-agnostic via Open Web Interface for .NET (OWIN) support  A cloud-ready environment-based configuration system  A light-weight and modular HTTP request pipeline  Build and run cross-platform ASP.NET Core apps on Windows, Mac, and Linux  In-built support for dependency injection, logging, caching, etc. Intro >> Features
  • 4. .NET Framework/Standard/Core/5-7x Release History Version Release Date End of Support .NET Core 1.0 2016-06-27 2019-06-27 .NET Core 1.1 2016-11-18 2019-06-27 .NET Core 2.0 2017-08-14 2018-10-01 .NET Core 2.1 2018-05-30 2021-08-21 .NET Core 2.2 2018-12-04 2019-12-23 .NET Core 3.0 2019-09-23 2020-03-03 .NET Core 3.1 2019-12-03 2022-12-03 .NET 5.0 2020-11-10 2022-05-08 .NET 6.0 2021-11-08 2024-11-08
  • 7. .NET Framework/Standard/Core/5-7x .NET 6 Features  Hot reload  C# 10 features and new/modified project templates  Performance improvements in FileStream, System.Text.Json  Writeable DOM  IAsyncEnumerable serialization/deserialization  HTTP/3 preview support  OpenTelemetry support  NuGet package validation
  • 8. .NET Framework/Standard/Core/5-7x Frameworks Differences Feature .NET Core .NET Framework Open-Source Fully open-source Includes certain open-sources components Cross-Platform Runs on Windows, Linux, macOS Runs only on Windows Application Models Web, mobile, Windows Universal App WinForms, ASP.NET, WPF Installation Single package installation independently of the underlying OS Single package installation for Windows OS Performance High performance and scalability Less effective in terms of performance and scalability Packaging Shipped as a collection of NuGet packages All the libraries are packaged and shipped together CLI Tools Provides CLI tools for all supported platforms No CLI tools provided from out of the box
  • 9. .NET Framework/Standard/Core/5-7x Prefer or Choose  The project demands cross-platform integration  The project requires the development of microservices  Project relies heavily on CLI  Working with Docker containers  High-performance and scalable system needs  You are running multiple .NET versions side-by-side  Applications are already running on .NET Framework  The Applications require technologies like ASP.NET WinForms, ASP.NET WebForms, WWF, or WCF that are not present in .NET Core  Applications are built to run on Windows alone .NET Core/5-7 .NET Framework 4.x
  • 10. .NET Dependency Injection Inversion of Control is a principle in software engineering which transfers the control of objects or portions of a program to a container or framework Intro Inversion of Control Dependency Injection Dependency Injection is a design pattern in software engineering in which an object receives another object that it depends on Dependency Inversion Dependency Inversion is a design principle in software engineering which means we should not depend on low-level implementations, but rather rely on high-level abstractions Service Locator Service Locator is a design pattern used in software engineering to encapsulate the processes involved in obtaining a service with a strong abstraction layer
  • 11. .NET Dependency Injection Types of Dependency Injection Constructor Injection Constructor injection is the process of using the constructor and its arguments to pass the required dependencies into the dependent object Property Injection Property injection is the process of using the property and maybe an attribute to pass the optional dependency into the dependent object Method Injection Method injection is the process of using the method and its arguments to pass the dependencies into the dependent object
  • 12. .NET Dependency Injection IServiceProvider IServiceScope IServiceScopeFactory The main interface, through which is able to retrieve the implementation of a service registered with the container A factory for creating instances of IServiceScope Abstractions Provides with a scoped container that will be disposed by the end of the request or execution block ServiceDescriptor Describes a service with its service type, implementation, and lifetime
  • 13. .NET Dependency Injection Life Time Scopes Scope Life Time Description Pros & Cons Transient Creates a new instance every time The service state could be calculated on the fly  Not memory efficient  No memory leaks  Thread safety Scoped Create a single instance per request and shares it within the request The service state relates to the request or context, and needs to be shared between depending services  Maintains the state beyond the request Singleton Creates a single instance and shared it across the application The service state is a global and could be shared between all services  Memory leaks  No thread safety  Memory efficient
  • 14. .NET Dependency Injection Service Design  Avoid stateful, static classes and members  Avoid creating global state by designing apps to use singleton services instead  Avoid direct instantiation of dependent classes within services  async/await and Task based service resolution isn't supported. Because C# doesn't support asynchronous constructors, use asynchronous methods after synchronously resolving the service  Avoid using the Service Locator pattern  Disposable transient services are captured by the container for disposal. This can turn into a memory leak if resolved from the top-level container  Enable scope validation to make sure the app doesn't have singletons that capture scoped services
  • 15. .NET Dependency Injection Unsupported Features  Property injection  Resolving a service with some associated metadata  Defined Named/Keyed variants of a service  Child containers  Custom lifetime management  Lazy initialization  Dynamic instantiation  Thread lifetime scope  Wise validation
  • 16. .NET Dependency Injection Third Party Libraries  Autofac  DryIoc  Grace  LightInject  Lamar  Stashbox  Unity  Simple Injector