Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Tools and Skills for .NET 8

You're reading from   Tools and Skills for .NET 8 Get the career you want with good practices and patterns to design, debug, and test your solutions 

Arrow left icon
Product type Paperback
Published in Jul 2024
Publisher Packt
ISBN-13 9781837635207
Length 778 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Mark J. Price Mark J. Price
Author Profile Icon Mark J. Price
Mark J. Price
Arrow right icon
View More author details
Toc

Table of Contents (22) Chapters Close

Preface 1. Introducing Tools and Skills for .NET 2. Making the Most of the Tools in Your Code Editor FREE CHAPTER 3. Source Code Management Using Git 4. Debugging and Memory Troubleshooting 5. Logging, Tracing, and Metrics for Observability 6. Documenting Your Code, APIs, and Services 7. Observing and Modifying Code Execution Dynamically 8. Protecting Data and Apps Using Cryptography 9. Building an LLM-Based Chat Service 10. Dependency Injection, Containers, and Service Lifetime 11. Unit Testing and Mocking 12. Integration and Security Testing 13. Benchmarking Performance, Load, and Stress Testing 14. Functional and End-to-End Testing of Websites and Services 15. Containerization Using Docker 16. Cloud-Native Development Using .NET Aspire 17. Design Patterns and Principles 18. Software and Solution Architecture Foundations 19. Your Career, Teamwork, and Interviews 20. Epilogue 21. Index

DI with ASP.NET Core

The most common project type that uses DI extensively is an ASP.NET Core project. In this section, we will look at some of the special cases of DI when building web apps and services.

Registering services for features using extension methods

With a complex ASP.NET Core project, you are likely to need to register many related services for each feature of the website or web service in Program.cs, as shown in the following code:

builder.Services.AddScoped<IShoppingCart, InMemoryShoppingCart>();
builder.Services.AddScoped<ICustomerAccount, CustomerAccount>();
builder.Services.AddScoped<IUserRegistration, UserRegistration>();

It is good practice to define an extension method to group all these registrations, as shown in the following code:

public static class ServiceCollectionExtensions
{
  public static IServiceCollection AddNorthwindFeatures(
    this IServiceCollection services)
  {
    services.AddScoped<IShoppingCart,...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at ₹800/month. Cancel anytime