Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

set _instance for Singleton Beans in the constructor. #700

Description

@mwinters-stuff

I found a problem, the following is my attempt to example what I came across, this problem occured because _instance is set after the constructor e.t.c. of the bean has executed.
(this code probably wont compile as i am typeing it from my head)..

@EBean(scope="singleton")
class DatabaseHelper
{
}

@EBean(scope="singleton")
class Worker1
{
  @Bean
  DatabaseHelper database;
}

@EBean(scope="singleton")
class Worker2
{
  @Bean
  DatabaseHelper database;
  @Bean
  Worker1 worker1;
}

@Bean(activity/fragment/whatever)
class someotherclass
{
  @Bean
  Worker2 worker2;
}

In this case, worker2 creates a database helper and worker1
worker1 will also create a new databasehelper..

If _instance was set in the constructor to "this", then we would only get one instance of databasehelper.

I had a go at making the changes myself, but after making the change, i couldnt compile the source through some error unleated to where i had made changes.

Activity

  1. DayS commented on Sep 1, 2013

    @DayS
    Contributor

    This is related to a known one about cyclic dependencies with singleton scope. However, I can't find the related issue...

    To resolve this bug, the only way is to manually set dependencies in some bean. In this example : you should add the following code in Worker2 :

    @AfterInject
    void init() {
         worker1.setDatabaseHelper(database)
    }

    However, we should fix this. But it may be on AA 3.1, as we have to focus on AA 3.0 release :)

  2. WonderCsabo commented on Jan 13, 2014

    @WonderCsabo
    Member

    This is fixed in #792, or just related?

  3. DayS commented on Jan 13, 2014

    @DayS
    Contributor

    Nop, This issue has been fixed in 3.0 via #792

  4. removed this from the 3.1 milestone on Sep 7, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions