Workshop is designed to provide a solid understanding of the .NET ecosystem and to introduce powerful concept of Dependency Injection (DI) in software development
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