[JBoss JIRA] (CDI-535) cdi instance injection ordering
by John Ament (JIRA)
[ https://issues.jboss.org/browse/CDI-535?page=com.atlassian.jira.plugin.sy... ]
John Ament commented on CDI-535:
--------------------------------
I would say more than anything, my concern is on the reuse/misuse of {{Priority}} and using something new like {{OrderBy}} would not be an issue. Priority introduces misuse in my opinion.
Even then, if you have multiple beans, all from the same field (all dependent scoped for example), how would you order them?
> cdi instance injection ordering
> -------------------------------
>
> Key: CDI-535
> URL: https://issues.jboss.org/browse/CDI-535
> Project: CDI Specification Issues
> Issue Type: Feature Request
> Components: Beans
> Affects Versions: 2.0 (discussion)
> Reporter: Ochieng Marembo
> Priority: Optional
>
> We should allow ordering of bean instance injection using the {{Instance<MyBeanInterface>}} when an instance injection is used.
> h3. Use case:
> Developer always define a kind of chain of processor beans, which may need to run in specific order.
> h3. Current scenario:
> Using the Instance injection mechanism, a developer can inject multiple beans implementing the same interface and iterate of them. In order to ensure ordering, the developer could do one of the following:
> #1
> {code:java}
> private Iterable<MyBeanInterface> myBeans;
> @Inject
> void injectBeans(@Any Instance<MyBeanInterface> myBeans) {
> //the create order does some kind of ordering on the beans.
> this.myBeans = createOrder(myBeans);
> }
> {code}
> #2
> This second option may be expensive if we have to order the beans everytime we execute the logic, and if this bean is applicationscoped, it wont make sense to do the ordering in the method call.
> {code:java}
> @Any
> @Inject
> private Instance<MyBeanInterface> myBeans;
> public void doSomething() {
> Iterable<MyBeanInterface> orderedbeans = createOrder(myBeans.select(someQualifier));
> }
> {code}
> h3. Our Proposal
> We already have {{javax.annotation.Priority}} or any cdi specific annotation which we can add to {{MyBeanInterfaceImpl}} so that on injection of an {{Instance<MyBeanInterface>}}, all possible injection values are sorted based on the {{Priority.value()}} and if no annotation is defined, defaults to {{Priority.value = Integer.MAX_VALUE}}
> {code:java}
> public interface MyBeanInterface {}
> @MyQualifier
> @Priority(0)
> public class MyFirstBean implements MyBeanInterface{
> }
> @MyQualifier
> @Priority(2)
> public class MySecondBean implements MyBeanInterface{
> }
> @ApplicationScoped
> public class MyBeanProcessor {
> //We expect that this injected instances shall be in order based on the @Priority annotation
> @Any
> @Inject
> private Instance<MyBeanInterface> myBeans;
> }
> {code}
--
This message was sent by Atlassian JIRA
(v6.4.11#64026)
8 years, 2 months
[JBoss JIRA] (CDI-452) Specify that web scoped (request, session, application) beans are injectable in async servlets
by arjan tijms (JIRA)
[ https://issues.jboss.org/browse/CDI-452?page=com.atlassian.jira.plugin.sy... ]
arjan tijms commented on CDI-452:
---------------------------------
[~marembo2008]
The mentioned opaque security context is not particular to EJB. In fact, CDI already makes use of it by having a build-in bean for {{Principal}}, meaning you can do {{@Inject Principal principal}}. And Servlet containers use the same thing via web.xml constraints and things like {{HttpServletRequest.getUserPrincipal}}.
So nothing of what I mentioned is EJB specific. Even things like {{@RolesAllowed}} are in fact not EJB (they're from Common Annotations, aka JSR 250), and every spec, including CDI can use it. This is also one of the goals of JSR 375 (Java EE Security API).
> Specify that web scoped (request, session, application) beans are injectable in async servlets
> ----------------------------------------------------------------------------------------------
>
> Key: CDI-452
> URL: https://issues.jboss.org/browse/CDI-452
> Project: CDI Specification Issues
> Issue Type: Feature Request
> Components: Contexts, Java EE integration
> Affects Versions: 1.0
> Reporter: Ed Burns
> Assignee: John Ament
> Fix For: 2.0 (discussion)
>
>
> Consider this code based on this blog post: < https://weblogs.java.net/blog/swchan2/archive/2013/06/06/asynchronous-ser... >.
> {code}
> @WebServlet(urlPatterns="/test2", asyncSupported=true)
> public class TestAsyncMESServlet extends HttpServlet {
> @Resource
> private ManagedExecutorService managedExecutorService;
> @Inject
> MyRunnableImpl myRunnableImpl;
> @Override
> protected void doGet(HttpServletRequest req, HttpServletResponse res)
> throws ServletException, IOException {
> final AsyncContext asyncContext = req.startAsync();
> final PrintWriter writer = res.getWriter();
> managedExecutorService.submit(myRunnableImpl);
> }
> public static class MyRunnableImpl implements Runnable {
> @Inject
> Bean bean; // Bean is @RequestScoped
> @Override
> public void run() {
> writer.println("Done");
> asyncContext.complete();
> }
> }
> }
> {code}
> According to Jozef Hartzinger, this currently does not work, because only @Dependent and @ApplicationScoped beans are propagated to the new thread. To keep CDI relevant in light of the reactive programming movement and the popularity of node.js, we need to make this work.
--
This message was sent by Atlassian JIRA
(v6.4.11#64026)
8 years, 2 months
[JBoss JIRA] (CDI-452) Specify that web scoped (request, session, application) beans are injectable in async servlets
by Ochieng Marembo (JIRA)
[ https://issues.jboss.org/browse/CDI-452?page=com.atlassian.jira.plugin.sy... ]
Ochieng Marembo commented on CDI-452:
-------------------------------------
[~arjant] for javaee ejb environment, that works. But CDI is not meant primarily for a full java ee environment. Infact, most people prefer using CDI outside the bounds of ejb-containers, as ejb is relegated to heavy weight transactional backend-services, and for application which are not transactional, using ejb's for its security and role context would not suffice.
> Specify that web scoped (request, session, application) beans are injectable in async servlets
> ----------------------------------------------------------------------------------------------
>
> Key: CDI-452
> URL: https://issues.jboss.org/browse/CDI-452
> Project: CDI Specification Issues
> Issue Type: Feature Request
> Components: Contexts, Java EE integration
> Affects Versions: 1.0
> Reporter: Ed Burns
> Assignee: John Ament
> Fix For: 2.0 (discussion)
>
>
> Consider this code based on this blog post: < https://weblogs.java.net/blog/swchan2/archive/2013/06/06/asynchronous-ser... >.
> {code}
> @WebServlet(urlPatterns="/test2", asyncSupported=true)
> public class TestAsyncMESServlet extends HttpServlet {
> @Resource
> private ManagedExecutorService managedExecutorService;
> @Inject
> MyRunnableImpl myRunnableImpl;
> @Override
> protected void doGet(HttpServletRequest req, HttpServletResponse res)
> throws ServletException, IOException {
> final AsyncContext asyncContext = req.startAsync();
> final PrintWriter writer = res.getWriter();
> managedExecutorService.submit(myRunnableImpl);
> }
> public static class MyRunnableImpl implements Runnable {
> @Inject
> Bean bean; // Bean is @RequestScoped
> @Override
> public void run() {
> writer.println("Done");
> asyncContext.complete();
> }
> }
> }
> {code}
> According to Jozef Hartzinger, this currently does not work, because only @Dependent and @ApplicationScoped beans are propagated to the new thread. To keep CDI relevant in light of the reactive programming movement and the popularity of node.js, we need to make this work.
--
This message was sent by Atlassian JIRA
(v6.4.11#64026)
8 years, 2 months
[JBoss JIRA] (CDI-535) cdi instance injection ordering
by George Gastaldi (JIRA)
[ https://issues.jboss.org/browse/CDI-535?page=com.atlassian.jira.plugin.sy... ]
George Gastaldi commented on CDI-535:
-------------------------------------
By the way, in my example above {{@OrderBy}} is not meant to be a {{@Qualifier}}, just a marker annotation
> cdi instance injection ordering
> -------------------------------
>
> Key: CDI-535
> URL: https://issues.jboss.org/browse/CDI-535
> Project: CDI Specification Issues
> Issue Type: Feature Request
> Components: Beans
> Affects Versions: 2.0 (discussion)
> Reporter: Ochieng Marembo
> Priority: Optional
>
> We should allow ordering of bean instance injection using the {{Instance<MyBeanInterface>}} when an instance injection is used.
> h3. Use case:
> Developer always define a kind of chain of processor beans, which may need to run in specific order.
> h3. Current scenario:
> Using the Instance injection mechanism, a developer can inject multiple beans implementing the same interface and iterate of them. In order to ensure ordering, the developer could do one of the following:
> #1
> {code:java}
> private Iterable<MyBeanInterface> myBeans;
> @Inject
> void injectBeans(@Any Instance<MyBeanInterface> myBeans) {
> //the create order does some kind of ordering on the beans.
> this.myBeans = createOrder(myBeans);
> }
> {code}
> #2
> This second option may be expensive if we have to order the beans everytime we execute the logic, and if this bean is applicationscoped, it wont make sense to do the ordering in the method call.
> {code:java}
> @Any
> @Inject
> private Instance<MyBeanInterface> myBeans;
> public void doSomething() {
> Iterable<MyBeanInterface> orderedbeans = createOrder(myBeans.select(someQualifier));
> }
> {code}
> h3. Our Proposal
> We already have {{javax.annotation.Priority}} or any cdi specific annotation which we can add to {{MyBeanInterfaceImpl}} so that on injection of an {{Instance<MyBeanInterface>}}, all possible injection values are sorted based on the {{Priority.value()}} and if no annotation is defined, defaults to {{Priority.value = Integer.MAX_VALUE}}
> {code:java}
> public interface MyBeanInterface {}
> @MyQualifier
> @Priority(0)
> public class MyFirstBean implements MyBeanInterface{
> }
> @MyQualifier
> @Priority(2)
> public class MySecondBean implements MyBeanInterface{
> }
> @ApplicationScoped
> public class MyBeanProcessor {
> //We expect that this injected instances shall be in order based on the @Priority annotation
> @Any
> @Inject
> private Instance<MyBeanInterface> myBeans;
> }
> {code}
--
This message was sent by Atlassian JIRA
(v6.4.11#64026)
8 years, 2 months
[JBoss JIRA] (CDI-535) cdi instance injection ordering
by George Gastaldi (JIRA)
[ https://issues.jboss.org/browse/CDI-535?page=com.atlassian.jira.plugin.sy... ]
George Gastaldi updated CDI-535:
--------------------------------
Description:
We should allow ordering of bean instance injection using the {{Instance<MyBeanInterface>}} when an instance injection is used.
h3. Use case:
Developer always define a kind of chain of processor beans, which may need to run in specific order.
h3. Current scenario:
Using the Instance injection mechanism, a developer can inject multiple beans implementing the same interface and iterate of them. In order to ensure ordering, the developer could do one of the following:
#1
{code:java}
private Iterable<MyBeanInterface> myBeans;
@Inject
void injectBeans(@Any Instance<MyBeanInterface> myBeans) {
//the create order does some kind of ordering on the beans.
this.myBeans = createOrder(myBeans);
}
{code}
#2
This second option may be expensive if we have to order the beans everytime we execute the logic, and if this bean is applicationscoped, it wont make sense to do the ordering in the method call.
{code:java}
@Any
@Inject
private Instance<MyBeanInterface> myBeans;
public void doSomething() {
Iterable<MyBeanInterface> orderedbeans = createOrder(myBeans.select(someQualifier));
}
{code}
h3. Our Proposal
We already have {{javax.annotation.Priority}} or any cdi specific annotation which we can add to {{MyBeanInterfaceImpl}} so that on injection of an {{Instance<MyBeanInterface>}}, all possible injection values are sorted based on the {{Priority.value()}} and if no annotation is defined, defaults to {{Priority.value = Integer.MAX_VALUE}}
{code:java}
public interface MyBeanInterface {}
@MyQualifier
@Priority(0)
public class MyFirstBean implements MyBeanInterface{
}
@MyQualifier
@Priority(2)
public class MySecondBean implements MyBeanInterface{
}
@ApplicationScoped
public class MyBeanProcessor {
//We expect that this injected instances shall be in order based on the @Priority annotation
@Any
@Inject
private Instance<MyBeanInterface> myBeans;
}
{code}
was:
We should allow ordering of bean instance injection using the ```Instance<MyBeanInterface>``` when an instance injection is used.
h3. Use case:
Developer always define a kind of chain of processor beans, which may need to run in specific order.
h3. Current scenario:
Using the Instance injection mechanism, a developer can inject multiple beans implementing the same interface and iterate of them. In order to ensure ordering, the developer could do one of the following:
#1
{code:java}
private Iterable<MyBeanInterface> myBeans;
@Inject
void injectBeans(@Any Instance<MyBeanInterface> myBeans) {
//the create order does some kind of ordering on the beans.
this.myBeans = createOrder(myBeans);
}
{code}
#2
This second option may be expensive if we have to order the beans everytime we execute the logic, and if this bean is applicationscoped, it wont make sense to do the ordering in the method call.
{code:java}
@Any
@Inject
private Instance<MyBeanInterface> myBeans;
public void doSomething() {
Iterable<MyBeanInterface> orderedbeans = createOrder(myBeans.select(someQualifier));
}
{code}
h3. Our Proposal
We already have {code}javax.annotation.Priority{code} or any cdi specific annotation which we can add to {code}MyBeanInterfaceImpl{code} so that on injection of an {code}Instance<MyBeanInterface>{code}, all possible injection values are sorted based on the {code}Priority.value(){code} and if no annotation is defined, defaults to {code}Priority.value = Integer.MAX_VALUE{code}
{code:java}
public interface MyBeanInterface {}
@MyQualifier
@Priority(0)
public class MyFirstBean implements MyBeanInterface{
}
@MyQualifier
@Priority(2)
public class MySecondBean implements MyBeanInterface{
}
@ApplicationScoped
public class MyBeanProcessor {
//We expect that this injected instances shall be in order based on the @Priority annotation
@Any
@Inject
private Instance<MyBeanInterface> myBeans;
}
{code}
> cdi instance injection ordering
> -------------------------------
>
> Key: CDI-535
> URL: https://issues.jboss.org/browse/CDI-535
> Project: CDI Specification Issues
> Issue Type: Feature Request
> Components: Beans
> Affects Versions: 2.0 (discussion)
> Reporter: Ochieng Marembo
> Priority: Optional
>
> We should allow ordering of bean instance injection using the {{Instance<MyBeanInterface>}} when an instance injection is used.
> h3. Use case:
> Developer always define a kind of chain of processor beans, which may need to run in specific order.
> h3. Current scenario:
> Using the Instance injection mechanism, a developer can inject multiple beans implementing the same interface and iterate of them. In order to ensure ordering, the developer could do one of the following:
> #1
> {code:java}
> private Iterable<MyBeanInterface> myBeans;
> @Inject
> void injectBeans(@Any Instance<MyBeanInterface> myBeans) {
> //the create order does some kind of ordering on the beans.
> this.myBeans = createOrder(myBeans);
> }
> {code}
> #2
> This second option may be expensive if we have to order the beans everytime we execute the logic, and if this bean is applicationscoped, it wont make sense to do the ordering in the method call.
> {code:java}
> @Any
> @Inject
> private Instance<MyBeanInterface> myBeans;
> public void doSomething() {
> Iterable<MyBeanInterface> orderedbeans = createOrder(myBeans.select(someQualifier));
> }
> {code}
> h3. Our Proposal
> We already have {{javax.annotation.Priority}} or any cdi specific annotation which we can add to {{MyBeanInterfaceImpl}} so that on injection of an {{Instance<MyBeanInterface>}}, all possible injection values are sorted based on the {{Priority.value()}} and if no annotation is defined, defaults to {{Priority.value = Integer.MAX_VALUE}}
> {code:java}
> public interface MyBeanInterface {}
> @MyQualifier
> @Priority(0)
> public class MyFirstBean implements MyBeanInterface{
> }
> @MyQualifier
> @Priority(2)
> public class MySecondBean implements MyBeanInterface{
> }
> @ApplicationScoped
> public class MyBeanProcessor {
> //We expect that this injected instances shall be in order based on the @Priority annotation
> @Any
> @Inject
> private Instance<MyBeanInterface> myBeans;
> }
> {code}
--
This message was sent by Atlassian JIRA
(v6.4.11#64026)
8 years, 2 months
[JBoss JIRA] (CDI-535) cdi instance injection ordering
by George Gastaldi (JIRA)
[ https://issues.jboss.org/browse/CDI-535?page=com.atlassian.jira.plugin.sy... ]
George Gastaldi updated CDI-535:
--------------------------------
Description:
We should allow ordering of bean instance injection using the ```Instance<MyBeanInterface>``` when an instance injection is used.
h3. Use case:
Developer always define a kind of chain of processor beans, which may need to run in specific order.
h3. Current scenario:
Using the Instance injection mechanism, a developer can inject multiple beans implementing the same interface and iterate of them. In order to ensure ordering, the developer could do one of the following:
#1
{code:java}
private Iterable<MyBeanInterface> myBeans;
@Inject
void injectBeans(@Any Instance<MyBeanInterface> myBeans) {
//the create order does some kind of ordering on the beans.
this.myBeans = createOrder(myBeans);
}
{code}
#2
This second option may be expensive if we have to order the beans everytime we execute the logic, and if this bean is applicationscoped, it wont make sense to do the ordering in the method call.
{code:java}
@Any
@Inject
private Instance<MyBeanInterface> myBeans;
public void doSomething() {
Iterable<MyBeanInterface> orderedbeans = createOrder(myBeans.select(someQualifier));
}
{code}
h3. Our Proposal
We already have {code}javax.annotation.Priority{code} or any cdi specific annotation which we can add to {code}MyBeanInterfaceImpl{code} so that on injection of an {code}Instance<MyBeanInterface>{code}, all possible injection values are sorted based on the {code}Priority.value(){code} and if no annotation is defined, defaults to {code}Priority.value = Integer.MAX_VALUE{code}
{code:java}
public interface MyBeanInterface {}
@MyQualifier
@Priority(0)
public class MyFirstBean implements MyBeanInterface{
}
@MyQualifier
@Priority(2)
public class MySecondBean implements MyBeanInterface{
}
@ApplicationScoped
public class MyBeanProcessor {
//We expect that this injected instances shall be in order based on the @Priority annotation
@Any
@Inject
private Instance<MyBeanInterface> myBeans;
}
{code}
was:
We should allow ordering of bean instance injection using the ```Instance<MyBeanInterface>``` when an instance injection is used.
h3. Use case:
Developer always define a kind of chain of processor beans, which may need to run in specific order.
h3. Current scenario:
Using the Instance injection mechanism, a developer can inject multiple beans implementing the same interface and iterate of them. In order to ensure ordering, the developer could do one of the following:
#1
{code}
private Iterable<MyBeanInterface> myBeans;
@Inject
void injectBeans(@Any Instance<MyBeanInterface> myBeans) {
//the create order does some kind of ordering on the beans.
this.myBeans = createOrder(myBeans);
}
{code}
#2
This second option may be expensive if we have to order the beans everytime we execute the logic, and if this bean is applicationscoped, it wont make sense to do the ordering in the method call.
{code}
@Any
@Inject
private Instance<MyBeanInterface> myBeans;
public void doSomething() {
Iterable<MyBeanInterface> orderedbeans = createOrder(myBeans.select(someQualifier));
}
{code}
h3. Our Proposal
We already have {code}javax.annotation.Priority{code} or any cdi specific annotation which we can add to {code}MyBeanInterfaceImpl{code} so that on injection of an {code}Instance<MyBeanInterface>{code}, all possible injection values are sorted based on the {code}Priority.value(){code} and if no annotation is defined, defaults to {code}Priority.value = Integer.MAX_VALUE{code}
{code}
public interface MyBeanInterface {}
@MyQualifier
@Priority(0)
public class MyFirstBean implements MyBeanInterface{
}
@MyQualifier
@Priority(2)
public class MySecondBean implements MyBeanInterface{
}
@ApplicationScoped
public class MyBeanProcessor {
//We expect that this injected instances shall be in order based on the @Priority annotation
@Any
@Inject
private Instance<MyBeanInterface> myBeans;
}
{code}
> cdi instance injection ordering
> -------------------------------
>
> Key: CDI-535
> URL: https://issues.jboss.org/browse/CDI-535
> Project: CDI Specification Issues
> Issue Type: Feature Request
> Components: Beans
> Affects Versions: 2.0 (discussion)
> Reporter: Ochieng Marembo
> Priority: Optional
>
> We should allow ordering of bean instance injection using the ```Instance<MyBeanInterface>``` when an instance injection is used.
> h3. Use case:
> Developer always define a kind of chain of processor beans, which may need to run in specific order.
> h3. Current scenario:
> Using the Instance injection mechanism, a developer can inject multiple beans implementing the same interface and iterate of them. In order to ensure ordering, the developer could do one of the following:
> #1
> {code:java}
> private Iterable<MyBeanInterface> myBeans;
> @Inject
> void injectBeans(@Any Instance<MyBeanInterface> myBeans) {
> //the create order does some kind of ordering on the beans.
> this.myBeans = createOrder(myBeans);
> }
> {code}
> #2
> This second option may be expensive if we have to order the beans everytime we execute the logic, and if this bean is applicationscoped, it wont make sense to do the ordering in the method call.
> {code:java}
> @Any
> @Inject
> private Instance<MyBeanInterface> myBeans;
> public void doSomething() {
> Iterable<MyBeanInterface> orderedbeans = createOrder(myBeans.select(someQualifier));
> }
> {code}
> h3. Our Proposal
> We already have {code}javax.annotation.Priority{code} or any cdi specific annotation which we can add to {code}MyBeanInterfaceImpl{code} so that on injection of an {code}Instance<MyBeanInterface>{code}, all possible injection values are sorted based on the {code}Priority.value(){code} and if no annotation is defined, defaults to {code}Priority.value = Integer.MAX_VALUE{code}
> {code:java}
> public interface MyBeanInterface {}
> @MyQualifier
> @Priority(0)
> public class MyFirstBean implements MyBeanInterface{
> }
> @MyQualifier
> @Priority(2)
> public class MySecondBean implements MyBeanInterface{
> }
> @ApplicationScoped
> public class MyBeanProcessor {
> //We expect that this injected instances shall be in order based on the @Priority annotation
> @Any
> @Inject
> private Instance<MyBeanInterface> myBeans;
> }
> {code}
--
This message was sent by Atlassian JIRA
(v6.4.11#64026)
8 years, 2 months