objects should have their dependencies provided to them, not create them on their own. Good: class RepoRepository(private val service: RepoService) Bad: class RepoRepository() { private val service = RepoService() }
library that assists the developer with providing dependencies to core application objects class RepoRepository @Inject constructor(private val service: RepoService)
= instance; if (result == UNINITIALIZED) { synchronized (this) { result = instance; if (result == UNINITIALIZED) { result = provider.get(); /* */ instance = result; /* Null out the reference to the provider. We are never going to need it again, so we * can make it eligible for GC. */ provider = null; } } } return (T) result; }