Skip to content

Introduces the new local attribute on Inject metadata tag. #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
type="String"
required="false"
description="Id of the named bean to inject" />

<attribute name="local"
type="Boolean"
hint="boolean"
defaultValue="false"
required="false"
description="Denotes whether or not Swiz should use the ( parent / child ) relation, to find the bean that will be injected." />

<attribute name="required"
type="Boolean"
Expand Down Expand Up @@ -138,4 +145,4 @@
<context name="setter" />
<context name="method" />
</metadata>
</annotations>
</annotations>
21 changes: 20 additions & 1 deletion src/org/swizframework/metadata/InjectMetadataTag.as
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ package org.swizframework.metadata
* Backing variable for read-only <code>required</code> property.
*/
protected var _required:Boolean = true;

/**
* Backing variable for read-only <code>local</code> property.
*/
protected var _local:Boolean = false;

// ========================================
// public properties
Expand Down Expand Up @@ -117,6 +122,17 @@ package org.swizframework.metadata
{
return _required;
}

/**
* Returns local attribute of [Inject] tag as a <code>Boolean</code> value.
* If true Swiz will discovery beans only in own instance avoiding parent child structure.
*
* @default false
*/
public function get local():Boolean
{
return _local;
}

// ========================================
// constructor
Expand Down Expand Up @@ -169,6 +185,9 @@ package org.swizframework.metadata

if( hasArg( "required" ) )
_required = getArg( "required" ).value == "true";

if( hasArg( "local" ) )
_local = getArg( "local" ).value == "true";
}
}
}
}
14 changes: 7 additions & 7 deletions src/org/swizframework/processors/InjectProcessor.as
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ package org.swizframework.processors
// source attribute found - means we're injecting by name and potentially by property

// try to obtain the bean by using the first part of the source attribute
var namedBean:Bean = getBeanByName( injectTag.source.split( "." )[ 0 ] );
var namedBean:Bean = getBeanByName( injectTag.source.split( "." )[ 0 ], !injectTag.local );

if( namedBean == null )
{
Expand Down Expand Up @@ -216,7 +216,7 @@ package org.swizframework.processors
*/
protected function removeInjectByProperty( injectTag:InjectMetadataTag, bean:Bean ):void
{
var namedBean:Bean = getBeanByName( injectTag.source.split( "." )[ 0 ] );
var namedBean:Bean = getBeanByName( injectTag.source.split( "." )[ 0 ], !injectTag.local );

removePropertyBinding( bean, namedBean, injectTag );

Expand All @@ -242,7 +242,7 @@ package org.swizframework.processors
{
targetType = swiz.domain.getDefinition( injectTag.host.name ) as Class;
}
var typedBean:Bean = getBeanByType( targetType );
var typedBean:Bean = getBeanByType( targetType, !injectTag.local );

if( typedBean )
{
Expand Down Expand Up @@ -322,17 +322,17 @@ package org.swizframework.processors
/**
* Get Bean By Name
*/
protected function getBeanByName( name:String ):Bean
protected function getBeanByName( name:String, discovery:Boolean = true ):Bean
{
return beanFactory.getBeanByName( name );
return beanFactory.getBeanByName( name, discovery );
}

/**
* Get Bean By Type
*/
protected function getBeanByType( type:Class ):Bean
protected function getBeanByType( type:Class, discovery:Boolean = true ):Bean
{
return beanFactory.getBeanByType( type );
return beanFactory.getBeanByType( type, discovery );
}

/**
Expand Down