I looked at the IFactory instance in Flash - and all it has is one method - newInstance():* - which makes it really easy to make an IFactory that I can use to use with Prana:
Code:
package org.pranaframework.ioc.utils
{
import mx.core.IFactory;
import mx.logging.ILogger;
import mx.logging.Log;
import org.pranaframework.ioc.factory.IObjectFactory;
public class ContextRetrievalFactory implements IFactory
{
// the name of the object to retrieve from the config file
public var contextConfigName:String;
// the container object factory
public var objectFactory:IObjectFactory;
// the arguments that are used to retrieve the objet
public var constructorArguments:Array = null;
public function ContextRetrievalFactory(contextConfigName:String, objectFactory:IObjectFactory)
{
this.contextConfigName = contextConfigName;
this.objectFactory = objectFactory;
}
public function newInstance():*
{
return getObject(this.contextConfigName, this.objectFactory, this.constructorArguments);
}
// create an instance of the location delegate
protected static function getObject(s:String, container:IObjectFactory, constructorArguments:Array=null):* {
logger.debug("ContextRetrievalFactory retrieving object from the application context for configName:" + s);
return (container.getObject(s, constructorArguments));
}
/************************************************************/
/* DEPENDENCY INJECTION & LOGGING */
/************************************************************/
private static var _logger:ILogger;
private static function get logger():ILogger {
if (_logger == null)
_logger = Log.getLogger("org.pranaframework.ioc.utils.ContextRetrievalFactory");
return _logger;
}
}
}
I'm pretty sure I don't have credentials for the new SVN - so someone else will have to commit this - I might tweak it a bit as I use it.
Ryan