[xwiki-devs] [Proposal] Add support for JSR330 Provider
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/Provi... 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
+1 On Thu, Nov 10, 2011 at 3:44 PM, Vincent Massol <[email protected]> wrote:
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/Provi...
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 [email protected] http://lists.xwiki.org/mailman/listinfo/devs
-- Thomas Mortagne
+1 On Thu, Nov 10, 2011 at 15:53, Thomas Mortagne <[email protected]>wrote:
+1
On Thu, Nov 10, 2011 at 3:44 PM, Vincent Massol <[email protected]> wrote:
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/Provi...
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 [email protected] http://lists.xwiki.org/mailman/listinfo/devs
-- Thomas Mortagne _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
-- Denis Gervalle SOFTEC sa - CEO eGuilde sarl - CTO
+1 Caleb On 11/10/2011 09:44 AM, Vincent Massol wrote:
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/Provi...
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 [email protected] http://lists.xwiki.org/mailman/listinfo/devs
+1 Thanks, Marius On Thu, Nov 10, 2011 at 4:44 PM, Vincent Massol <[email protected]> wrote:
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/Provi...
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 [email protected] http://lists.xwiki.org/mailman/listinfo/devs
+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/Provi...
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 [email protected] http://lists.xwiki.org/mailman/listinfo/devs
participants (6)
-
Andreas Jonsson -
Caleb James DeLisle -
Denis Gervalle -
Marius Dumitru Florea -
Thomas Mortagne -
Vincent Massol