【问题标题】:Koin scope with multiple declarations?具有多个声明的 Koin 范围?
【发布时间】:2019-02-12 12:30:25
【问题描述】:

根据这篇文章https://insert-koin.io/docs/1.0/getting-started/android-scope/,我们可以为我们的对象创建范围。这是那里给出的一个例子。

scope("session") { MyScopePresenter(get())}

我的问题是我们是否允许在每个范围内放入多个定义?我觉得我们不是。任何地方都没有这样的例子。

    scope("session") {  
       Something() 
     AnotherThing()}

这行不通。我只能注入 AnotherThing() 而没有注入某些东西。

为什么 Koin 只允许每个范围有一个定义?

【问题讨论】:

    标签: android kotlin koin


    【解决方案1】:

    当您使用singlefactoryscope 定义将声明添加到module { ... } 时,它们会在内部创建所谓的BeanDefinition 对象。这个 bean 定义对象将提供声明对象的实例。每个BeanDefinition 对象将处理一个声明。这意味着你应该改变

    scope("session") {  
       Something() 
       AnotherThing()
    }
    

    进入

    scope("session") { Something() }
    scope("session") { AnotherThing() }
    

    为了让它工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-07-18
      • 1970-01-01
      • 2015-10-03
      • 2020-09-07
      • 1970-01-01
      • 2020-01-24
      • 1970-01-01
      相关资源
      最近更新 更多