Reader small image

You're reading from  C# 7 and .NET Core 2.0 High Performance

Product typeBook
Published inApr 2018
Reading LevelBeginner
Publisher
ISBN-139781788470049
Edition1st Edition
Languages
Right arrow
Author (1)
Ovais Mehboob Ahmed Khan
Ovais Mehboob Ahmed Khan
author image
Ovais Mehboob Ahmed Khan

Ovais Mehboob Ahmed Khan is a seasoned programmer and solution architect with nearly 20 years of experience in software development, consultancy, and solution architecture. He has worked with various clients across the world and is currently working as a senior customer engineer at Microsoft. He specializes mainly in application development using .NET and OSS technologies, Microsoft Azure, and DevOps. He is a prolific writer who has written several books and articles on various technologies. He really enjoys talking about technology and has given a number of technical sessions around the world.
Read more about Ovais Mehboob Ahmed Khan

Right arrow

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. We 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

Chapter 1, 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.

Chapter 2, Understanding .NET Core Internals and Measuring Performance, discusses the core concepts of .NET Core, including the compilation process, garbage collection, building highly-performant .NET Core applications utilizing multiple cores of the CPU, and publishing an application using a release build. We will also explore the benchmarking tool that is highly used for code optimization and provides results specific to in-memory objects.

Chapter 3, Multithreading and Asynchronous Programming in .NET Core, explores the core fundamentals of multithreaded and asynchronous programming. The chapter starts with the basic differences between multithreaded and asynchronous programming and walks you through the core concepts. It explores APIs and how to use them when writing a multithreaded application. We will learn how the Task Programming Library can be used to serve asynchronous operations, and how to implement the Task Asynchronous pattern. Lastly, we will explore parallel programming techniques and some of the best design patterns being used.

Chapter 4, Data Structures and Writing Optimized Code in C#, outlines the core concepts of data structures, the types of data structure, and their advantages and disadvantages, followed by the best possible scenarios to which each data structure is suited. We also learn about the Big O notation, which is one of the core topics to consider when writing code and helps developers check the quality of the code and performance. Lastly, we will look into some best practices and cover topics such as boxing and unboxing, string concatenation, exception handling, for and foreach, and delegates.

Chapter 5, Designing Guidelines for .NET Core Application Performance, showcases some coding principles that make application code look clean and easy to understand. If the code is clean, it offers other developers a way to understand it completely and helps in many other ways. We will learn some basic design principles that are considered to be part of the core principles when designing applications. Principles such as KISS, YAGNI, DRY, Separation of Concerns, and SOLID are highly essential in software design, and caching and choosing the right data structure have a significant impact on performance, and can improve performance if they are properly used. Lastly, we will learn some best practices that should be considered when handling communication, resource management, and concurrency.

Chapter 6, Memory Management Techniques in .NET Core, outlines the underlying process of how memory management is done in .NET. We will explore the debugging tool, which can be used by developers to investigate the object's memory allocation on the heap. We will also learn about memory fragmentation, finalizers, and how to implement a dispose pattern to clean up resources by implementing the IDisposable interface.

Chapter 7, Securing and Implementing Resilience in .NET Core Applications, takes you through resiliency, which is a very important factor when developing highly-performant applications in .NET Core. We will learn different policies and use the Polly framework to use those policies in .NET Core. We will also learn about safe storage mechanisms and how to use them in the development environment in order to keep sensitive information separate from the project repository. At the end of this chapter, we will learn some security fundamentals, which include SSL, CSRF, CORS, security headers, and the ASP.NET Core Identity framework, in order to protect ASP.NET Core applications.

Chapter 8, Microservices Architecture, looks at the most quickly evolving software architecture for developing highly performant and scalable applications for the cloud based on microservices. We will learn some of the core fundamentals of the microservices architecture, its benefits, and patterns and practices used when designing the architecture. We will discuss certain challenges faced when decomposing enterprise applications into the microservices architecture style and learn patterns such as API composition and CQRS in order to address them. Later in the chapter, we will develop a basic application in .NET Core and discuss the solution's structure and the components of microservices. Then we will develop identity and vendor services.

Chapter 9, Monitoring Application Performance Using Tools, dives into key performance metrics that are essential for monitoring an application's performance. We will explore and set up App Metrics, which is a free tool that is cross-platform and provides various extensions that can be used to achieve extensive reporting. We will go through a step-by-step guide on how to configure and set up App Metrics and related components, such as InfluxDb and Grafana, which is used to store and view telemetry in the Grafana web-based tool and integrate it with ASP.NET Core application.

To get the most out of this book

The readers should be equipped with the following configurations of the environment:

  1. Development Environment: Visual Studio 2015/2017 Community Edition
  2. Execution Environment: .NET Core
  3. OS Environment: Windows or Linux

Download the example code files

You can download the example code files for this book from your account at www.packtpub.com. If you purchased this book elsewhere, you can visit www.packtpub.com/support and register to have the files emailed directly to you.

You can download the code files by following these steps:

  1. Log in or register at www.packtpub.com.
  2. Select the SUPPORT tab.
  3. Click on Code Downloads & Errata.
  4. Enter the name of the book in the Search box and follow the onscreen instructions.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR/7-Zip for Windows
  • Zipeg/iZip/UnRarX for Mac
  • 7-Zip/PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/C-Sharp-7-and-NET-Core-2-High-Performance/. In case there's an update to the code, it will be updated on the existing GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Download the color images

Conventions used

There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "Mount the downloaded WebStorm-10*.dmg disk image file as another disk on your system."

A block of code is set as follows:

public static IWebHost BuildWebHost(string[] args) => 
WebHost.CreateDefaultBuilder(args)
.UseMetrics()
.UseStartup<Startup>()
.Build();

Any command-line input or output is written as follows:

Install-Package App.Metrics 
Install-Pacakge App.Metrics.AspnetCore.Mvc

Bold: Indicates a new term, an important word, or words that you see onscreen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: "Select System info from the Administration panel."

Warnings or important notes appear like this.
Tips and tricks appear like this.

Get in touch

Feedback from our readers is always welcome.

General feedback: Email feedback@packtpub.com and mention the book title in the subject of your message. If you have questions about any aspect of this book, please email us at questions@packtpub.com.

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.

Piracy: If you come across any illegal copies of our works in any form on the Internet, we would be grateful if you would provide us with the location address or website name. Please contact us at copyright@packtpub.com with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Reviews

Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!

For more information about Packt, please visit packtpub.com.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
C# 7 and .NET Core 2.0 High Performance
Published in: Apr 2018Publisher: ISBN-13: 9781788470049
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Ovais Mehboob Ahmed Khan

Ovais Mehboob Ahmed Khan is a seasoned programmer and solution architect with nearly 20 years of experience in software development, consultancy, and solution architecture. He has worked with various clients across the world and is currently working as a senior customer engineer at Microsoft. He specializes mainly in application development using .NET and OSS technologies, Microsoft Azure, and DevOps. He is a prolific writer who has written several books and articles on various technologies. He really enjoys talking about technology and has given a number of technical sessions around the world.
Read more about Ovais Mehboob Ahmed Khan