Created
September 6, 2016 09:55
-
-
Save jeffijoe/d9a4ea3a45ffda376ad978c94eb8c401 to your computer and use it in GitHub Desktop.
Snippet for my Medium article
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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