DoclerLabs / hexMachina

Releases, issues, documentation, website of hexMachina, framework written in Haxe
http://hexmachina.org
MIT License
44 stars 8 forks source link

DSL API change : "factory" attribute renamed to "factory-method" and limited to instance method call. #187

Closed aliokan closed 7 years ago

aliokan commented 7 years ago

In same way than singleton-access is renamed static-call (#186), factory should be renamed factory-method. And to be limited to method call on instance.

<root name="applicationContext">
    <point id="point" type="hex.ioc.parser.xml.mock.MockPointFactory" static-call="getInstance" factory-method="getPoint">
        <argument type="Int" value="10"/>
        <argument type="Int" value="20"/>
    </point>
</root>
class MockPointFactory
{
    public function getPoint( x : Int, y : Int ) : Point
    {
        return new Point( x, y );
    }

    static var _Instance : MockPointFactory = null;

    static public function getInstance() : MockPointFactory
    {
        if ( MockPointFactory._Instance == null )
        {
            MockPointFactory._Instance = new MockPointFactory();
        }

        return MockPointFactory._Instance;
    }
}

Another example:

<root name="applicationContext">
    <div id="div" type="hex.ioc.parser.xml.mock.MockBrowser" static-ref="document" factory-method="querySelector">
        <argument value="#test"/>
    </div>
</root>
class MockBrowser
{
    public static var document( default, never ) : MockDocument = new MockDocument();
}