wookieb / alpha-dic

Powerful dependency injection container for node.js
MIT License
27 stars 0 forks source link

Add findServicesByAnnotation #5

Closed wookieb closed 7 years ago

wookieb commented 7 years ago

I found "getByPredicate" and "getByAnnotationName" methods insufficient for advanced service aggregation.

Most of the times I need to perform extra operations based on annotation properties. Once services are resolved by one of above method i'm losing information where certain instance comes from.

dic.getByAnnotationName('event-listener')
    .then((eventListeners) => {
        // what if I need to sort event listener by priority?
        // what if I need to perform additional configuration based on annotation properties?
    })

Instead introduce "findByAnnotation" and "findByPredicate"


const services = dic.findByAnnotation('event-listener', {event: 'event-name'})
    .sort((a, b) => a.getAnnotation('event-listener').priority - b.getAnnotation('event-listener').priority);

dic.getMany(services)
.then( .... )