Constructing Singletons

This example constructs a singleton (user) resource. Navigate to the resource from the root via the ‘me’ link relation.

singleton user

Goal

  • Return a user resource (logically on the root/home of the API-see virtual resources)
  • Practice the code layering of the solution and link relations from the previous tutorial
  • See the usage of a Repository Pattern (store) for retrieving a domain model

Note: while this tutorial creates the user singleton resource, the link to it from home is completed in the redirect page. The reason is that the home api must be highly cacheable and thus you don’t create user specific content (ie adding the user singleton would be an example of this) and thus we create virtual resources that are not cacheable to provide redirects. This tutorial picks up after the redirect.

Anatomy of code

Below, you see on overview of the code, then you see the implementation.

The code

Domain

Controller

Factories/Helpers

Unlock the next chapter
The primary role of the Domain Representation class (UserRepresentation) is
Allow for and make explicit the impedance mistmatch with persistence objects
Make it easy to write in the fluent style through the language construct of static extension methods
To allow for mappers and validators
All of the above