Description
Course info
Rating
(38)
Level
Intermediate
Updated
Mar 29, 2017
Duration
1h 9m
Description

At the core of developing correct and maintainable Azure Functions is a thorough knowledge of how to reduce code duplication. In this course, Reducing C# Code Duplication in Azure Functions, you'll learn how to create functions and Function Apps that reduce or eliminate duplicated code. First, you'll discover how to share source code within a Function App. Next, you'll explore how to share compiled code. Finally, you'll learn how to re-factor business logic code into a shared function. When you’re finished with this course, you'll have a foundational knowledge of reducing code duplication that will help you as you move forward to create more maintainable and less error-prone functions.

About the author
About the author

With over 15 years experience, Jason Roberts is a Microsoft .NET MVP, freelance developer, and author.

More from the author
Working with Files and Streams in C#
Intermediate
3h 13m
12 Oct 2018
Error Handling in C# with Exceptions
Intermediate
1h 37m
6 Aug 2018
More courses by Jason Roberts
Section Introduction Transcripts
Section Introduction Transcripts

Course Overview
Hi everyone, my name's Jason Roberts. Welcome to my course, Reducing C# Code Duplication in Azure Functions. I'm a Microsoft. NET MVP, freelance developer, and author. In this course, we're going to learn how to make maintaining our Azure functions easier and reduce potential errors by reducing or eliminating duplicated code. Some of the major topics that we'll cover in this course include how to reduce duplicated code within a single function app by sharing source code, how to share compiled code within a function app and across multiple function apps, and how to refactor out shared logic into dedicated functions. By the end of this course, you'll understand how to share source code, share compiled code, and create centralized logic in shared functions to reduce duplicated code. Before beginning the course, you should be familiar writing basic C# code and have a basic understanding of Azure functions. I hope you'll join me on this journey with the Reducing C# Code Duplication in Azure Functions course, at Pluralsight.

Sharing Compiled Code
Hi, welcome back. In the previous module we learned how to reduce code duplication by sharing source code amongst functions. In this module we're going to learn how we can reduce code duplication by instead of sharing source code, sharing compiled code. So in this module, we're going to start off by looking at some of the limitations of source code sharing, and then we're going to look at a number of different ways we can share compiled code. So we'll start off by learning about the pre-supplied assemblies in the functions at runtime, and then we'll learn how we can reference compiled code from NuGet packages, whether this be the official NuGet feed or an alternative or potentially private feed, such as MyGet. We'll then jump over to Visual Studio and we'll take the code from the previous module and instead of sharing it as source, we'll compile it into an assembly. Now that we've got our compiled DLL, we'll head back to the portal and we'll see how we can use this compiled assembly in a single function. If we want this same DLL to be available to all functions in the function app, we'll see how we can do this, and then we'll go and learn how we can update a shared compiled assembly in our function app. Finally, we'll see that because we've now got compiled code, we can actually share this code amongst multiple function apps, something that we can't do with source code sharing. So let's kick off this module by looking at some of the limitations of sharing source code.

Refactoring Code to a Shared Function
Hi. Welcome back to this final module. In the previous module we learned how we can share code in a compiled fashion between functions, and also across multiple function apps and other potential. NET applications. In this module we're going to be fully embracing the idea of functions as a service, and we're going to go and refactor the validation code into a shared Azure function. So in this module, we're going to go and create a new function, and we're going to move the loan application validation logic into this new HTTP function. So just as the example was in the previous modules, we're going to just stick with validating the age, but you can imagine more complex validation happening here. Now we've got our new validation function, we'll start off by refactoring the HTTP function, and rather than using the validation code in the shared assembly, we'll instead use the validation code from our new HTTP function. We'll then go and follow the same approach for our queue function, once again we'll remove the reliance on the validation code from the compiled assembly and use the validation logic in the new function. Now we have all of our validation logic in a single function, we'll go and make a business change. So we'll go and change the age to 25, and because we have this logic in the shared function now, we'll see that we don't have to go an upload any new assembly versions. So let's jump over to the portal and we'll go and create our new validation function.