Skip to content

Swiz teardown sets up prototype beans that have event handlers #36

@bclinkinbeard

Description

@bclinkinbeard

Migrated from SWIZ-66

When calling swiz.teardown(), prototype beans that have event handlers get constructed. Attached is a sample application to demonstrate the problem.

It's happening in EventHandlerProcessor.as on line 114. When trying to remove event handlers, it calls bean.source which has a getter with logic to setup the bean if it is not set up yet.

From @brian428

While I don't believe you should be calling teardown() directly, it does look like this would affect most of the processors. Possible fix in BeanFactory:

public function removeBean( bean:Bean ):void
{
    if( beans.indexOf( bean ) > -1 )
        beans.splice( beans.indexOf( bean ), 1 );

    if( !( bean is Prototype ) || Prototype( bean ).initialized )
        tearDownBean( bean );

    bean.beanFactory = null;
    bean.typeDescriptor = null;
    bean.source = null;
    bean = null;
}

Jeffrey Barrus added a comment - 14/Nov/11 4:54 PM
I found the problem because I am trying to do some integration testing and I really need to teardown everything between tests. I know the AutowiredTestCase uses a swiz instance as the event dispatcher rather than the top level application but I have created a FlexUnit Rule instead of using the AutowiredTestCase and I am using the top level application as the dispatcher. Is there a better way for me to tear down everything? When does swiz.teardown() get called normally?

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