liveBook · Manning

Business logic

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

Business logic is the application behavior that implements domain rules, decisions, and processes independently of presentation or infrastructure concerns.

Business logic is the core application behavior that applies domain rules, makes decisions, and performs processes. In ASP.NET Core, framework code handles networking, handlers receive requests, and business logic performs the application work. It may use databases or remote APIs without depending directly on ASP.NET Core. section 1.1

Keep business logic separate from HTTP-facing handlers:

  • Place domain behavior in C# classes or services rather than Razor Pages or API controllers. section 1.1 section 36.2
  • Let handlers validate requests, call business logic services, and return or redirect to the appropriate result. section 36.2
  • Extract logic into services to improve testability and reuse, especially as an application grows beyond a tiny example. section 12.4

RecipeService

A recipe application can place its business logic in a RecipeService. The service queries recipes, creates new recipes, and modifies existing ones, while page handlers or API controllers coordinate the HTTP interaction. section 12.4 section 36.2

Figure 1.1 A typical ASP.NET Core application consists of several layers. The ASP.NET Core framework code handles requests from a client, dealing with the complex networking code. Then the framework calls in to handlers (Razor Pages and Web API controllers, for example) that you write using primitives provided by the framework. Finally, these handlers call in to your application’s domain logic—typically, C# classes and objects without any dependencies that are specific to ASP.NET Core.
CH01_F01_Lock3

Use the layered application diagram to trace a request from ASP.NET Core networking through handlers to framework-independent domain logic. section 1.1

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

How deep it goes
Defines separation and service responsibilities, then stops short of detailing domain internals or advanced architecture.
Examples
Uses RecipeService operations, MVC product and shopping-cart interactions, and currency-conversion controller tests.
What you can do after
Build it in services that handlers call, then unit-test the behavior separately from HTTP framework systems.
How it connects
Connects ASP.NET Core, handlers, Razor Pages, Web API controllers, databases, Entity Framework Core, and unit testing.

Also explained in

Compare how 10 books explain business logic →

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.