Tools and Skills for .NET 8 - Mark J. Price - E-Book

Tools and Skills for .NET 8 E-Book

Mark J. Price

0,0
34,79 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.
Mehr erfahren.
Beschreibung

Unlock the full potential of .NET development with Tools and Skills for .NET 8.

Dive into source code management using Git and learn how to navigate projects while ensuring version control. Discover advanced debugging techniques and troubleshooting strategies to identify and resolve issues, and gain practical insights on documenting your code, APIs, and services, fostering project clarity and maintainability. Delve into the world of cryptography, ensuring confidentiality and integrity throughout your development lifecycle.

Elevate your skills as you explore cutting-edge topics such as building intelligent apps using custom LLM-based chat services, mastering dependency injection, optimizing performance through testing, and Docker containerization. Harness the power of cloud-native development with .NET Aspire, unlocking the benefits of modern cloud platforms. With guidance on software architecture best practices, this book empowers you to build robust, scalable and maintainable applications.

Advance your career with invaluable insights on job readiness and interview preparation, positioning yourself as a top-tier candidate in today's competitive job market.

Whether you're a seasoned .NET professional or an aspiring developer looking to enhance your skills, this book is your ultimate companion on the journey to .NET mastery.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB
MOBI

Seitenzahl: 1038

Veröffentlichungsjahr: 2024

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Tools and Skills for .NET 8

Get the career you want with good practices and patterns to design, debug, and test your solutions

Mark J. Price

Tools and Skills for .NET 8

Copyright © 2024 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

Senior Publishing Product Manager: Suman Sen

Acquisition Editor – Peer Reviews: Jane D’Souza

Project Editor: Janice Gonsalves

Content Development Editor: Rebecca Youé

Copy Editor: Safis Editing

Technical Editors: Kushal Sharma & Anirudh Singh

Proofreader: Safis Editing

Indexer: Hemangini Bari

Presentation Designer: Ajay Patule

Developer Relations Marketing Executive: Priyadarshini Sharma

First published: July 2024

Production reference: 1020724

Published by Packt Publishing Ltd.

Grosvenor House

11 St Paul’s Square

Birmingham

B3 1RB, UK.

ISBN 978-1-83763-520-7

www.packt.com

Contributors

About the author

Mark J. Price is a Microsoft Specialist: Programming in C# and architecting Microsoft Azure solutions, with over 30 years of experience. Since 1993, he has passed more than 80 Microsoft programming exams and specializes in preparing others to pass them. Between 2001 and 2003, Mark was employed to write official courseware for Microsoft in Redmond, USA. His team wrote the first training courses for C# while it was still an early alpha version. While with Microsoft, he taught “train-the-trainer” classes to get Microsoft Certified Trainers up to speed on C# and .NET. Mark has spent most of his career training a wide variety of students from 16-year-old apprentices to 70-year-old retirees, with the majority being professional developers. Mark holds a Computer Science BSc. Hons. degree.

Thank you to all my readers. Your support means I get to write these books and celebrate your successes. Special thanks to the readers who give me actionable feedback via my GitHub repository and email, and interact with me and the book communities on Discord. You help make my books even better with every edition.

About the reviewers

Kieran Foot is a self taught C# developer with a deep passion for learning new technologies and techniques. He is constantly exploring the latest development in C# and the .NET SDK with particular focus on web development. As the lead software developer at ConnX Business Solutions, a small software company based in the UK, he has the opportunity to apply his knowledge in practice and to assist others in acquiring new skills. He enjoys helping others on their C#/.NET journey and as such is an active member of the Packt Discord community (why not scan the QR code on the next page and chat with him?).

Milan Jovanović is a Microsoft MVP and has worked in the industry for more than seven years. He was a software architect at his last company. Today, he’s a full-time content creator helping .NET developers improve their software architecture and design skills. He specializes in web application development and is an enthusiast of Domain-Driven Design.

Milan has previously worked as a technical editor on Clean Architecture with .NET (ISBN: 9780138203368).

I want to thank my beautiful wife, Milica, who has always been there to support me. I love you, Miko!

Special thanks to my amazing parents, who have given me everything. I could never repay you, but I will keep trying.

A big thank you to Mark Price, the author of this book, whose books are incredibly informative, and I enjoy reading them very much.

Join our book’s Discord space

Read this book alongside other users, and the author himself.

Ask questions, provide solutions for other readers, chat with the author via Ask Me Anything sessions, and much more.

https://packt.link/TS1e

Contents

Preface

Where to find the code solutions

What this book covers

What you need for this book

Get in touch

Introducing Tools and Skills for .NET

Introducing this book and its contents

Companion books to complete your learning journey

Audiences for this book

Tools

Skills

Testing

Design and career development

Setting up your development environment

Choosing the appropriate tool and application type for learning

Using Visual Studio for general development

Using Code for cross-platform development

Using GitHub Codespaces for development in the cloud

Using Rider for cross-platform development

What I used

Deploying cross-platform

Downloading and installing Visual Studio

Visual Studio keyboard shortcuts

Visual Studio Enterprise edition tools

Downloading and installing Code

Installing other extensions

Managing Code extensions at the command prompt

Understanding Code versions

Code keyboard shortcuts

Downloading and installing Rider

Other JetBrains tools

Chrome AI tools

Making good use of the GitHub repository for this book

Raising issues with the book

Giving me feedback

Downloading solution code from the GitHub repository

Where to go for help

Reading documentation on Microsoft Learn

Getting help for the dotnet tool

LLMs like ChatGPT

Getting better help from LLMs using prompt engineering

AI usage by developers

Getting help on Discord and other chat forums

Setting up a database and projects for this book

Using a sample relational database

Setting up SQL Server and the Northwind database

Creating the Northwind database for a local SQL Server

Creating the Northwind database for SQL Edge in Docker

Creating a class library for entity models using SQL Server

Creating a class library for the data context using SQL Server

Creating a test project to check the integration of the class libraries

Running tests

Using .NET 9 with this book

Practicing and exploring

Exercise 1.1 – Online-only material

Exercise 1.2 – Practice exercises

Exercise 1.3 – Test your knowledge

Exercise 1.4 – Explore topics

Summary

Join our book’s Discord space

Making the Most of the Tools in Your Code Editor

Introducing common tools and features

Refactoring features

Code snippets

Editor configuration

AI companions

Tools in Visual Studio 2022

Refactoring features

Add method parameter checks

Method parameter refactoring

Convert foreach to for and vice versa

Simplify LINQ statements

Align code elements

Refactor to primary constructors

Code snippets

Code snippets schema

Creating and importing code snippets

Distributing code snippets

Editor configuration

AI companions: GitHub Copilot

Making the most of GitHub Copilot

Navigating Visual Studio

Copying and pasting a statement

Switching between file tabs and tool windows

Features to improve the editing experience

Line numbers and word wrap

Keyboard shortcuts

Formatting code

Task list

Extension Manager

Tools in Visual Studio Code

Refactoring features

Code snippets

Decompiling .NET assemblies

Creating a console app to decompile

Decompiling using the ILSpy extension for Visual Studio

Viewing source links with Visual Studio

No, you cannot technically prevent decompilation

Lowering C# code

Custom project and item templates

Creating a project for a template

Testing the project template

Practicing and exploring

Exercise 2.1 – Online-only material

Exercise 2.2 – Practice exercises

Exercise 2.3 – Test your knowledge

Exercise 2.4 – Explore topics

Summary

Join our book’s Discord space

Source Code Management Using Git

Introducing source code management

Features of source code management

Types of SCM system

Common SCM systems

Introducing Git

Features of Git

Why is Git hard to learn?

Roles in a team for Git

Downloading the latest Git

Git integration with Visual Studio

Configuring your Git identity

Configuring SSH signature enforcement

Configuring your default branch

Getting help for Git

Working with Git

Starting with a Git repository

Creating and adding files to a Git repository in theory

Tracking changes in Git

Creating a Git repository in practice

Creating a new project

Committing files

Undoing a commit

Cleaning a commit

Stashing

Ignoring files

Reviewing Git repositories

Viewing differences in files

Viewing your commit history

Filtering log output

Managing remote repositories

Branching and merging

Walking through a branching and merging example

Deleting and listing branches

Summary of common Git commands

Practicing and exploring

Exercise 3.1 – Online-only material

Exercise 3.2 – Practice exercises

Exercise 3.3 – Test your knowledge

Exercise 3.4 – Explore topics

Summary

Join our book’s Discord space

Debugging and Memory Troubleshooting

Debugging strategies

Introducing debugging strategies

Understanding the problem

How to start debugging

When to give up debugging

Interactive debugging with Visual Studio

Creating code with objects to view

Setting a breakpoint and starting debugging

Navigating with the debugging toolbar

Debugging windows

Controlling what appears in debug panes

Debugging test projects

Asking GitHub Copilot Chat for debugging help

Understanding stack and heap memory

How reference and value types are stored in memory

Understanding unsafe code

Understanding pointers

Other uses of pointers

Understanding boxing

Understanding garbage collection

Controlling the GC

Managing resources with IDisposable

Tools and skills for memory troubleshooting

Common memory tools and skills

Visual Studio tools

Using Visual Studio Memory Usage

Practicing and exploring

Exercise 4.1 – Online-only material

Exercise 4.2 – Practice exercises

Exercise 4.3 – Test your knowledge

Exercise 4.4 – Explore topics

Summary

Join our book’s Discord space

Logging, Tracing, and Metrics for Observability

Logging and tracing in .NET

Understanding ILogger in .NET

How to log using ILogger

Building a web service for logging

Testing the basic functionality of the web service

Monitoring with metrics in .NET

Concepts for metrics and alerts

Metrics

Alerts

Scenarios for metrics and alerts

Implementing metrics

Adding metrics to an ASP.NET Core project

Viewing metrics

Introducing OpenTelemetry

Supported instrumentation packages

Instrumenting an ASP.NET Core project

Viewing the telemetry

Practicing and exploring

Exercise 5.1 – Online-only material

Exercise 5.2 – Practice exercises

Exercise 5.3 – Test your knowledge

Exercise 5.4 – Explore topics

Summary

Join our book’s Discord space

Documenting Your Code, APIs, and Services

Introducing documentation

Benefits of documentation

When not to document

Documenting your source code

When should you document your source code?

Good practices for commenting your source code

Documenting public APIs in class libraries

XML comment documentation

How to document code using XML comments

Generating documentation using DocFX

Creating a DocFX project

Adding custom documentation content

Markdown markup language

Headings

Formatting text

Creating lists

Links and images

Code blocks and syntax highlighting

Tables

Documenting services

Considerations for documenting services

Tools for documenting services

Understanding the OpenAPI Specification (OAS)

Documenting a Minimal APIs service using OpenAPI

Documenting visually with Mermaid diagrams

Rendering Mermaid diagrams

Flowcharts using Mermaid

Class diagrams using Mermaid

Converting Mermaid to SVG

Practicing and exploring

Exercise 6.1 – Online-only material

Exercise 6.2 – Practice exercises

Exercise 6.3 – Test your knowledge

Exercise 6.4 – Explore topics

Summary

Join our book’s Discord space

Observing and Modifying Code Execution Dynamically

Working with reflection and attributes

Metadata in .NET assemblies

Versioning of assemblies

Reading assembly metadata

Creating custom attributes

Understanding compiler-generated types and members

Making a type or member obsolete

Dynamically loading assemblies and executing methods

A warning about reflection and native AOT

Reflection improvements in .NET 9

Doing more with reflection

Working with expression trees

Understanding components of expression trees

Executing the simplest expression tree

Creating source generators

Implementing the simplest source generator

Practicing and exploring

Exercise 7.1 – Online-only material

Exercise 7.2 – Practice exercises

Exercise 7.3 – Test your knowledge

Exercise 7.4 – Explore topics

Summary

Join our book’s Discord space

Protecting Data and Apps Using Cryptography

Understanding the vocabulary of protection

Techniques to protect your data

Keys and key sizes

IVs and block sizes

Salts

Generating keys and IVs

Encrypting and decrypting data

Encrypting symmetrically with AES

Hashing data

Hashing with the commonly used SHA-256

Signing data

Signing with SHA-256 and RSA

Generating random numbers for cryptography

Authenticating and authorizing users

Authentication and authorization mechanisms

Identifying a user

User membership

Implementing authentication and authorization

Protecting application functionality

Real-world authentication and authorization

What’s coming in .NET 9

CryptographicOperations.HashData() method

KMAC algorithm

Practicing and exploring

Exercise 8.1 – Online-only material

Exercise 8.2 – Practice exercises

Exercise 8.3 – Test your knowledge

Exercise 8.4 – Explore topics

Summary

Join our book’s Discord space

Building an LLM-Based Chat Service

Introducing LLMs

How LLMs work

Obtaining access to an LLM

Using Semantic Kernel with an OpenAI model

Understanding Semantic Kernel

Understanding functions

Adding functions

Adding session memory and enabling multiple functions

Streaming results

Adding logging and resilience

Running local LLMs

Hugging Face

Ollama

Ollama models

Ollama CLI

OllamaSharp .NET package

LM Studio

Practicing and exploring

Exercise 9.1 – Online-only material

Exercise 9.2 – Practice exercises

Exercise 9.3 – Test your knowledge

Exercise 9.4 – Explore topics

Summary

Join our book’s Discord space

Dependency Injection, Containers, and Service Lifetime

Introducing dependency injection

Why use DI?

The mechanisms of DI in .NET

Examples in modern .NET

Constructor injection example

Property injection examples

Method injection example

Registering dependency service lifetimes

Registering multiple implementations

When are exceptions thrown?

Best practices for DI

Implementing .NET Generic Host

Key features of the .NET Generic Host

Building a .NET Generic Host

Understanding host services and events

Service registration methods

Dependency graphs and service resolution

Disposing services

DI with ASP.NET Core

Registering services for features using extension methods

When you cannot use constructor injection

Using scoped services in middleware

Resolving services at startup

DI and views

DI, action methods, and Minimal APIs

Practicing and exploring

Exercise 10.1 – Online-only material

Exercise 10.2 – Practice exercises

Exercise 10.3 – Test your knowledge

Exercise 10.4 – Explore topics

Summary

Join our book’s Discord space

Unit Testing and Mocking

Introducing all types of testing

Unit testing

Integration, end-to-end, and security testing

Performance, load, and stress testing

Functional and usability testing

Testing terminology

Attributes of all good tests

Test outcomes

Test doubles, mocks, and stubs

Adopting a testing mindset

Pros and cons of test-driven development

Core principles of TDD

Pros of TDD

Cons of TDD

Good practices for TDD

Unit testing

How isolated should unit tests be?

Naming unit tests

Unit testing using xUnit

Common xUnit attributes

Creating a SUT

Writing simple unit tests

Test methods with parameters

Testing theory methods using InlineData

Testing theory methods using ClassData

Testing theory methods using strongly typed ClassData

Testing theory methods using MethodData

Positive and negative test results

Red flags in unit tests

Seeing output during test execution

Set up and tear down

Controlling test fixtures

Mocking in tests

Libraries for mocking

Using NSubstitute to create test doubles

Mocking with NSubstitute example

Making fluent assertions in unit testing

Making assertions about strings

Making assertions about collections and arrays

Making assertions about dates and times

Generating fake data with Bogus

Faking data test project

Writing a method with fake data

Practicing and exploring

Exercise 11.1 – Online-only material

Exercise 11.2 – Practice exercises

Exercise 11.3 – Test your knowledge

Exercise 11.4 – Explore topics

Summary

Join our book’s Discord space

Integration and Security Testing

Basics of integration testing

Which external systems to test

Sharing fixtures in integration tests

Walkthrough of an example integration test

Integration testing with data stores

Developer instances of the database and migrations

Data lifecycle

Testing services using dev tunnels

Installing the dev tunnel CLI

Exploring a dev tunnel with the CLI and an echo service

Exploring a dev tunnel with an ASP.NET Core project

Introducing security testing

Open Web Application Security Project

OWASP Top 10

A1:2021 – Broken Access Control

A2:2021 – Cryptographic Failures

A3:2021 – Injection

A4:2021 – Insecure Design

A5:2021 – Security Misconfiguration

A6:2021 – Vulnerable and Outdated Components

A7:2021 – Identification and Authentication Failures

A8:2021 – Software and Data Integrity Failures

A9:2021 – Security Logging and Monitoring Failures

A10:2021 – Server-Side Request Forgery (SSRF)

OWASP Top 10 summary

Threat modeling

Microsoft Threat Modeling Tool

Security Development Lifecycle (SDL)

OWASP resources

Azure Security and Compliance Blueprints

.NET security best practices

Practicing and exploring

Exercise 12.1 – Online-only material

Exercise 12.2 – Practice exercises

Exercise 12.3 – Test your knowledge

Exercise 12.4 – Explore topics

Summary

Join our book’s Discord space

Benchmarking Performance, Load, and Stress Testing

Benchmarking performance

Importance of a baseline

Big O notation

Statistical metrics

BenchmarkDotNet for benchmarking performance

Avoiding benchmarking mistakes

Isolating benchmarking code from setup or teardown

Trust the tool

Compare like to like

Beware of environmental variations

Identifying poor blog posts about performance

Load and stress testing

Apache JMeter

Bombardier – a fast cross-platform HTTP benchmarking tool

Using Bombardier

Downloading Bombardier

Comparing an AOT and a non-AOT web service

Testing the two web services with Bombardier

Interpreting Bombardier results

NBomber – a load testing framework

NBomber scenarios

Load simulations

NBomber types

NBomber project example

Practicing and exploring

Exercise 13.1 – Online-only material

Benchmarking mistakes

Exercise 13.2 – Practice exercises

Exercise 13.3 – Test your knowledge

Exercise 13.4 – Explore topics

Summary

Join our book’s Discord space

Functional and End-to-End Testing of Websites and Services

Understanding functional and end-to-end testing

Example 1: Testing a Web API service

Example 2: Testing an ASP.NET Core website

Example 3: Testing a SignalR real-time application

Testing web user interfaces using Playwright

Benefits for .NET developers

Alternatives to Playwright

Common Playwright testing types

Common Playwright testing methods

Common Playwright locator methods

Common Playwright locator automation methods

Testing common scenarios with eShopOnWeb

Page navigation and title verification

Interacting with a web user interface

Selecting dropdown items and clicking elements

Form submission, authentication, and validation

Responsive design testing

Emulating screen sizes

Emulating devices

Emulating locale, time zone, and geolocation

Emulating dark mode and color schemes

Emulating the user agent, disabling JavaScript, and going offline

Single-Page Applications (SPAs) and dynamic content

Generating tests with the Playwright Inspector

Testing web services using xUnit

Creating a web service ready for testing

Creating the test project

Practicing and exploring

Exercise 14.1 – Online-only material

Exercise 14.2 – Practice exercises

Exercise 14.3 – Test your knowledge

Exercise 14.4 – Explore topics

Summary

Join our book’s Discord space

Containerization Using Docker

Introducing containerization

How containers work and their benefits

Docker, Kubernetes, and .NET Aspire

Kubernetes

.NET Aspire

Container registries

Docker concepts

Docker tools and technologies

Docker command-line interface (CLI) commands

Building images using Dockerfiles

Configuring ports and running a container

Interactive mode

Setting environment variables

Common Docker container images

.NET container images

CVEs and Chiseled Ubuntu

Managing containers with Docker

Installing Docker and using prebuilt images

Docker image hierarchy and layers

Containerizing your own .NET projects

Containerizing a console app project

Publishing to a Docker container

Containerizing an ASP.NET Core project

Working with test containers

How Testcontainers for .NET works

Usage example

Practicing and exploring

Exercise 15.1 – Online-only material

Exercise 15.2 – Practice exercises

Exercise 15.3 – Test your knowledge

Exercise 15.4 – Explore topics

Summary

Join our book’s Discord space

Cloud-Native Development Using .NET Aspire

Introducing Aspire

What does the Aspire team say?

Code editor and CLI support for Aspire

Starting an Aspire solution

Aspire project types

Aspire resource types

Aspire application model and orchestration

Aspire project templates

Exploring the Aspire starter template

Creating the Aspire starter application

Exploring the Aspire starter solution

Deeper into Aspire

Developer dashboard for monitoring

AppHost project for orchestrating resources

ServiceDefaults project for centralized configuration

Participating functional projects

Configuring Redis

Aspire components

Logging, tracing, and metrics for observability

Docker versus Podman for containers

Waiting for containers to be ready

What about Dapr, Orleans, and Project Tye?

Dapr

Orleans

Project Tye

Choosing between Dapr, Orleans, and Aspire

Aspire for new and existing solutions

Creating a new Aspire solution

Aspire and PostgreSQL

Using data volumes and configuring a stable password

Adding Aspire to an existing solution

Switching to Aspire components

Reviewing the eShop reference application

Deployment with Aspire

Practicing and exploring

Exercise 16.1 – Online-only material

Exercise 16.2 – Practice exercises

Exercise 16.3 – Test your knowledge

Exercise 16.4 – Explore topics

Summary

Join our book’s Discord space

Design Patterns and Principles

SOLID principles

Single Responsibility Principle (SRP)

SRP example

SRP violating example

SRP adhering refactoring

SRP common mistakes

SRP takeaways

Open/Closed Principle (OCP)

OCP example

OCP violating example

OCP common mistakes

OCP takeaways

Liskov Substitution Principle (LSP)

LSP example

LSP violating example

LSP adhering refactoring

LSP common mistakes

LSP in .NET

LSP takeaways

Interface Segregation Principle (ISP)

ISP example

ISP violating example

ISP adhering refactoring

ISP common mistakes

ISP in .NET

ISP takeaways

Dependency Inversion Principle (DIP)

DIP example

DIP violating example

DIP common mistakes

DIP takeaways

Design patterns

Creational patterns

Builder pattern

Structural design patterns

Adapter a.k.a. the Wrapper pattern

Behavioral design patterns

Template Method pattern

Design principles

DRY

KISS

YAGNI

Law of Demeter

LoD example

LoD takeaways

Composition over Inheritance

Composition over Inheritance example

Composition over Inheritance violating example

Composition over Inheritance takeaways

Principle of Least Astonishment

PoLA example

PoLA takeaways

Algorithms and data structures

Sorting algorithms

Searching algorithms

Data structure algorithms

Hashing algorithms

Recursive algorithms

Where to learn more about algorithms and data structures

Practicing and exploring

Exercise 17.1 – Online-only material

Exercise 17.2 – Practice exercises

Exercise 17.3 – Test your knowledge

Exercise 17.4 – Explore topics

Summary

Join our book’s Discord space

Software and Solution Architecture Foundations

Introducing software and solution architecture

Software architecture

Solution architecture

Software architecture concepts

Domain-Driven Design (DDD)

Software Development Lifecycle (SDLC) methodologies

Software architecture styles

Command Query Responsibility Segregation (CQRS)

Solution architecture concepts

Conclusion

Uncle Bob’s Clean Architecture

Clean architecture concepts

Defining entities

Defining use cases and business rules

Implementing interfaces

Implementing presenters

Implementing controllers

Good practices in .NET Clean Architecture

Diagramming design using Mermaid

Mermaid for software and solution architecture

Mermaid diagram types

Mermaid flowcharts

Flowchart syntax

Example flowchart – a user login process

Example flowchart – a software development process

Sequence diagram syntax

Example sequence diagram – a user registration process

Example sequence diagram – website querying a database

Practicing and exploring

Exercise 18.1 – Online-only material

Exercise 18.2 – Practice exercises

Exercise 18.3 – Test your knowledge

Exercise 18.4 – Explore topics

Summary

Join our book’s Discord space

Your Career, Teamwork, and Interviews

Working on a development team

Being a software engineer

Career path

Roles on a development team that you will collaborate with

Project manager

Business analyst

Quality assurance analyst or tester

User experience designer

Database administrator

DevOps engineer

Front-end (FE) developer

Technical lead or architect

Onboarding process

How to ask for training and development

Identify specific training needs

Align training with business goals

Prepare a cost-benefit analysis

Propose a flexible plan

Request a meeting and present your case

Pair programming

Could an LLM replace a human paired programmer?

Applying for a job

Before you apply

Refine your skills and knowledge

Obtain certifications

Search for job openings

Craft your job application, resume, and online profiles

Your resume or curriculum vitae

Ask an LLM to improve your resume

Interview preparation

Do not use an LLM during an interview

Interviewing at the big companies

Applying for more experienced positions

Applying for tester positions

Selection of questions

Behavioral questions

STAR method

Using the STAR method effectively

Tips during interviews

How to handle difficult coding questions

How to handle unprepared interviewers

What to never do

Sample interview questions

1. .NET CLI tools

Good answer

Commonly given poor answer

2. Git fundamentals

Good answer

Commonly given poor answer

3. Entity Framework Core

Good answer

Commonly given poor answer

4. Interfaces and abstract classes

5. Properties and indexers

6. Generics

7. Delegates and events

8. Language Integrated Query (LINQ)

9. Asynchronous programming with async and await

10. Memory management and garbage collection

11. Differences between modern .NET and .NET Framework

12. Cross-platform capabilities

13. .NET Standard

14. Dependency injection in .NET

15. Middleware in ASP.NET Core

16. Configuration and Options pattern

17. Hosting and Kestrel server

18. Data types

19. Globalization and localization

20. Control structures

21. Exception handling

22. Git branching strategies

23. Code reviews and pair programming

24. Agile and Scrum methodologies

25. Documentation standards

26. Problem-solving skills

27. Project management tools

28. Estimation techniques

29. Team collaboration

30. Leadership and mentorship

31. MVC pattern

32. Razor syntax

33. Web API development

34. RESTful services best practices

35. SignalR for real-time web functionality

36. State management

37. Authentication and authorization

38. Blazor WebAssembly

39. Benefits of microservices

40. Challenges in microservices architecture

41. Docker containers and .NET

42. Microservices communication patterns

43. Resilience and transient fault handling

44. Distributed tracing

45. Health checks and monitoring

46. AutoMapper vs. extension method vs. implicit operator

47. ADO.NET fundamentals

48. Entity Framework Core performance tuning

49. Unit testing frameworks like xUnit

50. Mocking frameworks like NSubstitute

51. Integration testing strategies

52. Performance testing

53. Security testing

54. Automated UI testing

55. SOLID principles

56. Singleton pattern

57. Factory pattern

58. Memory leak identification

59. Development methodologies

60. Big O

When you’re failing, you’re learning

Practicing and exploring

Exercise 19.1 – Online-only material

Exercise 19.2 – Practice exercises

Exercise 19.3 – Test your knowledge

Exercise 19.4 – Explore topics

Summary

Join our book’s Discord space

Epilogue

Next steps on your .NET learning journey

Companion books to continue your learning journey

Ninth edition of C# 12 and .NET 8 coming soon for .NET 9

Planned .NET 10 trilogy

Packt books to take your learning further

Good luck!

Index

Landmarks

Cover

Index

Share your thoughts

Once you’ve read Tools and Skills for .NET 8, we’d love to hear your thoughts! Please click here to go straight to the Amazon review page for this book and share your feedback.

Your review is important to us and the tech community and will help us make sure we’re delivering excellent quality content.

Download a free PDF copy of this book

Thanks for purchasing this book!

Do you like to read on the go but are unable to carry your print books everywhere?

Is your eBook purchase not compatible with the device of your choice?

Don’t worry, now with every Packt book you get a DRM-free PDF version of that book at no cost.

Read anywhere, any place, on any device. Search, copy, and paste code from your favorite technical books directly into your application.

The perks don’t stop there, you can get exclusive access to discounts, newsletters, and great free content in your inbox daily.

Follow these simple steps to get the benefits:

Scan the QR code or visit the link below:

https://packt.link/free-ebook/9781837635207

Submit your proof of purchase.That’s it! We’ll send your free PDF and other benefits to your email directly.

1

Introducing Tools and Skills for .NET

In this first chapter, the goals are understanding the tools and skills that you will learn in this book, setting up your development environment to use Visual Studio 2022, Visual Studio Code, or JetBrains Rider, and then setting up a database and projects to use in the rest of the chapters. Throughout this book, I will use the names Visual Studio, Code, and Rider to refer to these three code editors respectively.

I use the term modern .NET to refer to .NET 8 and its predecessors like .NET 6, which derive from .NET Core. I use the term legacy .NET to refer to .NET Framework, Mono, Xamarin, and .NET Standard. Modern .NET is a unification of those legacy platforms and standards.

Every chapter in this book introduces some tools and some skills, but some chapters are more focused on a particular tool or a particular skill.

This chapter covers the following topics:

Introducing this book and its contentsSetting up your development environmentMaking good use of the GitHub repository for this bookWhere to go for helpSetting up a database and projects for this bookUsing .NET 9 with this book

The GitHub repository for this book has solutions using full application projects for all code tasks:

https://github.com/markjprice/tools-skills-net8/

After going to the GitHub repository, simply press the . (dot) key on your keyboard or change .com to .dev to change the repository into a live code editor based on Code using GitHub Codespaces. Code in a web browser is great to run alongside your chosen code editor as you work through the book’s coding tasks. You can compare your code to the solution code and easily copy and paste parts if needed.

Introducing this book and its contents

Before we dive into an overview of this book, let’s set the context by understanding that this is one of three books about .NET 8 that I have written that cover almost everything a beginner to .NET needs to know.

Companion books to complete your learning journey

This book is the third of three books in a trilogy that completes your learning journey through .NET 8:

The first book, C# 12 and .NET 8 – Modern Cross-Platform Development Fundamentals, covers the fundamentals of the C# language, the .NET libraries, and using ASP.NET Core and Blazor for web development. It is designed to be read linearly because skills and knowledge from earlier chapters build up and are needed to understand later chapters.The second book, Apps and Services with .NET 8, covers more specialized .NET libraries like internationalization and popular third-party packages including Serilog and Noda Time. You learn how to build native ahead-of-time (AOT)-compiled services with ASP.NET Core Minimal APIs and how to improve performance, scalability, and reliability using caching, queues, and background services. You implement more services using GraphQL, gRPC, SignalR, and Azure Functions. Finally, you learn how to build graphical user interfaces for websites, desktop, and mobile apps with Blazor and .NET MAUI.This third book covers important tools and skills that a professional .NET developer should have. These include design patterns and solution architecture, debugging, memory analysis, all the important types of testing, whether it be unit, integration, performance, or web user interface testing, and then topics for testing cloud-native solutions on your local computer like containerization, Docker, and .NET Aspire. Finally, we will look at how to prepare for an interview to get the .NET developer career that you want.

A summary of the .NET 8 trilogy and their most important topics is shown in Figure 1.1:

Figure 1.1: Companion books for learning .NET 8 for beginner-to-intermediate readers

We provide you with a PDF file that has color images of the screenshots and diagrams used in this book. You can download this file from https://packt.link/gbp/9781837635207.

Audiences for this book

This book caters to two audiences:

Readers who have completed my book for learning the fundamentals of the C# language, .NET libraries, and using ASP.NET Core for web development, C# 12 and .NET 8 – Modern Cross-Platform Development Fundamentals, and now want to take their learning further.Readers who already have basic skills and knowledge about C# and .NET and want to acquire practical skills and knowledge of common tools to become more professional with their .NET development, and in particular join a team of .NET developers.

Let’s look at an analogy:

First, an amateur cook might buy a book to learn fundamental skills, concepts, and terminology that any cook needs to make the most common dishes.Second, an amateur cook might also buy a recipe book to learn how to apply that knowledge and those skills to make complete meals.Third, to become a professional cook, they would also need to understand the roles in a professional kitchen, learn more specialized tools and skills that are needed when cooking meals for many more people in a professional environment, and how to work in a team of cooks.

These three scenarios are why I wrote three books about .NET.

The preface briefly introduces each chapter, but many readers skip the preface. So, let’s now review why each topic is covered in more depth.

Tools

There are many tools that a professional .NET developer should be familiar with. Some are built into most code editors like a debugger or source control integration, and some require separate applications and services like memory analysis and telemetry.

Even beginner developers know the basic tools included with a code editor like the main editing window, managing files in a project, how to set a breakpoint and start debugging, and then step through the code statement by statement, and how to run a project, so those topics will not be covered in this book.

Chapter 2, Making the Most of the Tools in your Code Editor, is about the less commonly used tools built into Visual Studio, Code, and Rider. The major tools like a debugger or memory analysis tools are covered in separate later chapters. This chapter covers topics like refactoring features and how to customize your code editor using standards like .editorconfig.

Chapter 3, Source Code Management Using Git, covers the most common tasks that you would perform with Git to manage your source code, especially when working in a team of .NET developers. Git is a distributed source control system, so developers have a local copy of the entire repository. This enables offline work, fast branching, and merging. Git is the most popular source code control system for .NET projects, and there are tools and extensions available for seamless integration with all code editors and command-line tools. GitHub is a popular Microsoft platform for hosting Git repositories and collaborating on software projects.

Chapter 4, Debugging and Memory Troubleshooting, is about using the debugging tools in your code editor. You will learn how to use the built-in debugging features, how to decorate your own code with attributes to make it easier to see what’s happening while debugging, and how to use tools in your code editor to track the usage of memory to improve your apps and services.

Chapter 5, Logging, Tracing, and Metrics for Observability, is about how to instrument your code to enable tracing, metrics, and logging during production, and how to implement telemetry using OpenTelemetry to monitor your code as it executes to enable observability.

Skills

As well as learning how to use the tools themselves, a professional .NET developer needs skills like documenting code, leveraging dynamic code, and implementing cryptographic techniques to protect code and data. You will also build a custom chatbot that uses a model enhanced with custom functions.

Chapter 6, Documenting Code, APIs, and Services, discusses how to best document your code to help other developers maintain it in the future using comments, and how to document your services and APIs to enable other developers to call them as designed. Forcing yourself to document your code has the side benefit that you will often spot places where you could improve the design and refactor your code and APIs.

Chapter 7, Observing and Modifying Code Execution Dynamically, introduces you to some common types that are included with .NET for performing code reflection, applying and reading attributes, working with expression trees, and most usefully, creating source generators.

Chapter 8, Protecting Data and Apps Using Cryptography, is about protecting your data from being viewed by malicious users using encryption, and from being manipulated or corrupted using hashing and signing. You will also learn about using authentication and authorization to protect applications from unauthorized users.

Chapter 9, Building a Custom LLM-based Chat Service, covers how to build a custom chat service that integrates a large language model (LLM) and custom functions based on business data.

Chapter 10, Dependency Injection, Containers and Service Lifetime, is about reducing tight coupling between components, which is especially critical to performing practical testing. This also enables you to better manage changes and software complexity.

Testing

One of the most important tools and skills for a .NET developer is testing to ensure quality. Testing spans the whole life cycle of development, from testing a small unit of behavior to end-to-end testing of the user experience and system integration. The earlier in the development process that you test, the lower the cost of fixing any mistakes that you discover.

Chapter 11, Unit Testing and Mocking, introduces testing practices that will improve your code quality. Unit testing is easy to get wrong and can become useless, undermining the team’s trust. Get it right, and you will save time and money and smooth out the development process.

Chapter 12, Integration and Security Testing, introduces a higher level of testing across all components of a solution, and the types of testing needed to maintain the security of your projects.

Chapter 13, Benchmarking Performance, Load, and Stress Testing, introduces how to properly use the BenchmarkDotNet library to monitor your code to measure performance and efficiency. Then, you will see how to perform load and stress testing on your projects to predict required resources and estimate the costs of deployment in production using Bombardier and NBomber.

Chapter 14, Functional and End-to-End Testing of Websites and Services, introduces you to testing APIs and web user interfaces using Playwright for automation.

Chapter 15, Containerization Using Docker, introduces you to the concept of containerization and specifically using Docker to virtualize hosts for services in complex solution architectures.

Chapter 16, Cloud-Native Development Using .NET Aspire, introduces you to .NET Aspire, an opinionated way to manage a cloud-native development environment. It automates local deployments during development and includes integrations with tools you learned about earlier in the book like OpenTelemetry for observability, Docker containers for microservices, and so on.

Design and career development

The final part of this book is about more theoretical concepts like design patterns, principles, and software and solution architecture, and ends with a chapter that wraps everything up with preparing for an interview to get the career that you want with a team of developers and other professionals.

Chapter 17, Design Patterns and Principles, introduces you to the SOLID design patterns as well as other common patterns and principles like DRY (Don’t Repeat Yourself), KISS (Keep It Simple, Stupid), YAGNI (You Ain’t Gonna Need It), and PoLA (Principle of Least Astonishment).

Chapter 18, Software and Solution Architecture Foundations, covers software and solution architecture, including using Mermaid to create architecture diagrams.

Chapter 19, Your Career, Teamwork, and Interviews, covers what you need to get the career you aspire to. To achieve this, you must impress with your resume and at an interview. This chapter covers commonly asked questions in interviews and suggested answers that fit with your experience to help you give realistic responses.

Setting up your development environment

Before you start programming, you’ll need a code editor for C#. Microsoft has a family of code editors and integrated development environments (IDEs), which include:

Visual Studio: Visual Studio 2022 for Windows. (Visual Studio 2022 for Mac reaches end-of-life on August 31, 2024, and is not recommended.)Code: Visual Studio Code for Windows, Mac, Linux, the Web, or GitHub Codespaces.Rider: JetBrains Rider, which is available for Windows, Mac, or Linux but does have a license cost. Rider is popular with more experienced .NET developers.

Choosing the appropriate tool and application type for learning

What is the best tool and application type for learning how to use tools and skills with C# and .NET?

I want you to be free to choose any C# code editor or IDE to complete the coding tasks in this book, including Visual Studio, Code, Rider, or a code editor that I’ve never heard of.

In this book, I give general instructions that work with all tools so you can use whichever tool you prefer.

Using Visual Studio for general development

Visual Studio can create most types of applications, including console apps, websites, web services, desktop, and mobile apps. Visual Studio only runs on Windows 10 version 1909 or later, or Windows Server 2016 or later, and only on 64-bit versions. Version 17.4 is the first version to support native ARM64.

Warning!

Visual Studio for Mac does not officially support .NET 8 and it will reach end-of-life in August 2024. If you have been using Visual Studio for Mac then you should switch to Code for Mac or Rider for Mac, or use Visual Studio in a virtual machine on your local computer or in the cloud using a technology like Microsoft Dev Box. The retirement announcement can be read here: https://devblogs.microsoft.com/visualstudio/visual-studio-for-mac-retirement-announcement/.

Using Code for cross-platform development

The most modern and lightweight code editor to choose from, and the only one from Microsoft that is cross-platform, is Code. It can run on all common operating systems, including Windows, macOS, and many varieties of Linux, including Red Hat Enterprise Linux (RHEL) and Ubuntu. Code is a good choice for modern cross-platform development because it has an extensive and growing set of extensions to support many languages beyond C#.

Being cross-platform and lightweight, it can be installed on all platforms that your apps will be deployed to for quick bug fixes and so on. Choosing Code means a developer can use a cross-platform code editor to develop cross-platform apps.

Code is by far the most popular IDE, with over 74% of professional developers selecting it in the Stack Overflow 2023 survey, which you can read at the following link: https://survey.stackoverflow.co/2023/#most-popular-technologies-new-collab-tools-prof.

Using GitHub Codespaces for development in the cloud

GitHub Codespaces is a fully configured development environment based on Code that can be spun up in an environment hosted in the cloud and accessed through any web browser. It supports Git repositories, extensions, and a built-in command-line interface so you can edit, run, and test from any device. Since it runs in the cloud and you interact with it via a web browser there is nothing to download and install, and since it is based on Code, it works the same way Code does on your local computer.

More Information

You can learn more about GitHub Codespaces at the following link: https://github.com/features/codespaces. Microsoft Dev Box is another way to host a development environment: https://azure.microsoft.com/en-us/products/dev-box.

Reviews of GitHub Codespaces are available at the following links:

https://dev.to/github/github-codespaces-ga-any-good-reviewed-and-tested-3e62https://medium.com/@pooyan_razian/github-codespaces-a-different-way-to-code-da455777f9ab

Using Rider for cross-platform development

Rider is a third-party code editor from JetBrains, the maker of IntelliJ IDEA, the leading Java and Kotlin IDE, and ReSharper, the popular Visual Studio plugin for .NET developers. Rider runs on multiple platforms: Windows, macOS, and Linux.

It has a license fee, but developers who use it are often professionals who appreciate the extra features it has like live code inspections, context actions, and refactorings. Using Rider can be an indicator of a more advanced developer.

You should expect new versions of Rider to support the latest version of .NET a few weeks after Visual Studio. For example, .NET 8 was released on November 14, 2023, and Visual Studio with official support for .NET 8 was released on the same day. But Rider version 2023.3 with official support for .NET 8 was not released until December 7, 2023.

Although JetBrains is a fantastic company with great products, both Rider and the ReSharper extension for Visual Studio are software, and all software has bugs and quirky behavior. For example, they might show errors like “Cannot resolve symbol” in your Razor Pages, Razor views, and Blazor components. Yet, you can build and run those files because there is no actual problem.

If you use Rider and you have installed the Unity Support or Heap Allocation Viewer plugins, then it will complain a lot about boxing. A common scenario when boxing happens is when value types like int and DateTime are passed as positional arguments to string formats. This is a problem for Unity projects because they use a different memory garbage collector than the normal .NET runtime. For non-Unity projects, like all the projects in this book, you can ignore these boxing warnings because they are not relevant. You can read more about this Unity-specific issue at the following link: https://docs.unity3d.com/Manual/performance-garbage-collection-best-practices.html#boxing.

What I used

To write and test the code for this book, I used the following hardware and software:

Visual Studio on:Windows 11 on an HP Spectre (Intel) laptopCode on:macOS on an Apple Silicon Mac mini (M1) desktopWindows 11 on an HP Spectre (Intel) laptopRider on:Windows 11 on an HP Spectre (Intel) laptopmacOS on an Apple Silicon Mac mini (M1) desktop

I hope that you have access to a variety of hardware and software too because seeing the differences on various platforms deepens your understanding of development challenges, although any one of the preceding combinations is enough to learn how to build practical apps and websites.

Deploying cross-platform

Your choice of code editor and operating system for development does not limit where your code gets deployed.

.NET 8 supports the following platforms for deployment:

Windows: Windows 10 version 1607 or later. Windows 11 version 22000 or later. Windows Server 2012 R2 SP1 or later. Nano Server version 1809 or later.Mac: macOS Catalina version 10.15 or later and in the Rosetta 2 x64 emulator. Mac Catalyst: 11.0 or later.Linux: Alpine Linux 3.17 or later. Debian 11 or later. Fedora 37 or later. openSUSE 15 or later. Oracle Linux 8 or later. Red Hat Enterprise Linux (RHEL) 8 or later. SUSE Enterprise Linux 12 SP2 or later. Ubuntu 20.04 or later.Android: API 21 or later.iOS and tvOS: 11.0 or later.

You can review the latest supported operating systems and versions at the following link: https://github.com/dotnet/core/blob/main/release-notes/8.0/supported-os.md.

Downloading and installing Visual Studio

Many professional .NET developers use Visual Studio in their day-to-day development work. Even if you choose to use Code to complete the coding tasks in this book, you might want to familiarize yourself with Visual Studio too.