C# 7 and .NET Core 2.0 High Performance
Build highly performant, multi-threaded, and concurrent applications using C# 7 and .NET Core 2.0
Ovais Mehboob Ahmed Khan
BIRMINGHAM - MUMBAI
C# 7 and .NET Core 2.0 High Performance
Copyright 2018 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.
Commissioning Editor: Merint Mathew
Acquisition Editor: Chaitanya Nair
Content Development Editor: Anugraha Arunagiri
Technical Editor: Jijo Maliyekal
Copy Editor: Safis Editing
Project Coordinator: Ulhas Kambali
Proofreader: Safis Editing
Indexer: Tejal Daruwale Soni
Graphics: Tania Dutta
Production Coordinator: Deepika Naik
First published: April 2018
Production reference: 1240418
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.
ISBN 978-1-78847-004-9
www.packtpub.com
mapt.io
Mapt is an online digital library that gives you full access to over 5,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
Mapt is fully searchable
Copy and paste, print, and bookmark content
PacktPub.com
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 www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at service@packtpub.com for more details.
At www.PacktPub.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 author
Ovais Mehboob Ahmed Khan is a seasoned programmer and solution architect with over 14 years of software development experience. He has worked in organizations across Pakistan, the USA, and the Middle East. Currently, he is working for a government entity based in Dubai. A Microsoft MVP, he specializes mainly in Microsoft .NET, the cloud and web development. He has published technical articles on MSDN, TechNet, personal blog, and he has authored two other books published by Packt: JavaScript for .NET Developers and Enterprise Application Architecture with .NET Core.
I would like to thank my family for supporting me, especially my mother, wife, and brother, who have always encouraged me in every goal of my life. My father, may he rest in peace, would have been proud of my achievements.
About the reviewer
Jalpesh Vadgama has been working on technologies like .NET such as MVC, ASP.NET Core, Web Forms, and REST APIs for over 14 years now. Experienced in open source server-side technologies such as Node.js, he has worked with frameworks such as jQuery, Knockout.js, Angular, React.js and Vue. He has been awarded the Microsoft MVP award six times for his technical contribution to .NET and has delivered over 50 Enterprise-level applications using .NET technologies. He has also been using software development methodologies such as Agile, Scrum, and Waterfall for quite a while.
I would like to thank my wife and family for their support.
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
The book begins with an introduction to the new features of C# 7 and .NET Core 2.0, and how they help improve the performance of your application. The book will then help you understand the core internals of .NET Core, which includes the compilation process, garbage collection, utilizing multiple cores of the CPU to develop highly-performant applications, and measuring performance using a powerful library for benchmarking applications named BenchmarkDotNet. W e will learn about developing applications and programs using multithreading and asynchronous programming, and how to use those concepts to build efficient applications for faster execution. Next, you'll understand the importance of data structure optimization and how it can be used efficiently. We move on to the patterns and best practices to use when designing applications in .NET Core, along with how to utilize memory in an effective way and avoid memory leakage. After that, we'll talk about implementing security and resiliency in .NET Core applications, and we'll use the Polly framework to implement a circuit breaker, and retry and fallback patterns, along with certain middleware to harden the HTTP pipeline. We'll also implement security such as authorization and authentication using the Identity framework. Moving ahead, we will learn about the microservices architecture and see how we can use it to create applications that are modular, highly scalable, and independently deployable. We end with App Metrics, and will learn how to use it to monitor the performance of your application.
Who this book is for
This book is for .NET developers who want to improve the speed of their application's code or who simply want to take their skills to the next level, where they can develop and produce quality applications that are not only performant but also adhere to the industry best practices. Basic C# knowledge is assumed.
What this book covers
, What's New in .NET Core 2 and C# 7? , discusses the .NET Core Framework and covers some improvements that were introduced with .NET Core 2.0. We will also look into the new features of C# 7 and see how we can write cleaner code and simplify syntactic expressions. Lastly, we cover the topic of writing quality code. We'll see how we can leverage the Code analysis feature of Visual Studio 2017 to add analyzers to our project and improve code quality.