Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
mobile ruleP2stack specificStack: Kotlin
dependency-injectionkotlinkoin
Register repositories as singletons in the DI container
Bind repositories (and other stateless, shared-resource services) as singletons rather than factory/new-per-injection. They wrap a shared data source and hold no per-caller state, so a new instance per injection wastes allocations and can duplicate caches/connections.
PR: profico-org-corpus batch2 (all stacks/products)Created: Jul 26, 2026
Bad example
Old codekotlin
| 1 | factory { AuthRepositoryImpl(get()) } // new repo on every inject |
Explanation (EN)
A repository is recreated on each injection though it's stateless and shared.
Objašnjenje (HR)
Good example
New codekotlin
| 1 | single { AuthRepositoryImpl(get()) } // one shared repository |
Explanation (EN)
A singleton binding shares one repository instance across the app.
Objašnjenje (HR)