Speaker, blogger, developer, Microsoft MVP for C# and all-around technology enthusiast. He spends most of the time at the keyboard typing yet another demo or application. If you take his keyboard away from him, he will give a session at regional conferences. Strong proponent of Open Source and all things chocolate. Loves mobile and game development, web and cloud services. Too little time for too many things.
Functional C# in Web API
- Stopnja 300
-
Datum
sreda
17. maj 2017 15:45
As a multi-paradigm language, one can write pretty much any kind of code in C#. Somehow that always meant writing object oriented code, but C# is quite functional. Web apps are typically written with DDD (domain driven design) or some other N-tier architecture in mind. This means a lot of interfaces, a lot of objects and a lot of DI. But we can do better. Before falling head first in F# with no escape hatch behind us, let's first consider the functional aspect of C#. Instead of interfaces, we will use delegates, instead of DI we will write all our dependencies in our static functions. By removing the burden of OO from our layers our code will become simpler, clearer and finally more testable. It is much easier to unit test your code when there are no stubs or mocks and when we can use simple values to pass to our functions.