Method injection in Parsley

315 views Asked by At

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.

1

There are 1 answers

0
Paul Sweatte On

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