Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Learning ASP.NET Core Best Practices With An Opensource Project

Learning ASP.NET Core Best Practices With An Opensource Project

RawCms is an open source headless CMS in asp.net. Complete this project was a challenge due to the hard requirements. During the speech, I will introduce the architecture and the issues we found, explain how to solve them and how to use such knowledge in projects every day. By the technical part, what is behind this project is the best setup for all asp.net core projects keeping in mind modern requirements. Keeping the RawCms experience in the background, during the speech will be presented a best-practice architecture, covering:

- Authentication (Oauth2 with a build-in server or federated via introspection)
- Interaction between SQL and NO SQL database
- Plugin system in C#
- Hooking system
- AOP and code automation

Daniele Fontani

March 10, 2020
Tweet

More Decks by Daniele Fontani

Other Decks in Programming

Transcript

  1. SINTRA DIGITAL BUSINESS MYSELF IN THREE PICTURES A picture is

    worth a thousand words There is a world outside the internet! TREKKING The better sandbox for learning! OPENSOURCE The place where I do my best WORK 3
  2. SINTRA DIGITAL BUSINESS MYSELF IN SOCIAL NETWORKS Building better tomorrow.

    Trekker inside. CTO interested in #CloudComputing, #AgileDevelopment and #Opensource 4 https://www.linkedin.com/in/daniele-fontani/ https://medium.com/@daniele.fontani https://twitter.com/zeppaman https://github.com/zeppaman [email protected]
  3. SINTRA DIGITAL BUSINESS Why opensource is the best env for

    developing new skills From opensource to open mind All the bricks needed for an enterprise asp.net application Best practices What was my test case The gym 5 AGENDA
  4. SINTRA DIGITAL BUSINESS You give you software for free, without

    patents Unsuccessful business model It’s just a loose of time Opensource is for losers Opensource? is simply Linux Ignorance 7 IN 2006
  5. SINTRA DIGITAL BUSINESS Learn new things, compare yourself with others

    CHALLENGING I give to the community for what I take ETHICAL Give me a lot, not money, but friends and knowledge REWARDING 8 THEN MY FIRST EXPERIENCE
  6. SINTRA DIGITAL BUSINESS Divide et impera MICROSERVICES One app, many

    customer MULTITENANCY One login many app IDENTITY World is Async BACKGROUND JOBS Get best from all MULTIPLE DATABASES Make things happens by design AOP BEST PRACTICES ROADMAP 13 For extension PLUGINs
  7. SINTRA DIGITAL BUSINESS 16 WHY PLUGIN IN THE MICROSERVICES ERA?

    There are some cases when microservices are hard to implement: • Old codebase • Background jobs • Completely coupled business logic • Very small application domains • On-Prem Products WE ARE HERE
  8. SINTRA DIGITAL BUSINESS Divide et impera MICROSERVICES One app, many

    customer MULTITENANCY One login many app IDENTITY World is Async BACKGROUND JOBS Get best from all MULTIPLE DATABASES Make things happens by design AOP BEST PRACTICES ROADMAP 18 For extension PLUGINs
  9. SINTRA DIGITAL BUSINESS AOP In computing, aspect-oriented programming (AOP) is

    a programming paradigm that aims to increase modularity by allowing the separation of cross-cutting concerns. It does so by adding additional behavior to existing code (an advice) without modifying the code itself […] This allows behaviors that are not central to the business logic (such as logging) to be added to a program without cluttering the code, core to the functionality. https://en.wikipedia.org/wiki/Aspect-oriented_programming 19
  10. SINTRA DIGITAL BUSINESS 24 IN 34 LINES OF CODE FULL

    EXAMPLE ON https://github.com/zeppaman/csharp-aop
  11. SINTRA DIGITAL BUSINESS 26 MY THOUGHT ABOUT AOP IN C#

    • Its' ok for logging and measuring (but with a good control on what is logged or not). Pay attention to the C# limit: only virtual method or interface implementation can be intercepted. • For the other application you cannot do yourself. You need a framework like Spring in Java, but we are on the other side.
  12. SINTRA DIGITAL BUSINESS Divide et impera MICROSERVICES One app, many

    customer MULTITENANCY One login many app IDENTITY World is Async BACKGROUND JOBS Get best from all MULTIPLE DATABASES Make things happens by design AOP BEST PRACTICES ROADMAP 27 For extension PLUGINs
  13. SINTRA DIGITAL BUSINESS 29 SYNC IS DEAD LONG LIVE TO

    ASYNC! In 2020 most scenario need to be async, we have to live with it. This means every web application is also a background worker. Note:We may have a microservice application where you invoke by api the job on other server(container), but the application that host background job... is still a web application because have to be invoked by API!
  14. SINTRA DIGITAL BUSINESS THE CHOICE Native, but just a process

    runner Based on service definition Native solution A complete scheduling solution Based on fluent code Hangfire 31
  15. SINTRA DIGITAL BUSINESS HANGFIRE 32 •Persistency •Balancing on multiple server

    •Dashboard •Authentication •Possibility to run processes manually What else?
  16. SINTRA DIGITAL BUSINESS Divide et impera MICROSERVICES One app, many

    customer MULTITENANCY One login many app IDENTITY World is Async BACKGROUND JOBS Get best from all MULTIPLE DATABASES Make things happens by design AOP BEST PRACTICES ROADMAP 34 For extension PLUGINs
  17. SINTRA DIGITAL BUSINESS IDENTITY Cyclops, you asked about my famous

    name. I’ll tell you. Then you can offer me a gift, as your guest. My name is Nobody. My father and mother, all my other friends— they call me Nobody. Odysseus and Polyphemus - Odyssey 35
  18. SINTRA DIGITAL BUSINESS 36 WHAT IS NOT ACCEPTABLE ON 2020

    • INSERT YOUR PASSWORD TWICE • HAVE DIFFERENT ACCOUNT FOR DIFFERENT APPLICATION • USE SERVICE ACCOUNTS THAT OPERATES ON BEHALF OF YOU • IMPLEMENT IT BY YOURSELF
  19. SINTRA DIGITAL BUSINESS Divide et impera MICROSERVICES One app, many

    customer MULTITENANCY One login many app IDENTITY World is Async BACKGROUND JOBS Get best from all MULTIPLE DATABASES Make things happens by design AOP BEST PRACTICES ROADMAP 39 For extension PLUGINs
  20. SINTRA DIGITAL BUSINESS 41 WHY • Pick the best from

    each tool • RDBMS may be not enough in 2020 If you are fighting against tanks, you don’t need a swiss army. You need the army.
  21. SINTRA DIGITAL BUSINESS 42 HOW You can use event listener

    on Hibernate, the OnSave method on Entity framework, or in case you are not using a orm.. Well, in thi case you need to rewrite the app and the full text search Is the last of your problems AUTOMATIC
  22. SINTRA DIGITAL BUSINESS Divide et impera MICROSERVICES One app, many

    customer MULTITENANCY One login many app IDENTITY World is Async BACKGROUND JOBS Get best from all MULTIPLE DATABASES Make things happens by design AOP BEST PRACTICES ROADMAP 44 For extension PLUGINs
  23. SINTRA DIGITAL BUSINESS 46 SCENARIOS Data isolation can be theoretically

    done at all levels (row, table, database, server) but only this make sense: • Put all data in the same table, but separate filtering basing on user (not GDPR compliant, not performant). • Use different database (with the options to have multiple servers) Options
  24. SINTRA DIGITAL BUSINESS 47 WHY THE HELL I NEED MULTI

    TENANCY? It is not really needed in B2B application, but it is a common scenario when: • You have multiple customer on same infrastructure (SaaS) • Your are designing a product • You may transform your custom application to a product or platform for many customer • You hold sensitive data and GDPR ask you for security
  25. SINTRA DIGITAL BUSINESS 50 OR DO NOT REINVENT THE WHEEL

    AUTOFAC TENANT NAME DETECTION POLICY MANAGE PER TENANT DIFFERENCES
  26. SINTRA DIGITAL BUSINESS Divide et impera MICROSERVICES One app, many

    customer MULTITENANCY One login many app IDENTITY World is Async BACKGROUND JOBS Get best from all MULTIPLE DATABASES Make things happens by design AOP BEST PRACTICES ROADMAP 51 For extension PLUGINs
  27. SINTRA DIGITAL BUSINESS 53 WHAT IS MICROSERVICES? The Chimera of

    Arezzo, Etruscan artwork. Now conserved in Florence. The Chimera Everybody try to implement microservices, but how micro they have to be is not said. A myth or reality?
  28. SINTRA DIGITAL BUSINESS 54 WHY MICROSERVICES ARE A CHIMERA? •

    The size of each microservices depends upon the business logic complexity and dependency. You microservice could be not so micro • Reusing of common part is not easy on a distributed system. If the common layer changes quickly you finish for having a monolithic system splitted into a lot of part Problems • A good analysis helps • Use containers, always. • Start with a good architecture (oauth2 with IDS, job server,...). Solutions
  29. SINTRA DIGITAL BUSINESS Divide et impera MICROSERVICES One app, many

    customer MULTITENANCY One login many app IDENTITY World is Async BACKGROUND JOBS Get best from all MULTIPLE DATABASES Make things happens by design AOP BEST PRACTICES ROADMAP 55 For extension PLUGINs ALL DONE!
  30. SINTRA DIGITAL BUSINESS 57 POINT OF INTEREST • Opensource is

    not for losers, but a real allied for become a better programmer. • Working on challenging projects make you a better programmer. • Lot of optional stuff are now included, don’t reinvent the wheel
  31. SINTRA DIGITAL BUSINESS 58 REFERENCES • SOURCE CODE https://github.com/zeppaman/aspnet-best-practices •

    RAWCMS https://github.com/arduosoft/RawCMS • AOP https://levelup.gitconnected.com/aop-dotnet-applications-67c6d94c08b0 • THIS PRESENTATION https://speakerdeck.com/zeppaman/learning-asp-dot-net-core-best-practices-w ith-an-opensource-project