question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Scope is resurrected with its instances

See original GitHub issue

STR:

  1. Create a scope
  2. Declare an instance on that scope
  3. Close the scope
  4. Create a new scope the same way
  5. Declare an instance on that scope (same way as in step 2)

ER: Instance is successfully declared AR: Created scope already contains the instance

package com.test

import org.junit.Test
import org.koin.core.qualifier.named
import org.koin.dsl.koinApplication
import org.koin.dsl.module

class ScopeTest {

    val baseUrl = "base_url"
    val baseUrlKey = named("BASE_URL_KEY")

    val scopeId = "user_scope"
    val scopeKey = named("KEY")

    val koin = koinApplication {
        modules(
            module {
                scope(scopeKey) {
                }
            }
        )
    }.koin


    @Test
    fun `recreate a scope`() {
        val scope = koin.createScope(scopeId, scopeKey)
        scope.declare(baseUrl, baseUrlKey)
        scope.close()

        val scope2 = koin.createScope(scopeId, scopeKey)
        scope2.declare(baseUrl, baseUrlKey)
    }

}

org.koin.core.error.DefinitionOverrideException: Trying to override existing definition '[Single:'java.lang.String',qualifier:q:'BASE_URL_KEY',scope:q:'KEY']' with new definition typed 'class kotlin.String'

The issue was not observed on v2.0.1 but appeared after upgrading to 2.1.4

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
vitkhudenkocommented, Jul 9, 2020
koin_screenshot

Thanks to @StanislavChumarin for investigation.

1reaction
vitkhudenkocommented, Jul 21, 2020

Not sure we need to deep copy the ScopeDefinition itself. This ScopeDefinition brings the Scope with all related definitions, no runtime things here.

But need to investigate 👍

Maybe “deep copy” is not the accurate/right term here, but the idea is that a newly created scope should be only seeded with the compile time definitions (versus using the object directly as is). Scopes should not share among themselves the same seeded compile time definitions object, otherwise setting a new definition in runtime on a particular scope effectively sets it to all scopes (even future ones).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Have Mercy on Those Who Doubt | Desiring God
Suffice it to say, strange encounters with the resurrected Son of God and the scope of the mission he was giving them, colliding...
Read more >
Rule 611. Mode and Order of Examining Witnesses and ...
(b) Scope of Cross-Examination. Cross-examination should not go beyond the subject matter of the direct examination and matters affecting the witness's ...
Read more >
Object.Finalize Method (System) - Microsoft Learn
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
Read more >
Resurrection difference in using Object Initializer
Essentially i'm trying to demonstrate the use of the c# finalizer and make an object that cannot die, I called it Zombie. Now,...
Read more >
The Whole Creation Has Been Groaning - Baylor University
cosmic scope of God´s salvation in Jesus Christ. What ... perfected, so that it shares in the glory of the resurrected children of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found