longevity

A Persistence Framework for Scala and NoSQL

View project on GitHub

repo pools

The longevity context provides three different repo pools:

  • one that goes against your application database (context.repoPool)
  • one that goes against your test database (context.testRepoPool)
  • one that goes against an in-memory database (context.inMemTestRepoPool)

We can retrieve the repositories from the pool by type:

import longevity.persistence.Repo
val userRepo: Repo[User] = context.repoPool[User]

You should easily be able to inject these repositories into whatever dependency injection approach you are using. For instance, with Scaldi:

import longevity.persistence.Repo
import scaldi.Module

class PersistenceModule extends Module {
  bind[Repo[User]] to context.repoPool[User]
  bind[Repo[Blog]] to context.repoPool[Blog]
  bind[Repo[BlogPost]] to context.repoPool[BlogPost]
}

class TestPersistenceModule extends Module {
  bind[Repo[User]] to context.testRepoPool[User]
  bind[Repo[Blog]] to context.testRepoPool[Blog]
  bind[Repo[BlogPost]] to context.testRepoPool[BlogPost]
}

We’ll look at schema creation next, since that responsibility falls to the RepoPool.

prev: write timestamps
up: the longevity context
next: schema creation