Adopting .NET 5
Total Page:16
File Type:pdf, Size:1020Kb
Adopting .NET 5 Understand modern architectures, migration best practices, and the new features in .NET 5 Hammad Arif Habib Qureshi BIRMINGHAM—MUMBAI Adopting .NET 5 Copyright © 2020 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 authors, 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: Aaron Lazar Publishing Product Manager: Richa Tripathi Senior Editor: Nitee Shetty Content Development Editor: Ruvika Rao Technical Editor: Pradeep Sahu Copy Editor: Safis Editing Project Coordinator: Deeksha Thakkar Proofreader: Safis Editing Indexer: Pratik Shirodkar Production Designer: Jyoti Chauhan First published: December 2020 Production reference: 1291220 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-80056-056-7 www.packt.com To my wife, Sidrah, who assumed a disproportionate share of our responsibilities so that I could focus on this book. And to my children, Shanzay and Aaliyah, both of whom are now excited to resume playtime with me. – Hammad Arif I would like to dedicate these efforts to my beautiful wife for her support throughout my life, to my mother for my upbringing, and to my two children, who look up to their father and who one day will build on the things they aspire to and give back a lot to this wonderful world in which we live. – Habib Qureshi 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 professionals • Improve your learning with Skill Plans built especially for you • Get a free eBook or video every month • Fully searchable for easy access to vital information • Copy 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 [email protected] 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. Contributors About the authors Hammad Arif is a passionate IT leader and speaker with over 16 years' experience in architecture, design, and implementing cutting-edge solutions to address business opportunities for enterprise applications. He earned his bachelor's degree in computer science and has previously worked as a solutions architect on Microsoft platforms. Based in Sydney, Hammad is currently leading a software development team that builds solutions on Azure and AWS platforms that serves all the top-tier financial institutions in Australia. Comparing my initial drafts with the final copy, I can see a noticeable improvement that would not have been possible without the expert guidance from the Packt editorial team. In particular, I'd like to thank Ruvika Rao for the painstaking effort of thoroughly ensuring content quality and proposing improvements, often multiple times. I also wish to thank my experienced co-author, Habib Qureshi. His advice was invaluable during every step of my first book authoring journey. Habib Qureshi is an integration architect and lead developer with almost two decades of professional experience in the software industry. He has worked with start-ups and enterprises, successfully delivering high-quality solutions in an agile manner. He has experience in multiple countries and cultures with on-site, off-site, and remote teams. He is a go-getter and teams always look up to him for technical reviews and solutions. First of all, I would like to thank Neha Sharma for reaching out to me at a time when I was ready to author another book. Next, I would like to thank all of the Packt team, who were very helpful and communicative from start to finish, especially Ruvika as the content editor, who was very interactive and helped us to reach our set targets on time. About the reviewers Omprakash Pandey, a Microsoft 365 consultant, has been working with industry experts to understand project requirements and work on the implementation of projects for the last 20 years. He has trained more than 50,000 aspiring developers and has assisted in the development of more than 50 enterprise applications. He has offered innovative solutions on .NET development, Microsoft Azure, and other technologies. He has worked for multiple clients across various locations, including Hexaware, Accenture, Infosys, and many more. He has been a Microsoft Certified Trainer for more than 5 years. Senthil Kumar is a Microsoft MVP in Visual Studio technologies. He is a co-author of the book Windows 10 Development Recipes Using JavaScript and CSS, published by Apress. Senthil has been working in the IT industry for over 9 years now and has had exposure to a variety of languages, including C#, JavaScript, PHP, and others. 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 Section 1: Features and Capabilities 1 Introducing .NET 5 Features and Capabilities Technical requirements 20 What are the .NET 5 headliners? 30 Evolution of .NET 21 Discovering self-contained applications 30 Discovering the distinguishing .NET 5 app trimming optimizations 33 factors in .NET versions 22 ReadyToRun 34 Understanding the advantages of one Developing programs for .NET 34 over the other 23 Performance improvements 35 What is the outlook for jumping Why performance is so important? 35 to .NET 5? 25 Performance improvements in .NET Types of applications developed versions 37 using .NET 26 Let's do some benchmarking 41 Web applications 26 .NET release schedule 48 Mobile development 27 .NET support life cycle 49 Desktop applications 27 .NET Framework support 50 Internet of Things 28 .NET Core support 50 Cloud-native development and microservices 28 Summary 51 Machine learning 28 Visual Studio solution templates for .NET 28 ii Table of Contents 2 What's New in C# 9? Technical requirements 54 Letting the new keyword infer the type Having prior knowledge of C# 54 for us 71 Embracing other productivity The .NET Framework enhancements 73 requirements to use C# 9 54 Leveraging performance Configuring LINQPad 6 for .NET 5 and improvements 78 C# 9 55 Introducing Span<T> 78 Understanding what's new in Choosing the winner – Substring C# 9 57 versus Slice showdown 79 Writing concise code with pattern Utilizing .NET library performance matching 58 improvements 81 Keeping track of changes – immutable records 65 Summary 81 Further reading 82 Section 2: Design and Architecture 3 Design and Architectural Patterns Technical requirements 86 communication 97 Why should we follow design Standard communication protocols 98 strategies? 86 Architectural patterns 99 Application design patterns 87 Monolith application architecture 100 Refreshing the GoF design patterns 87 Microservices architecture 101 Refresher of the SOLID design principles 89 Backend for Frontend (BFF) 102 Dependency injection 90 Serverless architecture 104 The Repository pattern 93 Enterprise Service Bus (ESB) 105 Communication styles and Distributed processing 106 protocols 97 Summary 110 Synchronous and asynchronous Table of Contents iii 4 Containerized Microservices Architecture Technical requirements 112 WSL as a Docker engine 126 Why overview other topics and What is Tye? 127 not just microservices? 113 Introduction to containerization The gRPC communication and container orchestration 127 protocol 113 What are some modern container HTTP/2 and Protobuf 114 fundamentals? 128 gRPC versus REST APIs versus SOAP 114 Kubernetes basics 130 What's new with gRPC in .NET 5? 116 Sample service proto file 116 Let's build a demo microservices application 132 What is WSL? 118 What is the application? 133 Installing WSL on your development Architecture for the demo application 133 machine 119 Developing the microservices Some useful VS Code-related application 136 extensions 122 Things to check before you start Summary 163 debugging with WSL 125 Further reading 164 Section 3: Migration 5 Upgrading Existing .NET Apps to .NET 5 Technical requirements