12, and Beyond 3rd Edition (Early Access) Carl-Hugo Marcotte
12, and Beyond 3rd Edition (Early Access) Carl-Hugo Marcotte
com
https://textbookfull.com/product/architecting-asp-net-core-
applications-carl-hugo-marcotte/
textbookfull.com
https://textbookfull.com/product/biota-grow-2c-gather-2c-cook-loucas/
textbookfull.com
https://textbookfull.com/product/a-golden-treatise-of-mental-prayer-
st-peter-of-alcantara/
textbookfull.com
Fundamentals of Logic Design 7th Edition Roth
https://textbookfull.com/product/fundamentals-of-logic-design-7th-
edition-roth/
textbookfull.com
https://textbookfull.com/product/strategic-management-of-health-care-
organizations-eighth-edition-edition-peter-m-ginter/
textbookfull.com
https://textbookfull.com/product/sports-injuries-of-the-shoulder-
lennard-funk/
textbookfull.com
https://textbookfull.com/product/advances-in-carpet-manufacture-k-k-
goswami/
textbookfull.com
Theory of Thermodynamic Measurements of Quantum Systems
Far from Equilibrium Abhay Shastry
https://textbookfull.com/product/theory-of-thermodynamic-measurements-
of-quantum-systems-far-from-equilibrium-abhay-shastry/
textbookfull.com
Architecting ASP.NET Core
Applications
Copyright © 2023 Packt Publishing
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, and its dealers
and distributors will be held liable for any damages caused or alleged
to be caused directly or indirectly by this book.
Livery Place
35 Livery Street
Birmingham
B3 2PB, UK
ISBN: 978-1-80512-338-5
www.packt.com
Table of Contents
1. Architecting ASP.NET Core Applications, Third Edition: An
atypical design patterns guide for .NET 8, C# 12, and beyond
2. 1 Introduction
I. Before you begin: Join our book community on Discord
II. What is a design pattern?
III. Anti-patterns and code smells
i. Anti-patterns
ii. Code smells
IV. Understanding the web – request/response
V. Getting started with .NET
i. .NET SDK versus runtime
ii. .NET 5+ versus .NET Standard
iii. Visual Studio Code versus Visual Studio versus the
command-line interface
iv. Technical requirements
VI. Summary
VII. Questions
VIII. Further reading
3. 2 Automated Testing
I. Before you begin: Join our book community on Discord
II. Introduction to automated testing
i. Unit testing
ii. Integration testing
iii. End-to-end testing
iv. Other types of tests
v. Picking the right test style
III. Testing approaches
i. TDD
ii. ATDD
iii. BDD
iv. Refactoring
v. Technical debt
IV. Testing techniques
i. White-box testing
ii. Black-box testing
iii. Grey-box testing
iv. White-box vs. Black-box vs. Grey-box testing
v. Conclusion
V. Test case creation
i. Equivalence Partitioning
ii. Boundary Value Analysis
iii. Decision Table Testing
iv. State Transition Testing
v. Use Case Testing
VI. How to create an xUnit test project
VII. Key xUnit features
i. Facts
ii. Assertions
iii. Theories
iv. Closing words
VIII. Arrange, Act, Assert
IX. Organizing your tests
i. Unit tests
ii. Integration tests
X. Writing ASP.NET Core integration tests
i. Classic web application
ii. Minimal hosting
XI. Important testing principles
XII. Summary
XIII. Questions
XIV. Further reading
4. 3 Architectural Principles
I. Before you begin: Join our book community on Discord
II. Separation of concerns (SoC)
III. Don’t repeat yourself (DRY)
IV. Keep it simple, stupid (KISS)
V. The SOLID principles
i. Single responsibility principle (SRP)
ii. Open/Closed principle (OCP)
iii. Liskov substitution principle (LSP)
iv. Interface segregation principle (ISP)
v. Dependency inversion principle (DIP)
VI. Summary
VII. Questions
VIII. Further reading
5. 4 REST APIs
I. Before you begin: Join our book community on Discord
II. REST & HTTP
i. HTTP methods
ii. HTTP Status code
iii. HTTP headers
iv. Versioning
v. Wrapping up
III. Data Transfer Object (DTO)
i. Goal
ii. Design
iii. Conceptual examples
iv. Conclusion
IV. API contracts
i. Code-first API Contract
ii. Wrapping up
V. Summary
VI. Questions
VII. Further reading
VIII. Answers
6. 5 Minimal API
I. Before you begin: Join our book community on Discord
II. Top-level statements
III. Minimal Hosting
IV. Minimal APIs
i. Map route-to-delegate
ii. Configuring endpoints
iii. Leveraging endpoint filters
iv. Leveraging the endpoint filter factory
v. Organizing endpoints
V. Using Minimal APIs with Data Transfer Objects
i. Goal
ii. Design
iii. Project – Minimal API
iv. Conclusion
VI. Summary
VII. Questions
VIII. Further reading
IX. Answers
7. 6 Model-View-Controller
I. Before you begin: Join our book community on Discord
II. The Model View Controller design pattern
i. Goal
ii. Design
iii. Anatomy of ASP.NET Core web APIs
iv. Conclusion
III. Using MVC with DTOs
i. Goal
ii. Design
iii. Project – MVC API
iv. Conclusion
IV. Summary
V. Questions
VI. Further reading
VII. Answers
8. 7 Strategy, Abstract Factory, and Singleton Design Patterns
I. Before you begin: Join our book community on Discord
II. The Strategy design pattern
i. Goal
ii. Design
iii. Project – Strategy
iv. Conclusion
III. The Abstract Factory design pattern
i. Goal
ii. Design
iii. Project – Abstract Factory
iv. Project – The mid-range vehicle factory
v. Impacts of the Abstract Factory
vi. Conclusion
IV. The Singleton design pattern
i. Goal
ii. Design
iii. An alternate (better) way
iv. Code smell – Ambient Context
v. Conclusion
V. Summary
VI. Questions
VII. Answers
9. 8 Dependency Injection
I. Before you begin: Join our book community on Discord
II. What is dependency injection?
i. The composition root
ii. Striving for adaptability
iii. Understanding the use of the IoC container
iv. The role of an IoC container
v. Code smell – Control Freak
vi. Object lifetime
vii. Registering our dependencies
viii. Registering your features elegantly
ix. Using external IoC containers
III. Revisiting the Strategy pattern
i. Constructor injection
ii. Property injection
iii. Method injection
iv. Project – Strategy
v. Conclusion
IV. Understanding guard clauses
V. Revisiting the Singleton pattern
i. Project – Application state
ii. Project – Wishlist
iii. Conclusion
VI. Understanding the Service Locator pattern
i. Project – ServiceLocator
ii. Conclusion
VII. Revisiting the Factory pattern
i. Project – Factory
VIII. Summary
IX. Questions
X. Further reading
XI. Answers
10. 9 Options, Settings, and Configuration
I. Before you begin: Join our book community on Discord
II. Loading the configuration
III. Learning the building blocks
i. IOptionsMonitor<TOptions>
ii. IOptionsFactory<TOptions>
iii. IOptionsSnapshot<TOptions>
iv. IOptions<TOptions>
IV. Project – CommonScenarios
i. Manual configuration
ii. Using the settings file
iii. Injecting options
iv. Named options
v. Reloading options at runtime
V. Project – OptionsConfiguration
i. Creating the program
ii. Configuring the options
iii. Implementing a configurator object
iv. Adding post-configuration
v. Using multiple configurator objects
vi. Exploring other configuration possibilities
VI. Project – OptionsValidation
i. Eager validation
ii. Data annotations
iii. Validation types
VII. Project – OptionsValidationFluentValidation
VIII. Workaround – Injecting options directly
IX. Project – Centralizing the configuration
X. Using the configuration-binding source generator
i. Project – ConfigurationGenerators: Part 1
XI. Using the options validation source generator
i. Project – ConfigurationGenerators: Part 2
XII. Using the ValidateOptionsResultBuilder class
i. Project - ValidateOptionsResultBuilder
XIII. Summary
XIV. Questions
XV. Further reading
XVI. Answers
11. 10 Logging patterns
I. Before you begin: Join our book community on Discord
II. About logging
III. Writing logs
IV. Log levels
V. Logging providers
VI. Configuring logging
VII. Structured logging
VIII. Summary
IX. Questions
X. Further reading
XI. Answers
12. 11 Structural Patterns
I. Before you begin: Join our book community on Discord
II. Implementing the Decorator design pattern
i. Goal
ii. Design
iii. Project – Adding behaviors
iv. Project – Decorator using Scrutor
v. Conclusion
III. Implementing the Composite design pattern
i. Goal
ii. Design
iii. Project – BookStore
iv. Conclusion
IV. Implementing the Adapter design pattern
i. Goal
ii. Design
iii. Project – Greeter
iv. Conclusion
V. Implementing the Façade design pattern
i. Goal
ii. Design
iii. Project – The façades
iv. Conclusion
VI. Summary
VII. Questions
VIII. Further reading
IX. Answers
13. 12 Behavioral Patterns
I. Before you begin: Join our book community on Discord
II. Implementing the Template Method pattern
i. Goal
ii. Design
iii. Project – Building a search machine
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
iv. Conclusion
III. Implementing the Chain of Responsibility pattern
i. Goal
ii. Design
iii. Project – Message interpreter
iv. Conclusion
IV. Mixing the Template Method and Chain of Responsibility
patterns
i. Project – Improved message interpreter
ii. Project – A final, finer-grained design
iii. Conclusion
V. Summary
VI. Questions
VII. Answers
14. 13 Understanding the Operation Result Design Pattern
I. Before you begin: Join our book community on Discord
II. The Operation Result pattern
i. Goal
ii. Design
iii. Project – Implementing different Operation Result
patterns
iv. Advantages and disadvantages
III. Summary
IV. Questions
V. Further reading
VI. Answers
15. 14 Layering and Clean Architecture
I. Before you begin: Join our book community on Discord
II. Introducing layering
i. Classic layering model
ii. Splitting the layers
iii. Layers versus tiers versus assemblies
III. Responsibilities of the common layers
i. Presentation
ii. Domain
iii. Data
IV. Abstract layers
V. Sharing the model
VI. Clean Architecture
VII. Implementing layering in real life
i. To be or not to be a purist?
ii. Building a façade over a database
VIII. Summary
IX. Questions
X. Further reading
XI. Answers
16. 15 Object Mappers, Aggregate Services, and Façade
I. Before you begin: Join our book community on Discord
II. Object mapper
i. Goal
ii. Design
iii. Project – Mapper
iv. Conclusion
III. Code smell – Too many dependencies
IV. Pattern – Aggregate Services
V. Pattern – Mapping Façade
VI. Project – Mapping service
VII. Project – AutoMapper
VIII. Project – Mapperly
IX. Summary
X. Questions
XI. Further reading
XII. Answers
17. 16 Mediator and CQRS Design Patterns
I. Before you begin: Join our book community on Discord
II. A high-level overview of Vertical Slice Architecture
III. Implementing the Mediator pattern
i. Goal
ii. Design
iii. Project – Mediator (IMediator)
iv. Project – Mediator (IChatRoom)
v. Conclusion
IV. Implementing the CQS pattern
i. Goal
ii. Design
iii. Project – CQS
iv. Conclusion
V. Code smell – Marker Interfaces
i. Metadata
ii. Dependency identifier
VI. Using MediatR as a mediator
i. Project – Clean Architecture with MediatR
ii. Conclusion
VII. Summary
VIII. Questions
IX. Further reading
X. Answers
18. 17 Getting Started with Vertical Slice Architecture
I. Before you begin: Join our book community on Discord
II. Anti-pattern – Big Ball of Mud
III. Vertical Slice Architecture
i. What are the advantages and disadvantages?
ii. Project – Vertical Slice Architecture
iii. Conclusion
IV. Continuing your journey: A few tips and tricks
V. Summary
VI. Questions
VII. Further reading
VIII. Answers
19. 18 Request-EndPoint-Response (REPR) and Minimal APIs
I. Before you begin: Join our book community on Discord
II. Request-EndPoint-Response (REPR) pattern
i. Goal
ii. Design
iii. Project – SimpleEndpoint
iv. Conclusion
III. Project – REPR—A slice of the real-world
i. Assembling our stack
ii. Dissecting the code structure
iii. Exploring the shopping basket
iv. Managing exception handling
v. Grey-box testing
IV. Summary
V. Questions
VI. Further reading
VII. Answers
20. 19 Introduction to Microservices Architecture
I. Before you begin: Join our book community on Discord
II. What are microservices?
i. Cohesive unit of business
ii. Ownership of data
iii. Microservice independence
III. An introduction to event-driven architecture
i. Domain events
ii. Integration events
iii. Application events
iv. Enterprise events
v. Conclusion
IV. Getting started with message queues
i. Conclusion
V. Implementing the Publish-Subscribe pattern
i. Message brokers
ii. The event sourcing pattern
iii. Example
iv. Conclusion
VI. Introducing Gateway patterns
i. Gateway Routing pattern
ii. Gateway Aggregation pattern
iii. Backend for Frontend pattern
iv. Mixing and matching gateways
v. Conclusion
VII. Project – REPR.BFF
i. Layering APIs
ii. Running the microservices
iii. Creating typed HTTP clients using Refit
iv. Creating a service that serves the current customer
v. Features
vi. Conclusion
VIII. Revisiting the CQRS pattern
i. Advantages and potential risks
ii. Conclusion
IX. Exploring the Microservice Adapter pattern
i. Adapting an existing system to another
ii. Decommissioning a legacy application
iii. Adapting an event broker to another
iv. Conclusion
X. Summary
XI. Questions
XII. Further reading
XIII. Answers
21. 20 Modular Monolith
I. Before you begin: Join our book community on Discord
II. What is a Modular Monolith?
i. What are traditional Monoliths?
ii. What are microservices?
III. Advantages of Modular Monoliths
IV. Key Components of a Modular Monolith
V. Implementing a Modular Monolith
i. Planning the project
ii. Defining our stack
VI. Project—Modular Monolith
i. Sending events from the catalog module
ii. Consuming the events from the basket module
iii. Inside the aggregator
iv. Exploring the REST API HttpClient
v. Sending HTTP requests to the API
vi. Validating the existence of a product
VII. Transitioning to Microservices
VIII. Challenges and Pitfalls
IX. Conclusion
X. Questions
XI. Further reading
XII. An end is simply a new beginning
XIII. Answers
Architecting ASP.NET Core
Applications, Third Edition: An
atypical design patterns guide for
.NET 8, C# 12, and beyond
Welcome to Packt Early Access. We’re giving you an exclusive
preview of this book before it goes on sale. It can take many months
to write a book, but our authors have cutting-edge information to
share with you today. Early Access gives you an insight into the latest
developments by making chapter drafts available. The chapters may
be a little rough around the edges right now, but our authors will
update them over time.You can dip in and out of this book or follow
along from start to finish; Early Access is designed to be flexible. We
hope you enjoy getting to know more about the process of writing a
Packt book.
1. Chapter 1: Introduction
2. Chapter 2: Automated Testing
3. Chapter 3: Architectural Principles
4. Chapter 4: REST APIs
5. Chapter 5: Minimal API
6. Chapter 6: Model-View-Controller
7. Chapter 7: Strategy, Abstract Factory, and Singleton Design
Patterns
8. Chapter 8: Dependency Injection
9. Chapter 9: Options, Settings, and Configuration
10. Chapter 10: Logging patterns
11. Chapter 11: Structural Patterns
12. Chapter 12: Behavioral Patterns
13. Chapter 13: Understanding the Operation Result Design Pattern
14. Chapter 14: Layering and Clean Architecture
15. Chapter 15: Object Mappers, Aggregate Services, and Façade
16. Chapter 16: Mediator and CQRS Design Patterns
17. Chapter 17: Getting Started with Vertical Slice Architecture
18. Chapter 18: Request-EndPoint-Response (REPR) and Minimal
APIs
19. Chapter19: Introduction to Microservices Architecture
20. Chapter20: Modular Monolith
1 Introduction
Before you begin: Join our book community on Discord
Give your feedback straight to the author himself and chat to other early readers on our Discord
server (find the "architecting-aspnet-core-apps-3e" channel under EARLY ACCESS
SUBSCRIPTION).
https://packt.link/EarlyAccess
The goal of this book is not to create yet another design pattern book; instead, the chapters are
organized according to scale and topic, allowing you to start small with a solid foundation and build
slowly upon it, just like you would build a program.Instead of a guide covering a few ways of
applying a design pattern, we will explore the thought processes behind the systems we are designing
from a software engineer’s point of view.This is not a magic recipe book; from experience, there is no
magical recipe when designing software; there are only your logic, knowledge, experience, and
analytical skills. Let’s define “experience” as your past successes and failures. And don’t worry, you
will fail during your career, but don’t get discouraged by it. The faster you fail, the faster you can
recover and learn, leading to successful products. Many techniques covered in this book should help
you achieve success. Everyone has failed and made mistakes; you aren’t the first and certainly won’t
be the last. To paraphrase a well-known saying by Roosevelt: the people that never fail are the ones
who never do anything.At a high level:
This book explores basic patterns, unit testing, architectural principles, and some ASP.NET Core
mechanisms.
Then, we move up to the component scale, exploring patterns oriented toward small chunks of
software and individual units.
After that, we move to application-scale patterns and techniques, exploring ways to structure an
application.
Some subjects covered throughout the book could have a book of their own, so after this book,
you should have plenty of ideas about where to continue your journey into software architecture.
Here are a few pointers about this book that are worth mentioning:
The chapters are organized to start with small-scale patterns and then progress to higher-level
ones, making the learning curve easier.
Instead of giving you a recipe, the book focuses on the thinking behind things and shows the
evolution of some techniques to help you understand why the shift happened.
Many use cases combine more than one design pattern to illustrate alternate usage so you can
understand and use the patterns efficiently. This also shows that design patterns are not beasts
to tame but tools to use, manipulate, and bend to your will.
As in real life, no textbook solution can solve all our problems; real problems are always more
complicated than what’s explained in textbooks. In this book, I aim to show you how to mix and
match patterns to think “architecture” instead of giving you step-by-step instructions to
reproduce.
The rest of the introduction chapter introduces the concepts we explore throughout the book,
including refreshers on a few notions. We also touch on .NET, its tooling, and some technical
requirements.In this chapter, we cover the following topics:
Anti-patterns
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
An anti-pattern is the opposite of a design pattern: it is a proven flawed technique that will most
likely cause you trouble and cost you time and money (and probably give you headaches).An anti-
pattern is a pattern that seems a good idea and seems to be the solution you were looking for, but it
causes more harm than good. Some anti-patterns started as legitimate design patterns and were
labelled anti-patterns later. Sometimes, it is a matter of opinion, and sometimes the classification
can be influenced by the programming language or technologies.Let’s look at an example next. We
will explore some other anti-patterns throughout the book.
A God class is a class that handles too many things. Typically, this class serves as a central entity
which many other classes inherit or use within the application it is the class that knows and manages
everything in the system; it is the class. On the other hand, it is also the class that nobody wants to
update, which breaks the application every time somebody touches it: it is an evil class!The best
way to fix this is to segregate responsibilities and allocate them to multiple classes rather than
concentrating them in a single class. We look at how to split responsibilities throughout the book,
which helps create more robust software.If you have a personal project with a God class at its core,
start by reading the book and then try to apply the principles and patterns you learn to divide that
class into multiple smaller classes that interact together. Try to organize those new classes into
cohesive units, modules, or assemblies.To help fix God classes, we dive into architectural principles
in Chapter 3, Architectural Principles, opening the way to concepts such as responsibility
segregation.
Code smells
A code smell is an indicator of a possible problem. It points to areas of your design that could
benefit from a redesign. By “code smell,” we mean “code that stinks” or “code that does not smell
right.”It is important to note that a code smell only indicates the possibility of a problem; it does not
mean a problem exists. Code smells are usually good indicators, so it is worth analyzing your
software’s “smelly” parts.An excellent example is when a method requires many comments to
explain its logic. That often means that the code could be split into smaller methods with proper
names, leading to more readable code and allowing you to get rid of those pesky comments.Another
note about comments is that they don’t evolve, so what often happens is that the code described by a
comment changes, but the comment remains the same. That leaves a false or obsolete description of
a block of code that can lead a developer astray.The same is also true with method names.
Sometimes, the method’s name and body tell a different story, leading to the same issues.
Nevertheless, this happens less often than orphan or obsolete comments since programmers tend to
read and write code better than spoken language comments. Nonetheless, keep that in mind when
reading, writing, or reviewing code.
An excellent example of a code smell is using the new keyword. This indicates a hardcoded
dependency where the creator controls the new object and its lifetime. This is also known as the
Control Freak anti-pattern, but I prefer to box it as a code smell instead of an anti-pattern since
the new keyword is not intrinsically wrong.At this point, you may be wondering how it is possible not
to use the new keyword in object-oriented programming, but rest assured, we will cover that and
expand on the control freak code smell in Chapter 7, Deep Dive into Dependency Injection.
The long methods code smell is when a method extends to more than 10 to 15 lines of code. That is
a good indicator that you should think about that method differently. Having comments that
separate multiple code blocks is a good indicator of a method that may be too long.Here are a few
examples of what the case might be:
Usually, each problem has one or more solutions; you need to spot the problem and then find,
choose, and implement one of the solutions. Let’s be clear: a method containing 16 lines does not
necessarily need refactoring; it could be OK. Remember that a code smell indicates that there might
be a problem, not that there necessarily is one—apply common sense.
After that cycle, the server is no longer aware of the client. Moreover, if the client sends another
request, the server is unaware that it responded to a request earlier for that same client because
HTTP is stateless.There are mechanisms for creating a sense of persistence between requests for
the server to be “aware” of its clients. The most well-known of these is cookies.If we dig deeper, an
HTTP request comprises a header and an optional body. Then, requests are sent using a specific
method. The most common HTTP methods are GET and POST . On top of those, extensively used by
web APIs, we can add PUT , DELETE , and PATCH to that list.Although not every HTTP method accepts
a body, can respond with a body, or should be idempotent, here is a quick reference table:
An idempotent request is a request that always yields the same result, whether it is sent once or
multiple times. For example, sending the same POST request multiple times should create multiple
similar entities, while sending the same DELETE request multiple times should delete a single entity.
The status code of an idempotent request may vary, but the server state should remain the same. We
explore those concepts in more depth in Chapter 4, Model-View-Controller.Here is an example of a
GET request:
The HTTP header comprises a list of key/value pairs representing metadata that a client wants to
send to the server. In this case, I queried my blog using the GET method and Google Chrome
attached some additional information to the request. I replaced the Cookie header’s value with ...
because it can be pretty large and that information is irrelevant to this sample. Nonetheless, cookies
are passed back and forth like any other HTTP header.
The client sends cookies, and the server returns them for every request-response cycle. This
could kill your bandwidth or slow down your application if you pass too much information
back and forth (cookies or otherwise). One good example would be a serialized identity
cookie that is very large.
Another example, unrelated to cookies but that created such a back-and-forth, was the good
old Web Forms ViewState . This was a hidden field sent with every request. That field could
become very large when left unchecked.
Nowadays, with high-speed internet, it is easy to forget about those issues, but they can
significantly impact the user experience of someone on a slow network.
When the server decides to respond to the request, it returns a header and an optional body,
following the same principles as the request. The first line indicates the request’s status: whether it
was successful. In our case, the status code was 200 , which indicates success. Each server can add
more or less information to its response. You can also customize the response with code.Here is the
response to the previous request:
HTTP/1.1 200 OK
Server: GitHub.com
Content-Type: text/html; charset=utf-8
Last-Modified: Wed, 03 Oct 2018 21:35:40 GMT
ETag: W/"5bb5362c-f677"
Access-Control-Allow-Origin: *
Expires: Fri, 07 Dec 2018 02:11:07 GMT
Cache-Control: max-age=600
Content-Encoding: gzip
X-GitHub-Request-Id: 32CE:1953:F1022C:1350142:5C09D460
Content-Length: 10055
Accept-Ranges: bytes
Date: Fri, 07 Dec 2018 02:42:05 GMT
Via: 1.1 varnish
Age: 35
Connection: keep-alive
X-Served-By: cache-ord1737-ORD
X-Cache: HIT
X-Cache-Hits: 2
X-Timer: S1544150525.288285,VS0,VE0
Vary: Accept-Encoding
X-Fastly-Request-ID: 98a36fb1b5642c8041b88ceace73f25caaf07746
<Response body truncated for brevity>
Now that the browser has received the server’s response, it renders the HTML webpage. Then, for
each resource, it sends another HTTP call to its URI and loads it. A resource is an external asset,
such as an image, a JavaScript file, a CSS file, or a font.After the response, the server is no longer
aware of the client; the communication has ended. It is essential to understand that to create a
pseudo-state between each request, we need to use an external mechanism. That mechanism could
be the session-state leveraging cookies, simply using cookies, or some other ASP.NET Core
mechanisms, or we could create a stateless application. I recommend going stateless whenever
possible. We write primarily stateless applications in the book.
Note
If you want to learn more about session and state management, I left a link in the Further
reading section at the end of the chapter.
As you can imagine, the backbone of the internet is its networking stack. The Hypertext Transfer
Protocol (HTTP) is the highest layer of that stack (layer 7). HTTP is an application layer built on
the Transmission Control Protocol (TCP). TCP (layer 4) is the transport layer, which defines
how data is moved over the network (for instance, the transmission of data, the amount of
transmitted data, and error checking). TCP uses the Internet Protocol (IP) layer to reach the
computer it tries to talk to. IP (layer 3) represents the network layer, which handles packet IP
addressing.A packet is a chunk of data that is transmitted over the wire. We could send a large file
directly from a source to a destination machine, but that is not practical, so the network stack breaks
down large items into smaller packets. For example, the source machine breaks a file into multiple
packets, sends them to the target machine, and then the target reassembles them back into the
source file. This process allows numerous senders to use the same wire instead of waiting for the first
transmission to be done. If a packet gets lost in transit, the source machine can also send only that
packet back to the target machine.Rest assured, you don’t need to understand every detail behind
networking to program web applications, but it is always good to know that HTTP uses TCP/IP and
chunks big payloads into smaller packets. Moreover, HTTP/1 limits the number of parallel requests a
browser can open simultaneously. This knowledge can help you optimize your apps. For example, a
high number of assets to load, their size, and the order in which they are sent to the browser can
increase the page load time, the perceived page load time, or the paint time.To conclude this subject
and not dig too deep into networking, HTTP/1 is older but foundational. HTTP/2 is more efficient
and supports streaming multiple assets using the same TCP connection. It also allows the server to
send assets to the client before it requests the resources, called a server push.If you find HTTP
interesting, HTTP/2 is an excellent place to start digging deeper, as well as the HTTP/3 proposed
standard that uses the QUIC transport protocol instead of HTTP (RFC 9114). ASP.NET Core 7.0+
supports HTTP/3, which is enabled by default in ASP.NET Core 8.0.Next, let’s quickly explore .NET.
Applications
Libraries
Applications target a version of .NET, such as net5.0 and net6.0 . Examples of that would be an
ASP.NET application or a console application.Libraries are bundles of code compiled together, often
distributed as a NuGet package. .NET Standard class library projects allow sharing code between
.NET 5+, and .NET Framework projects. .NET Standard came into play to bridge the compatibility
gap between .NET Core and .NET Framework, which eased the transition. Things were not easy
when .NET Core 1.0 first came out.With .NET 5 unifying all the platforms and becoming the future of
the unified .NET ecosystem, .NET Standard is no longer needed. Moreover, app and library authors
should target the base Target Framework Moniker (TFM), for example, net8.0 . You can also
target netstandard2.0 or netstandard2.1 when needed, for example, to share code with .NET
Framework. Microsoft also introduced OS-specific TFMs with .NET 5+, allowing code to use OS-
specific APIs like net8.0-android and net8.0-tvos . You can also target multiple TFMs when
needed.
Note
I’m sure we will see .NET Standard libraries stick around for a while. All projects will not
just migrate from .NET Framework to .NET 5+ magically, and people will want to continue
sharing code between the two.
The next versions of .NET are built over .NET 5+, while .NET Framework 4.X will stay where it is
today, receiving only security patches and minor updates. For example, .NET 8 is built over .NET 7,
Random documents with unrelated
content Scribd suggests to you:
a hemisphere of stars. Ahead, above the horizon, was a crescent
moon that served to silhouette the hill and its horizon of trees.
Around them were dark shapes, motionless.
Earl kept the flashlight ready, but didn't use it as they stole swiftly
forward. Neither man spoke, but their breathing was a stentorian
sound that blended with distant traffic noises and the nearby chirping
of a cricket, and the rustling of weeds as they forced them aside in
their passage.
They reached the hill and went forward more slowly, using caution as
they remembered the effects of the paralysis gun. Now Earl was
remembering the way he had come before, finding landmarks in the
darkness. At last he stopped and touched Basil's arm to bring him to
a halt.
"It's on the other side of these bushes," he whispered. "I'll use the
flash."
He parted the branches. Suddenly a cone of light exploded in the
darkness.
"Right there," Basil said. Then, in surprise, "It's gone!"
"Naturally," Earl said in some disgust. "It fits the pattern."
"What pattern?" Basil asked.
Earl was slow in answering. He said, "I don't know. I just felt it. Or
maybe I do know. Nadine and that guy Ladd were small and got big
in a hurry. What was to keep that thing from doing the same? That's
part of it. The other part is just a feeling. They don't seem to want to
advertise to the world that they're here. Maybe the damn thing
became invisible or something. With stasis spheres and small people
that get big, and paralysis guns, what's so impossible about that ship
or whatever it is getting big and becoming invisible? I'll bet it's still
there."
But though they passed back and forth over the entire area, with
increasing boldness, they encountered nothing, visible or invisible,
that was out of the ordinary.
There was a concave depression in the soil where Earl remembered
the puffball shape to have been. Even fresh scars in the dirt around
the depression.
For a while Earl blundered through the underbrush calling Nadine's
name cautiously, without hope. Finally they were forced to give up
and return to the lab building.
"We could call the police," Basil said doubtfully.
"Oh, sure," Earl said, his voice harsh. "What would we tell them? Dr.
Glassman would be called in. Next they'd call the boys in the white
jackets."
"Maybe they're just the boys we need," Basil said. "Or a good stiff
drink. I like the idea of the drink."
It was ten o'clock in the morning when Irene Conner pushed open
the door without knocking and strolled casually into Earl's laboratory.
She saw him at the far end of the room, hunched over with his
elbows on the window sill, his back to her.
"Hi, Earl," she called cheerfully. "Want to have mid-morning coffee
with me?"
"No," Earl said without moving.
"You sound tired," Irene said, going over to stand beside him. "Or is
it spring fever—more accurately the summer doldrums."
"Neither," he said, glancing up at her with tired eyes. "I just want to
be left alone. I'm thinking." He straightened up with a deep sigh.
"Why don't you get Basil to have coffee with you?"
"That jerk?" Irene said. "He gets in my hair."
"Like you get in mine?" Earl said.
"That was cruel."
"Sorry," Earl relented. "I didn't get much sleep last night. I've got
problems. I'd much rather be left alone with them right now."
Irene inspected him critically as a man might inspect his automobile.
"Your eyes are bloodshot," she said. "Why not have some coffee with
me and tell me your problems. Maybe I can help you."
"Nobody can help me—least of all you."
The phone on the desk in the corner rang. Earl went to answer it.
"This is Glassman," the phone said. "I want a general staff meeting in
my office at once. Tell Dr. Conner she must be there too."
"Okay," Earl said. He hung up and looked at Irene. "Goat face," he
explained. "General staff meeting. We're to go to his office at once."
"Maybe this is it," Irene said, suddenly sober.
Earl nodded. That was the way it would come. A phone call for
general staff meeting. A quiet announcement that one of the
scientists had at last found the ideal nerve fluid for the brain. That's
all there would be to it. The greatest achievement since—if not
including—the atom bomb, and the historic moment would pass
without a shout—with perhaps only a tired sigh of relief, a glance of
envy at the lucky one who had found it.
"Well, let's get it over with," Earl said.
They went into the hall and walked side by side in silence toward the
back of the building where it joined the Dome. Basil joined them, for
once hardly noticing Irene as he looked questioningly at Earl, who
shook his head imperceptibly.
They entered Dr. Glassman's office. The director was sitting behind
his desk, ignoring them, pretending to be reading some typewritten
papers.
Earl looked around. They were all there now, he and the other nine
scientists, and Dr. Glassman. Only there was something wrong with
the picture. One of them should have been beaming at the others,
the light of triumph in his or her eyes. Instead, the other nine
reflected his own puzzled bewilderment.
"Sit down, sit down," Dr. Glassman said, looking up at them. He
waited until they were all seated about the room, then cleared his
throat importantly, pushing aside the papers he had been reading. He
started to say something, then became aware of their expressions.
He shook his head. "The end isn't in sight yet. But we may be closer
than we think. I'll introduce you in a moment to a new addition to
our staff. A person who—from the reports I've seen from Washington
—seems to be quite a genius at creating new type molecules, tailor-
made for specific tasks. Our new associate won't be assigned a
separate lab. Instead, will serve as a sort of general consultant,
observing all your work, and will make suggestions for hastening
things up a bit." A murmur of voices and sharp footsteps came from
the hall. "My wife has been showing our new colleague the Brain. I
think they're coming now."
The door opened. Mrs. Glassman's cheerful face appeared. "They're
all here now," she said over her shoulder.
The door opened farther. Earl, and everyone else, was staring at the
opening, waiting for their first glimpse of the newcomer.
Earl half rose to his feet before he stopped himself. Then he slowly
sat down, his eyes wide and puzzled.
It was Nadine. She wasn't wearing the clothes he had bought for her
the day before. Instead, she was dressed in a stylishly cut business
suit and low heeled slippers, a trim hat covering her hair. She had
paused just inside the room, a half smile on her carefully painted lips.
Her eyes surveyed each face pleasantly, passing over Earl's as though
she had never seen him before.
"Come up here, my dear," Dr. Glassman said in honeyed tones. And
to the others, "I want you to meet Dr. Nadine Holmes." Then back to
her, "What did you think of the Brain? Quite an imposing thing, isn't
it?"
"Yes, it is," Nadine replied. "I felt quite—awed by it, sitting there
where it will remain for untold centuries, waiting only for the vital
fluid that will give it the ability to think."
"I'm sure it won't be untold centuries before it gets the fluid," Dr.
Glassman said, chuckling heartily at his own humor. "I'll introduce
you to your co-workers, Dr. Holmes. This is Dr. Paul Hardwick...."
Earl caught Basil's attention and shook his head warningly. He waited,
then, for his turn at being introduced, his heart pounding violently,
his pulse racing.
"... and this is Dr. Earl Frye ..." Dr. Glassman said.
"How do you do, Dr. Frye." Nadine's hand was smooth and cool as
she rested it in his. Her eyes sized him up with impersonal interest,
but without a flicker of recognition.
"... and this is Dr. Basil Nelson ...."
Nadine withdrew her hand gently and moved on.
"And now you may return to your work," Dr. Glassman announced. "I
know the male members of the staff will be waiting for a visit from
our charming new member, but you must be patient. She will get
around to all of you in the next few days."
Earl was in the hall before Glassman had finished. He wanted to
think. Rapid footsteps caught up with him. "Now can we have
coffee?" she asked with humorous petulance.
"No!" Earl said with more fierceness in his voice than he had
intended. It had the effect of a physical blow on Irene. She fell back
a step, blinking.
Basil caught up with them. "I want to talk with you, Earl," he said.
"Basil," Irene cut in, "will you have coffee with me?"
"Me?" Basil said in delight. "Sure." He linked his arm in hers. "Let's
go." He looked back over his shoulder at Earl. "Thanks, Earl," he said.
"I'll see you later." It was two hours later.
"You sure it's her?" Basil said. "I'm inclined to agree with you. Of
course, I saw her only for a second or two.... Where do you suppose
she picked up those snazzy clothes? I was watching her when she
was introduced to you. Boy, is she some actress!"
"I'm wondering if it was an act," Earl said frowning.
"Of course it was—had to be if she's the same girl. But she didn't let
on she knew you at all."
"That's why I wonder if it was an act. There was something strange
about her. I can't quite put my finger on it—or yes I can. She's
changed. Today her whole personality is different. And where did she
get papers authentic enough to fool Glassman?"
"Why don't you ask her when she comes here?" Basil suggested.
Earl shook his head. "I wonder if she could be under some sort of
hypnosis? No, wait. It isn't any more absurd than a paralysis gun. If
she doesn't stay here tonight I'm going to follow her and see where
she goes. Are you with me?"
"Uh," Basil hesitated. "Depends on when she leaves the building.
Irene and I have sort of a date to have dinner at the Red Barn at six
o'clock."
"Go ahead," Earl said, grinning. "I'll probably have more success
alone anyway. We'd get in each other's way."
"Why don't you ask Glassman where she's staying? It's probably
some hotel in town."
"I'll think about it," Earl said.
When Basil left, Earl went to the window and looked toward the hill.
Would Nadine go there? Was there some hiding place on the hill
where she would go, to wait until tomorrow, after her "day's work"
was done?
Earl nodded to himself. It had to be. Nothing else fitted into the crazy
pattern of events.
One thing he was certain of now. In spite of the accident that had
broken open the "ship" when it landed out there, its coming here—or
here and now—was no accident. Nor Nadine's apparent familiarity
with his name the night before, or her showing up now with
credentials that gave her the run of the place in an almost
supervisory capacity.
And that meant that her interest was in the Brain. Hers—and who
else? George Ladd, of course. How many more? If each of those
stasis spheres had contained a person, there were dozens more in on
it.
Then why had Nadine been sent into the open when she was certain
to be recognized by him?
That was what had been bothering him from the instant she walked
into Glassman's office. On the surface it was the most stupid thing
that could have occurred. On the surface....
Stupid. Yet somehow stupid didn't seem to fit. Maybe it had been
exceedingly cunning. Maybe there was something he had missed.
Cunning it might be—or stupid. But there was something else about it
that neither adjective quite fit. There was obviously organization in
back of Nadine. People. A "ship". Paralysis guns and what they
implied. Therefore planning, colored by one accident. Suppose every
detail of the plan had been worked out ahead of time, and was going
ahead without alteration. Suppose the original plan had specified that
Nadine was to be the "front", and the plan was proceeding blindly, on
the behavior level of instinct in animals who repeat instinctive
routines made senseless by changed environment. Or the blind
function level of a machine that keeps turning out parts when the
conveyor belt has stopped, until it wrecks itself.
It annoyed Earl not to be able to pin his thoughts down, to bring
everything into full focus.
Scarcely fifteen feet away she came to a stop and turned to face
toward the concave depression in the ground, another fifty feet
beyond her. With her free hand she reached up and patted at her hair
like any normal girl would do, unconsciously.
Abruptly Earl became aware of something just beyond her. It wasn't
tangible. A shimmering in the air. A slight but definite refractive
quality that had not been there the moment before.
Nadine had seen it too. She walked forward a few steps.
"This is it!" Earl thought to himself. He crouched to run after her.
She took another step. She vanished, not abruptly, but as one might
vanish into a bright silver but otherwise transparent fog.
In that instant Earl moved hurtling forward so that when she
disappeared he was a step behind her.
Instantly the peaceful wooded scene vanished. His feet were on a
smooth hard floor. Ahead of him he caught a brief glimpse of walls, of
people without clothes.
Then he was falling over Nadine and trying to keep from falling on
her. His arms were around her. Somehow he twisted so that when he
landed she was on top, unhurt.
There was a stunned eternity when her eyes were looking into his,
recognition and gladness unmasked, hope and pleading sending him
some secret message, some unspoken word trembling on her lips.
But Earl had seen George Ladd even as he fell, and the never
forgotten instincts developed in him during World War III were in
motion, making him continue his roll so that in the next instant he
was on his feet, Nadine behind him. Ladd hadn't expected this and
was caught by surprise. Earl took advantage of that brief uncertainty,
stepping in and bringing a short chopping right against Ladd's jaw.
Before George Ladd reached the floor, Earl was running in great
strides, his eyes darting ahead in search of a place to escape.
"Wait!" Nadine called. But he didn't pause. He couldn't trust her.
George Ladd had been armed with his paralysis gun. He'd been
waiting for him. This had been a trap, and Nadine had led him into it.
Ahead was a doorway. He hesitated. Should he continue on down the
corridor or take the doorway? He decided on the latter. It opened into
a room, unoccupied at the moment. There were windows. One of
them was open. Earl didn't hesitate. Beyond the window was a wide
paved street. If he could get away, mingle with crowds....
No one was in sight. He sprinted along the pavement, away from the
Dome which he had glimpsed over his shoulder. It was beautiful, its
basic structure adorned with granite superstructures of fine
workmanship. But he didn't pause to admire it. He wanted people,
lots of people, to mix with and hide from pursuit.
For a hundred yards the street went through parkways. Then ahead
were buildings. He reached them, racing along a canyon formed by
windowless walls of buildings. He rounded a corner. The street was
still deserted.
He ran on and on, turning corners when he came to them, but
always heading in one general direction so as not to circle back
toward the Dome.