Java Dagger2:从singleton组件返回not singleton对象
如何从Java Dagger2:从singleton组件返回not singleton对象,java,android,kotlin,dependency-injection,dagger-2,Java,Android,Kotlin,Dependency Injection,Dagger 2,如何从@singleton组件返回非单例对象 例如,我有: ApplicationComponent.kt @Singleton @Component(modules = [ApplicationModule::class]) interface ApplicationComponent() { fun database(): Database fun model(): Model } class Model @Inject constructor() Model.kt @S
@singleton
组件返回非单例对象
例如,我有:
ApplicationComponent.kt
@Singleton
@Component(modules = [ApplicationModule::class])
interface ApplicationComponent() {
fun database(): Database
fun model(): Model
}
class Model @Inject constructor()
Model.kt
@Singleton
@Component(modules = [ApplicationModule::class])
interface ApplicationComponent() {
fun database(): Database
fun model(): Model
}
class Model @Inject constructor()
我想要的是每次都返回一个不同的
模型
实例,与数据库
相反,它将是一个单例,由ApplicationModule.kt提供,如果您提供模型
@Singleton
@Component(modules = [ApplicationModule::class])
interface ApplicationComponent() {
fun database(): Database
fun model(): Model
}
class Model @Inject constructor()
@Singleton
class Model @Inject constructor()
或作为
这将是一个单身汉
如果您没有使用@Singleton
、@reusible
或任何其他作用域对任何提供程序进行注释,您将始终创建一个新实例