liveBook · Manning

Plain old CLR object

As explained in Building Web APIs with ASP.NET Core

A plain old CLR object (POCO) is a normal .NET class without framework-specific inheritance or dependencies.

A plain old CLR object (POCO) is a normal .NET class that carries data without framework-specific inheritance, dependencies, attributes, infrastructure concerns, special types, or unrelated responsibilities. Its properties can be serialized into JSON, making it useful for representing data returned by a web API. section 2.4.4

A POCO supports a small API feature by:

  • Defining data as ordinary properties, such as Id, Name, and Year on a BoardGame class. section 2.4.5
  • Providing objects that a controller can return as a JSON array from an HTTP GET action. section 2.4.4 section 2.4.5
  • Keeping data representation separate from controller responsibilities and framework behavior. section 2.4.4
Listing 2.3 BoardGame.cs file
namespace MyBGList
{
   public class BoardGame
   {
       public int Id { get; set; }

       public string? Name { get; set; }

       public int? Year { get; set; }
   }
}

Inspect the compact BoardGame class, which uses ordinary properties to model sample board-game data. section 2.4.5

Replacing the template data object

Delete WeatherForecast.cs, add BoardGame.cs, and define a class with Id, Name, and Year properties. A BoardGamesController can then return three BoardGame objects at the /BoardGames route. The same sample output can be produced with Minimal API, but the controller remains useful when data retrieval and updates become more complex. section 2.4.5

How Building Web APIs with ASP.NET Core covers it

How deep it goes
Defines the class shape and serialization role, but stops short of database-backed behavior or complex domain responsibilities.
Examples
Uses WeatherForecast and BoardGame classes with Date, TemperatureC, Summary, Id, Name, and Year properties.
What it assumes
Assumes basic C# class and property knowledge while introducing framework-independent data modeling from a template example.
What you can do after
Build it from scratch as a simple C# data class and return its objects from a controller or Minimal API endpoint.
How it connects
Connects ordinary data classes with ASP.NET Core controllers, JSON serialization, Minimal API, and Entity Framework Core.

Also explained in

Compare how 2 books explain plain old CLR object →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building Web APIs with ASP.NET Core. The section links point to the parts of the book it draws on.