0

Is it possible to inject method using parsley framework in flex application ?

I am able to inject the class itself but is it possible for method to be injected.

dvdgsng
  • 1,691
  • 16
  • 27
TrexTroy
  • 303
  • 7
  • 22
  • 1
    Since you can inject both classes and simple properties, I don't see why you wouldn't be able to inject a `Function` reference. – RIAstar Aug 22 '13 at 14:22
  • 1
    Note that this is exactly what Parsley does w/it's `[MessageDispatcher]` meta data. How you to do this w/some other method is probably buried in the Parsley documentation. You might specify which version of Parsley you're using then maybe someone more enlightened than me can help you. – Sunil D. Aug 23 '13 at 16:21
  • 1
    On further review, you might be able to use "property injection" where the property in question is a `Function`. However, you cannot inject this property by type, you'd have to inject it using an ID. The "inject by type" way won't work, because all functions are of type `Function` and there's no way for Parsley to know which function it should inject into the property. – Sunil D. Aug 23 '13 at 16:23

1 Answers1

0

You can place [Inject] metadata tags on any number of methods:

package com.bookstore.actions 
{

class LoginAction 
    {
    private var service:LoginService;
    private var manager:UserManager;

    [Inject]
    public function init (service:LoginService, manager:UserManager = null) : void        
        {
        this.service = service;
        this.manager = manager;    
        }

    }
}

As with Constructor Injection Parsley will recognize whether a method parameter is optional or not and accordingly treat the dependency as optional or required. The object to be injected will be selected by type, so you should make sure to include at most one object with a matching type into your configuration. For Method Injection there are no restrictions on MXML configuration, so in contrast to Constructor Injection you could also use simple MXML tags for adding the objects to the container.

References

Parsley Manual: Method Injection

Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265