liveBook · Manning

Separation of concerns

As explained in ASP.NET Core in Action, 3e

Separation of concerns is a design principle that isolates distinct aspects of an application so each can change with minimal impact on the others.

Separation of concerns isolates distinct application responsibilities so each part can change and be tested with minimal impact on the others. In an MVC-style application, this reduces coupling between business logic, request handling, and presentation. section 13.4.4 section 16.1

Assign each responsibility to a clearly defined component:

  • The view takes data and generates HTML. section 13.4.4
  • The application model executes business logic and updates application state. section 13.4.4 section 16.1
  • The controller or page handler validates the request and selects the response. section 13.4.4
  • Services should perform request-related business operations instead of page handlers changing data directly. section 13.5

Filtering a to-do list

A request for todo/listcategory/{category}/{username} is routed to a Razor Page handler. The handler validates the incoming values and delegates business work to a service or application model. The view then renders the returned to-do items as HTML. Changing the display does not require changing the filtering logic, while changing the business rules does not require rewriting the view. section 16.1 section 13.4.4

Figure 13.12 A complete Razor Pages request for the list of to-dos in the Simple category
CH13_F12_Lock3

Trace how routing, the page handler, application model, and view combine to produce a complete Razor Pages response. section 13.4.4

How ASP.NET Core in Action, 3e covers it

How deep it goes
Explains component responsibilities, coupling risks, and service delegation through a complete request, but does not detail implementation code.
Examples
Uses a filtered to-do list and a complete Razor Pages request from URL routing through HTML response.
What you can do after
Apply it via ASP.NET Core Razor Pages by assigning validation, business logic, and presentation to separate components.
How it connects
Connects MVC, single-responsibility principle, routing, model binding, validation, services, and tight coupling.

Also explained in

Compare how 22 books explain separation of concerns →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of ASP.NET Core in Action, 3e. The section links point to the parts of the book it draws on.