Book Image

Hands-On Design Patterns with C# and .NET Core

By : Gaurav Aroraa, Jeffrey Chilberto
Book Image

Hands-On Design Patterns with C# and .NET Core

By: Gaurav Aroraa, Jeffrey Chilberto

Overview of this book

Design patterns are essentially reusable solutions to common programming problems. When used correctly, they meet crucial software requirements with ease and reduce costs. This book will uncover effective ways to use design patterns and demonstrate their implementation with executable code specific to both C# and .NET Core. Hands-On Design Patterns with C# and .NET Core begins with an overview of object-oriented programming (OOP) and SOLID principles. It provides an in-depth explanation of the Gang of Four (GoF) design patterns, including creational, structural, and behavioral. The book then takes you through functional, reactive, and concurrent patterns, helping you write better code with streams, threads, and coroutines. Toward the end of the book, you’ll learn about the latest trends in architecture, exploring design patterns for microservices, serverless, and cloud native applications. You’ll even understand the considerations that need to be taken into account when choosing between different architectures such as microservices and MVC. By the end of the book, you will be able to write efficient and clear code and be comfortable working on scalable and maintainable projects of any size.
Table of Contents (19 chapters)
Free Chapter
1
Section 1: Essentials of Design Patterns in C# and .NET Core
4
Section 2: Deep Dive into Utilities and Patterns in .NET Core
10
Section 3: Functional Programming, Reactive Programming, and Coding for the Cloud

Chapter 5 – Implementing Design Patterns – .NET Core

  1. If you are not sure what type of service lifetime to use, what type is it best to register a class as? Why?

Transient lifetime services are created each time they are requested. The majority of classes should be lightweight, stateless services, so this is the best service lifetime to use.

  1. In .NET Core ASP .NET solutions, a scope is defined per web request or per session?

A scope is per web request (connection).

  1. Does registering a class as a Singleton in the .NET Core DI framework make it thread-safe?

No, the framework will provide the same instance for subsequent requests, but does not make a class thread-safe.

  1. Is it true that the .NET Core DI framework can only be replaced with other Microsoft-supplied DI frameworks?

Yes, there are many DI frameworks that can be used instead of the native DI framework...