In-Memory Repository – Layered Repository

Unit test is executed in less than half of the second. When we have an integration test which is using a repository that is connected to a database it will be executed in several seconds. With a repository, that has an implementation in-memory, tests will be executed faster. There are also other benefits.

  • In the in-memory repository we keep entities that application needs in one request or session. We don’t keep all entities.
  • We can implement the in-memory repository with maps. Basically for each entity we implement CRUD operations.
  • We can serialize an in-memory repository in a cache or a file.
  • We can create a layered repository, that is a repository that it uses for stating state a state from an another repository. When select calls are made, the layered repository calls the another repository and join results.
  • If we have serializable commands for create, update and delete entities, we can recreate the in-memory repository anytime. We can cache serializable commands and then create the in-memory repository.
  • We can export the in-memory repository to serializable commands for create, update and delete entities.
  • We can create any number of in-memory repositories. For example, each user has his own repository.
  • With layered repository we can track changes for entities in each layer.
  • There is no need for transactions. We can recreate the in-memory repository or implement copy operation, that create copy of the in-memory repository.
  • Test are executed faster than if we use a connection to an external database.


Leave a Reply