tschneidereit / SwiftSuspenders

NOTE: Find the offical repo at http://github.com/robotlegs/swiftsuspenders
https://github.com/robotlegs/swiftsuspenders
MIT License
280 stars 89 forks source link

Issue with constructor injection using config xml #13

Closed jomifo closed 14 years ago

jomifo commented 14 years ago

The following simple example yields, "Error: Injector is missing a rule to handle injection into target [class Class1]. Target dependency: Object, method: null, parameter: 1". Works fine with the metadata approach.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
    <mx:Script>
        <![CDATA[
            import org.swiftsuspenders.Injector;

            public function init():void
            {

                var diconfig:XML =
                <types>
                    <type name='Class1'>
                        <constructor>
                            <arg injectionname="exampleObjectParam" />
                        </constructor>
                    </type>
                </types>

                var injector:Injector = new Injector(diconfig);
                injector.mapValue(Object,{mode:'test'},'exampleObjectParam');
                var o:Class1 = injector.instantiate(Class1);
                trace(o.param1);
            }
        ]]>
    </mx:Script>
</mx:Application>

package
{
    import flash.events.IEventDispatcher;

    public class Class1 extends Object
    {
        public var param1:Object;

        public function Class1(p:Object)
        {
            param1 = p;
        }

    }
}
tschneidereit commented 14 years ago

Thanks, I'll look into it. Certainly looks like it should be working.

jomifo commented 14 years ago

Thank you. I looked into the issue a bit myself. The values of description in the Injector.getInjectionPoints method after createInjectionPointsFromConfigXML (at approximately line 202) are the same when getInjectionPoints is called for each respective class for both the config xml and metadata approaches. However, it seems that the order in which getInjectionPoints for each class (in this case there are two, one for Class1 and one for Object) are reversed between the 2 approaches. Not sure this is the issue, but thought I'd share the observation just in case.

Thanks for your great work on this library. I've been looking for a simple, quick, non-framework-based, Flash-capable DI approach for awhile and your package suits very nicely.

tschneidereit commented 14 years ago

Fixed a bug that caused XML configuration of named constructor arguments to fail

Closed by 22f09aa41b2d784b10fdf72e5272b1e7ad075301

tschneidereit commented 14 years ago

Hey jomifo,

thanks again for the bug report. As it turns out, I made a stupid mistake when implementing ctor injection that caused XML configuration for named arguments to simply be ignored. I've added a zip of version 1.0.1 containing the fix to the downloads.