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

A Homage To Good Old MVC - JetBrains .NET Days ...

Alexander Zeitler
September 25, 2024
51

A Homage To Good Old MVC - JetBrains .NET Days 2024

Alexander Zeitler

September 25, 2024
Tweet

Transcript

  1. Bootstrapping / Indiehacking is on the rise An idea, implemented

    by a single developer No VC money Make or buy Simplicity
  2. Rediscovering ASP.NET Core MVC Batteries included • Rich .NET Base

    Class Library (BCL) • Razor View Engine (Layouts, Partials, HTML Helpers, Conditions etc.) • Identity (Cookie, OIDC, SSO and more) • Localization / Globalization Other platforms mimic ASP.NET • Bun • Next.js
  3. Poll: what’s your web application stack? ASP.NET Core MVC /

    Razor Pages Blazor SPA (Angular, React, Vue) Something else Photo by Jens Lelie on Unsplash
  4. MVC - what we have been taught Model View Controller

    Updates Sends user input Manipulates
  5. MVC - What we have made of it Photo by

    Susan Q Yin on Unsplash
  6. Coupling In software engineering, coupling is the degree of interdependence

    between software modules; a measure of how closely connected two routines or modules are; the strength of the relationships between modules. Coupling is not binary but it is multi-dimensional. Coupling on Wikipedia
  7. We made it SOLID Single Responsibility Open/Closed Liskov Substitution Interface

    Segregation Dependency Inversion Photo by Pawel Czerwinski on Unsplash
  8. Cohesion In computer programming, cohesion refers to the degree to

    which the elements inside a module belong together. In one sense, it is a measure of the strength of relationship between the methods and data of a class and some unifying purpose or concept served by that class. In another sense, it is a measure of the strength of relationship between the class's methods and data.
  9. The forces: Coupling vs. Cohesion Loose Coupling, high Cohesion Good

    High Coupling, low Cohesion Bad Cohesion on Wikipedia
  10. Locality of Behavior The behaviour of a unit of code

    should be as obvious as possible by looking only at that unit of code. The primary feature for easy maintenance is locality: Locality is that characteristic of source code that enables a programmer to understand that source by looking at only a small portion of it. – Richard P. Gabriel, Patterns of Software
  11. A different Model Smaller More concise Different models for different

    contexts Multiple models for different features No “property creep” across the solution
  12. Multiple models using Event Sourcing (Commands) Small, concise Events (what

    happened?) Stream per Aggregate Multiple projections (read models = state based on Events) per stream
  13. Event Sourcing in .NET: MartenDB Event Store on top of

    Postgres Strong Consistency if required Versions Projections Concurrency Multi-Tenancy models Not everything has to be event sourced: Use the Marten Document Store MartenDB
  14. HTMX Like jQuery but every HTML element can trigger every

    type of HTTP Request HTMX support for Controllers / Request / Response: dotnet add package Htmx HTMX for Razor Views: dotnet add package Htmx.TagHelpers
  15. Wolverine Command Execution Asynchronous Processing Messaging In Memory Message Bus

    Message Brokers RabbitMQ AWS SQS Azure Service Bus Marten Integration Wolverine
  16. Navigating the code - Cognitive load ProductController inside Controllers namespace

    with an Add method when you have many Controllers with Add methods Add View inside Views/Product folder with many Add Views under the Views folder ProductModel inside Models folder which is used across different methods/actions AddNewProductController inside the Feature folder AddNewProduct with a method/action AddNewProduct AddNewProduct View inside the Feature folder AddNewProduct AddNewProduct Model inside Feature folder AddNewProduct for the AddNewProduct method/action Product Model for the actual product read model/view
  17. UI is the place for coupling Composition of the individual

    Contexts ViewModel Composition View Composition
  18. Tag Helpers Build your own reusable and shareable Components Can

    be tested Can be nested Can have Razor View Content Can be navigated (go to definition / find usages)
  19. Different Response Types in ASP.NET Core MVC [Consumes] Attribute [Produces]

    Attribute Check the Accept header Application State vs. Resource State Your API is a UI HTML is one representation