Skip to content
This repository was archived by the owner on Jul 3, 2019. It is now read-only.

Map Singleton bug #48

@soundstep

Description

@soundstep

Hi,
I think I found a bug in a very specific case. The getInstance will create a new instance in a PostConstruct handler, even if it is mapped as singleton.

My problem was in a more complicated scenario of an command that is dispatched from a PostConstruct in ClassA, and this ClassA was injected in the command class for monitoring purpose, throwing an error.

I minimized the code the following 3 classes to show the bug:

import org.swiftsuspenders.Injector; import flash.display.Sprite; public class Main extends Sprite { public static var injector:Injector; public function Main() { injector = new Injector(); injector.mapSingleton(ClassA); injector.mapSingleton(ClassB); injector.getInstance(ClassA); } }
public class ClassA {
    [Inject]
    public var classB:ClassB;
    public function ClassA() {
        trace("Constructor", this);
    }
    [PostConstruct]
    public function initialize():void {
        trace("Initialize", this, ", classB instance:", classB);
        Main.injector.getInstance(ClassA); // should not create a new ClassA (will throw an error)
    }
}

public class ClassB {
    public function ClassB() {
        trace("Constructor", this);
    }
    [PostConstruct]
    public function initialize():void {
        trace("Initialize", this);
    }
}

The error looks like:

Constructor [object ClassA] Constructor [object ClassB] Initialize [object ClassB] Initialize [object ClassA] , classB instance: [object ClassB] Constructor [object ClassA] Initialize [object ClassA] , classB instance: [object ClassB] Constructor [object ClassA] Initialize [object ClassA] , classB instance: [object ClassB] Constructor [object ClassA] Initialize [object ClassA] , classB instance: [object ClassB]

Let me know what you think.

Romu

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions