Slide 1

Slide 1 text

SINTRA DIGITAL BUSINESS Learning ASP.NET Core Best Practices With An Opensource Project 1

Slide 2

Slide 2 text

SINTRA DIGITAL BUSINESS 2 HELLO EVERYONE Until Covid-19 do us apart!

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

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]

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

SINTRA DIGITAL BUSINESS 6 FROM OPENSOURCE TO OPEN MIND

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

SINTRA DIGITAL BUSINESS I've never stopped. 9 AND THEN... I've never stopped

Slide 10

Slide 10 text

SINTRA DIGITAL BUSINESS 10 THE GYM

Slide 11

Slide 11 text

SINTRA DIGITAL BUSINESS DEMO http://rawcms-demo.herokuapp.com/ PROJECT PAGE https://github.com/arduosoft/RawCMS RAWCMS 11 11

Slide 12

Slide 12 text

SINTRA DIGITAL BUSINESS 12 BEST PRACTICES

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

SINTRA DIGITAL BUSINESS PLUGINS Extend you application adding a deployable artifact. 14

Slide 15

Slide 15 text

SINTRA DIGITAL BUSINESS 15 WHAT WE NEED

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

SINTRA DIGITAL BUSINESS 17 THE BASICS

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

SINTRA DIGITAL BUSINESS 20 IN SIMPLE WORDS Make things happen without writing code.

Slide 21

Slide 21 text

SINTRA DIGITAL BUSINESS 21 THE LOGGING EXAMPLE BEFORE AOP AFTER AOP

Slide 22

Slide 22 text

SINTRA DIGITAL BUSINESS 22 THE DATA EXAMPLE BEFORE AOP AFTER AOP

Slide 23

Slide 23 text

SINTRA DIGITAL BUSINESS 23 HOW IT IS POSSIBLE ProxyDispatcher

Slide 24

Slide 24 text

SINTRA DIGITAL BUSINESS 24 IN 34 LINES OF CODE FULL EXAMPLE ON https://github.com/zeppaman/csharp-aop

Slide 25

Slide 25 text

SINTRA DIGITAL BUSINESS 25 I CAN'T BELIEVE IT 1 MINUTE DEMO

Slide 26

Slide 26 text

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.

Slide 27

Slide 27 text

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

Slide 28

Slide 28 text

SINTRA DIGITAL BUSINESS BACKGROUND JOBS 28 Web can’t wait for you

Slide 29

Slide 29 text

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!

Slide 30

Slide 30 text

SINTRA DIGITAL BUSINESS 30 WHY PUT IT INSIDE A WEB APPLICATION?

Slide 31

Slide 31 text

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

Slide 32

Slide 32 text

SINTRA DIGITAL BUSINESS HANGFIRE 32 •Persistency •Balancing on multiple server •Dashboard •Authentication •Possibility to run processes manually What else?

Slide 33

Slide 33 text

SINTRA DIGITAL BUSINESS 33 I CAN’T BELIEVE IT 1 MINUTE DEMO

Slide 34

Slide 34 text

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

Slide 35

Slide 35 text

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

Slide 36

Slide 36 text

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

Slide 37

Slide 37 text

SINTRA DIGITAL BUSINESS 37 SCENARIOS WITH IDS START EASY AND EVOLVE LATER

Slide 38

Slide 38 text

SINTRA DIGITAL BUSINESS 38 SCENARIOS FEDERATION STANDALONE

Slide 39

Slide 39 text

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

Slide 40

Slide 40 text

SINTRA DIGITAL BUSINESS MULTIPLE DATABASE Keeping same data in multiple places 40

Slide 41

Slide 41 text

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.

Slide 42

Slide 42 text

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

Slide 43

Slide 43 text

SINTRA DIGITAL BUSINESS 43 IN CODE WORDS

Slide 44

Slide 44 text

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

Slide 45

Slide 45 text

SINTRA DIGITAL BUSINESS MULTITENCANCY One application, multiple customers 45

Slide 46

Slide 46 text

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

Slide 47

Slide 47 text

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

Slide 48

Slide 48 text

SINTRA DIGITAL BUSINESS 48 HOW TO IMPLEMENT IT Dependency Injection is your friend

Slide 49

Slide 49 text

SINTRA DIGITAL BUSINESS 49 IN CODE WORDS CONFIGURATION USAGE

Slide 50

Slide 50 text

SINTRA DIGITAL BUSINESS 50 OR DO NOT REINVENT THE WHEEL AUTOFAC TENANT NAME DETECTION POLICY MANAGE PER TENANT DIFFERENCES

Slide 51

Slide 51 text

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

Slide 52

Slide 52 text

SINTRA DIGITAL BUSINESS MICROSERVICES Divide et impera 52

Slide 53

Slide 53 text

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?

Slide 54

Slide 54 text

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

Slide 55

Slide 55 text

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!

Slide 56

Slide 56 text

SINTRA DIGITAL BUSINESS 56 WHAT TO TAKE HOME

Slide 57

Slide 57 text

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

Slide 58

Slide 58 text

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

Slide 59

Slide 59 text

SINTRA DIGITAL BUSINESS 59 THANK YOU