Dagger2 Scope
# @Scope
@Scope //스코프임을 알린다.
@Retention(value = AnnotationRetention.RUNTIME) //이 주석은 런타임동안 유지된다.
annotation class ActivityScope
When a type is marked with a scope annotation, it can only be used by components that are annotated with the same scope.
@Scope라고 붙인 타입은 같은 스코프를 가진 컴포넌트에서만 사용될 수 있다.
When a component is marked with a scope annotation, it can only provide types with that annotation or types that have no annotation.
@Scope라고 붙인 컴포넌트는 같은 스코프를 가진 타입이나 아예 스코프 지정을 안한 타입만을 제공할 수 있다.
A subcomponent cannot use a scope annotation used by one of its parent components.
자식 컴포넌트는 부모컴포넌트에서 쓰인 스코프를 쓸 수 없다.
// Classes annotated with @ActivityScope are scoped to the graph and the same
// instance of that type is provided every time the type is requested
@ActivityScope
@Subcomponent
interface LoginComponent { ... }
// A unique instance of LoginViewModel is provided in Components
// annotated with @ActivityScope
@ActivityScope
class LoginViewModel @Inject constructor(
private val userRepository: UserRepository
) { ... }