Skip to content

Details

LeedsSharp are proud to present Andrew Poole in "Fluent method chaining in C# and orchestration code so clear your product owner can read it!"

Please note this event is a week earlier than its usual date.

Abstract:

What if there was a way to declaratively describe a chain or flow of methods, especially async methods, which could be used when handling API requests or messages from a queue or anywhere actually? What if that flow of methods was self-documenting and understandable at a glance?

Recently, while refactoring a growing piece of business logic, my team and I found a way to achieve this. My talk tells the story of that refactoring journey. It is a mixture of slides and live coding demos in Visual Studio, where I show that the flows of chained methods are easy to read, navigate, debug and test. We end up with orchestration code which describes a whole system or vertical slice and, with some care, is even readable by product owners and business analysts!
I start by describing the problem and some background, including the use of discriminated unions in C# (using OneOf) and I set out the aims we had for the refactoring effort.
Next, I demonstrate the solution we came up with and how easy it is to use. Then I do a deep dive into the extension methods which enable the method chaining.
Next, I introduce the concept of orchestration by co-locating related flows together in a single class.
I go back to the demo, show some orchestration code, and add more chained methods, showing a few more features.
I complete the demo by introducing an end-to-end component test and stepping through it in the debugger, while it tests the entire orchestration flow.
I discuss that while our solution is event sourced, it is flow driven. Then I finish with some limitations and conclusions.

Events in Leeds, LS1 4JB, GB
C#
Functional Programming
.NET
Computer Programming

Sponsors

Sponsor logo
FruitionIT
FruitionIT give us support, advice and pay for the Pizza and Beer
Sponsor logo
tronik ecommerce consultants
Help organising meetups.
Sponsor logo
JetBrains
2 free annual Personal subscriptions for the winner of our xmas quiz.

Members are also interested in