Skip to content

Instantly share code, notes, and snippets.

@jeffijoe
Created September 6, 2016 09:55
Show Gist options
  • Save jeffijoe/d9a4ea3a45ffda376ad978c94eb8c401 to your computer and use it in GitHub Desktop.
Save jeffijoe/d9a4ea3a45ffda376ad978c94eb8c401 to your computer and use it in GitHub Desktop.
Snippet for my Medium article
import { createContainer, asClass, asFunction } from 'awilix'
import makeTodosService from './todosService'
import TodosRepository from './todosRepository'
export default function configureContainer () {
const container = createContainer()
// Ordering does not matter.
container.register({
// Notice the scoped() at the end - this signals
// Awilix that we are gonna want a new instance per "scope"
todosService: asFunction(makeTodosService).scoped(),
// We only want a single instance of this
// for the apps lifetime (it does not deal with user context),
// so we can reuse it!
todosRepository: asClass(TodosRepository).singleton()
})
return container
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment