Customizing ASP.NET Core 5.0 - Jürgen Gutsch - E-Book

Customizing ASP.NET Core 5.0 E-Book

Jürgen Gutsch

0,0
27,59 €

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

ASP.NET Core is the most powerful Microsoft web framework. Although it’s full of rich features, sometimes the default configurations can be a bottleneck and need to be customized to suit the nature and scale of your app. If you’re an intermediate-level .NET developer who wants to extend .NET Core to multiple use cases, it's important to customize these features so that the framework works for you effectively.
Customizing ASP.NET Core 5.0 covers core features that can be customized for developing optimized apps. The customization techniques are also updated to work with the latest .NET 5 framework.
You’ll learn essential concepts relating to optimizing the framework such as configuration, dependency injection, routing, action filters, and more. As you progress, you’ll be able to create custom solutions that meet the needs of your use case with ASP.NET Core. Later chapters will cover expert techniques and best practices for using the framework for your app development needs, from UI design to hosting. Finally, you’ll focus on the new endpoint routing in ASP.NET Core to build custom endpoints and add third-party endpoints to your web apps for processing requests faster.
By the end of this application development book, you’ll have the skills you need to be able to customize ASP.NET Core to develop robust optimized apps.

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

EPUB
MOBI

Seitenzahl: 115

Veröffentlichungsjahr: 2021

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.



Customizing ASP.NET Core 5.0

Turn the right screws in ASP.NET Core to get the most out of the framework

Jürgen Gutsch

BIRMINGHAM—MUMBAI

Customizing ASP.NET Core 5.0

Copyright © 2021 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(s), 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.

Group Product Manager: Ashwin Nair

Publishing Product Manager: Pavan Ramchandani 

Senior Editor: David Sugarman 

Content Development Editor: Abhishek Jadhav

Technical Editor: Saurabh Kadave

Copy Editor: Safis Editing 

Project Coordinator: Kinjal Bari 

Proofreader: Safis Editing 

Indexer: Rekha Nair

Production Designer: Jyoti Chauhan 

First published: January 2021

Production reference: 1270121

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham

B3 2PB, UK.

ISBN 978-1-80107-786-6

www.packt.com

To my family, friends, colleagues, and the .NET developer community, who supported and encouraged me to do this work. To my three sons, who gave me the power to complete it.

– Jürgen Gutsch

Packt.com

Subscribe to our online digital library for full access to over 7,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website.

Why subscribe?

Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionalsImprove your learning with Skill Plans built especially for youGet a free eBook or video every monthFully searchable for easy access to vital informationCopy and paste, print, and bookmark content

Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at packt.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at customercare@packtpub.com for more details.

At www.packt.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks.

Foreword

I have known Jürgen for more than 7 years and he never ceases to impress me with his knowledge and his experience in software development and web development, his expertise in ASP.NET Core and Azure solutions, and his consultancy and software architecture skills. Jürgen has been involved with ASP.NET since the first releases and has a vast amount of experience with all the .NET and .NET Core versions. His journey has now moved on to Azure and application development in the cloud using the latest ASP.NET Core technologies, Azure DevOps, and cloud-based solutions.

Jürgen is one of the leading community experts in the Swiss and German region and is extremely active in this field. You will always find him present at the local conferences, .NET Core meetups, and Microsoft events, or organizing these events himself. He has been a Microsoft MVP for Developer Technologies since 2015 and I have had the pleasure to develop and learn from him by implementing solutions using some of the early versions and pre-releases of ASP.NET Core or solutions such as ASP.NET Core health checks. He is always helping the .NET community by giving them a chance to speak at meetups and offering speakers a platform. I did my first .NET user group talk in Basel with his help and support.

Above all, he is always there as a friend and I can always ask for support or his help in solving problems and he helps make the .NET community in Switzerland so strong, helpful, and easy for others to join and improve.

Damien Bowden

Blogger on damienbod.com, Microsoft MVP for Developer Technologies, and Senior Software Consultant.Well known on Twitter as @damien_bod

Contributors

About the author

Jürgen Gutsch is a .NET-addicted web developer from southern Germany. He has been working with .NET and ASP.NET since the early versions in 2002. Before that, he wrote server-side web applications using classic ASP. He is also an active member of the .NET developer community, speaking at conferences and user group events. Jürgen writes for developer magazines; he also publishes articles on his blog and contributes to several open source projects.

Jürgen has been a Microsoft MVP for Developer Technologies since 2015.

He works as a developer, consultant, and trainer for the digital agency YOO Inc. located in Basel (Switzerland). YOO Inc. serves national, as well as international, clients and specializes in creating custom digital solutions for distinct business needs.

You'll find Jürgen on Twitter at @sharpcms.

I want to thank Oli, Kathrin, Marcel, and Maxi for their support and motivation.

About the reviewer

Toi B. Wright has been a Microsoft MVP in ASP.NET for 16 years and is also an ASP Insider. She is an experienced full-stack software developer, book author, courseware author, speaker, and community leader with over 25 years of experience. She has a BS in computer science and engineering from the Massachusetts Institute of Technology (MIT) and an MBA from Carnegie Mellon University (CMU).

Packt is searching for authors like you

If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea.

Table of Contents

Preface

Chapter 1: Customizing Logging

Technical requirements

Configuring logging

Creating a custom logger

Plugging in an existing third-party logger provider

Summary

Chapter 2: Customizing App Configuration

Technical requirements

Configuring the configuration

Using typed configurations

Configuration using INI files

Configuration providers

Summary

Further reading

Chapter 3: Customizing Dependency Injection

Technical requirements

Using a different dependency injection container

Looking at the ConfigureServices method

Using a different ServiceProvider type

Registering dependencies with ConfigureContainer

Introducing Scrutor

Summary

Chapter 4: Configuring and Customizing HTTPS with Kestrel

Technical requirements

Introducing Kestrel

Setting up Kestrel

For your safety

Summary

Chapter 5: Using IHostedService and BackgroundService

Technical requirements

Introducing IHostedService

Introducing BackgroundService

Implementing the new Worker Service projects

Summary

Chapter 6: Writing Custom Middleware

Technical requirements

Introducing middleware

Writing a custom middleware

Exploring the potential of middleware

Branching the pipeline with /map

Branching the pipeline with MapWhen()

Creating conditions with middleware

Using middleware on ASP.NET Core 3.0 and later

Rewriting a terminating middleware to current standards

Summary

Chapter 7: Content Negotiation Using a Custom OutputFormatter

Technical requirements

Introducing OutputFormatters

Preparing a test project

Testing the Web API

Creating custom OutputFormatters

Summary

Chapter 8: Managing Inputs with Custom ModelBinders

Technical requirements

Introducing ModelBinders

Preparing the test data

Preparing the test project

Creating PersonsCsvBinder

Using ModelBinder

Testing ModelBinder

Summary

Further reading

Chapter 9: Creating a Custom ActionFilter

Technical requirements

Introducing ActionFilters

Using ActionFilters

Summary

Further reading

Chapter 10: Creating Custom TagHelpers

Technical requirements

Introducing TagHelpers

Creating custom TagHelpers

Examining a more complex scenario

Summary

Further reading

Chapter 11: Configuring WebHostBuilder

Technical requirements

Re-examining WebHostBuilderContext

How does it work?

Summary

Chapter 12: Using Different Hosting Models

Technical requirements

Setting up WebHostBuilder

Setting up Kestrel

Setting up HTTP.sys

Hosting on IIS

Using NGINX or Apache on Linux

Configuring NGINX

Configuring Apache

Summary

Further reading

Chapter 13: Working with Endpoint Routing

Technical requirements

Exploring endpoint routing

Creating custom endpoints

Creating a more complex endpoint

Summary

Other Books You May Enjoy

Preface

ASP.NET Core is the most powerful web framework provided by Microsoft and is full of hidden features that make it even more powerful and useful.

Your application should not be made to match the framework; your framework should be able to do what your application really needs. With this book, you will learn how to find the hidden screws you can turn to get the most out of the framework.

Developers working with ASP.NET Core will be able to put their knowledge to work with this practical guide to customizing ASP.NET Core. The book provides a hands-on approach to implementation and its associated methodologies that will have you up and running and productive in no time.

This book is a compact collection of default ASP.NET Core behaviors you might want to change and step-by-step explanations of how to do so.

By the end of this book, you will know how to customize ASP.NET Core to get an optimized application out of it according to your individual needs.

ASP.NET Core architecture overview

To follow the next chapters, you should be familiar with the base architecture of ASP.NET Core and its components. This book tackles almost all of the components of the architecture.

The next figure shows the base architecture overview of ASP.NET Core 5.0. Let’s quickly go through the components shown here from the bottom to the top layer:

On the bottom, there is the Hosting layer. This is the layer that bootstraps the web server and all the stuff that is needed to start up an ASP.NET Core application, including logging, configuration, and the service provider. This layer creates the actual request objects and their dependencies that are used in the layers above.

The next layer above Hosting is the Middleware layer. This one works with the request object or manipulates it. This attaches the middleware to the request object. It executes the middleware for things such as error handling, authenticating HSTS, CORS, and so on.

Above that, there is the Routing layer, which routes the request to the endpoints depending on the route patterns defined. Endpoint routing is the new player from ASP.NET Core 3.1, and separates routing from the UI layers above to enable routing for different endpoints including Blazor, gRPC, and SignalR. As a reminder: in previous versions of ASP.NET Core, routing was part of the MVC layer, and every other UI layer needed to implement its own routing.

The actual endpoints are provided by the fourth layer, the UI layer, which contains the well-known UI frameworks Blazor, gRPC, SignalR, and MVC. This is where you will do the most of your work as an ASP.NET Core developer.

Lastly, above MVC, you will find WebAPI and Razor Pages.

What is covered in this book?

This book doesn’t cover all the topics mentioned in the architecture overview. This book covers most topics of the hosting layer, because that is the layer that contains the most things you might need to customize. This book tackles middleware and routing, as well as MVC features and some more WebAPI topics, where you can do some magic tricks.

At the beginning of each chapter, we will indicate to which level the topic belongs.

What is not covered and why?

This book doesn’t cover Razor Pages, SignalR, gRPC, and Blazor.

The reason is that gRPC and SignalR are already very specialized, and don’t really need to be customized. Blazor is a new member of the ASP.NET Core family and is not widely used yet. Also, the author isn’t familiar enough with Blazor to know all the screws to customize it. Razor Pages is on top of the MVC framework and customizations for MVC are also valid for Razor Pages.

Who this book is for

This book is for web developers working with ASP.NET Core, who might need to change default behaviors to get things done. The readers should have basic knowledge of ASP.NET Core and C#, since this book does not cover the basics of those technologies. The readers should also have a good knowledge of Visual Studio, Visual Studio Code, or any other code editor that supports ASP.NET Core and C#.

What this book covers

Chapter 1, Customizing Logging, teaches you how to customize the logging behavior and how to add a custom logging provider.

Chapter 2, Customizing App Configuration, helps you understand how to use different configuration sources and add custom configuration providers.

Chapter 3, Customizing Dependency Injection, teaches you how Dependency Injection (DI) works and how to use a different DI container.

Chapter 4, Configuring and Customizing HTTPS with Kestrel, looks into configuring HTTPS differently.

Chapter 5, Using IHostedService and BackgroundService, makes you understand how to execute tasks in the background.

Chapter 6, Writing Custom Middleware, deals with the HTTP context using middleware.

Chapter 7, Content Negotiation Using a Custom OutputFormatter, teaches you how to output different content types based on the HTTP Accept header.

Chapter 8, Managing Inputs with Custom ModelBinders, helps you create input models with different types of content.

Chapter 9, Creating a Custom ActionFilter, uncovers aspect-oriented programming using ActionFilters.

Chapter 10, Creating Custom TagHelpers, enables you to simplify the UI layer by creating TagHelpers.

Chapter 11, Configuring WebHostBuilder, helps you understand how to set up configuration on the hosting layer.

Chapter 12, Using Different Hosting Models, teaches you about different types of hosting on different platforms.

Chapter 13, Working with Endpoint Routing, helps you understand how to use the new routing to provide custom endpoints.

To get the most out of this book

The readers should have basic knowledge of ASP.NET Core and C#, as well as of Visual Studio, Visual Studio Code, or any other code editor that supports ASP.NET Core and C#.



Tausende von E-Books und Hörbücher

Ihre Zahl wächst ständig und Sie haben eine Fixpreisgarantie.