+1 Best regards,
Andreas Jonsson 2011-11-10 15:44, Vincent Massol skrev: > Hi devs, > > I've started investigating this. The documentation for Provider can be found > here: > http://code.google.com/p/atinject/source/browse/trunk/src/javax/inject/Provider.java > > Here's we would define a provider: > > @Component > public class MyProvider implements Provider<RoleToProvide> > { > @Inject <-- just to show that a provider is a component and be injected > other components > private SomeRole role; > > @Override > public RoleToProvide get() > { > … logic here to return a RoleToProvide instance… > } > } > > And here's how you'd use it: > > @Component > public class MyComponent implements MyRole > { > … > @Inject > private Provider<RoleToProvide> provider; > … > public void someMethod() > { > RoleToProvide instance = this.provider.get(); > … > > Rationale: > ========= > > * UC1: Useful to break cyclic dependencies in a cleaner way than having the > ComponentManager injected, especially since the Provider can be reused since > it's shared > * UC2: Useful to clean up code so that the logic to decide which > implementation to return can be externalized in a Provider implementation. > For example imagine you have a config property in xwiki.properties and based > on it you wish to return a component with one hint or another. You could use > a Provider for this. > * Allows us to be JSR330 compliant (not a very strong point but still an > argument ;)) > > Default Provider > ============= > > When you ask to get injected a Provider if no Provider is defined for the > Role you wish, you'll get injected a generic provider which simply does a > lookup using the Component Manager. This allows to simply implement UC1. > > WDYT? > > Thanks > -Vincent > > _______________________________________________ > devs mailing list > devs@xwiki.org > http://lists.xwiki.org/mailman/listinfo/devs > _______________________________________________ devs mailing list devs@xwiki.org http://lists.xwiki.org/mailman/listinfo/devs