[ 
https://issues.apache.org/jira/browse/MYFACES-3786?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13794407#comment-13794407
 ] 

Gerhard Petracek edited comment on MYFACES-3786 at 10/14/13 8:23 PM:
---------------------------------------------------------------------

to avoid something like:

{code}
    public void inject(Object instance, String scope) throws 
InjectionProviderException
    {
        AnnotatedType annoType = 
beanManager.createAnnotatedType(instance.getClass());
        InjectionTarget target = beanManager.createInjectionTarget(annoType);
        CreationalContext<?> creationalContext =  
beanManager.createCreationalContext(null);

        DependentInstanceStorage storage;
        if ("application".equals(scope))
        {
            storage = getApplicationScopedDependentInstanceStorage();
        }
        else if ("request".equals(scope))
        {
            storage = getRequestScopedDependentInstanceStorage();
        }
        //else if -- for all known scopes
        else 
        {
            storage = getFallbackDependentInstanceStorage(); //that's the case 
for new scopes
        }

        storage.add(new DependentInstanceEntry(instance, creationalContext));

        target.inject(instance, creationalContext);
    }
{code}

with #2 and #3, we would need to register one instance of a 
(DependentInstance)Storage per scope (with a defined naming-convention for a 
generic lookup by name).
so we could do something like:

{code}
    public void inject(Object instance, String scope) throws 
InjectionProviderException
    {
        AnnotatedType annoType = 
beanManager.createAnnotatedType(instance.getClass());
        InjectionTarget target = beanManager.createInjectionTarget(annoType);
        CreationalContext<?> creationalContext =  
beanManager.createCreationalContext(null);

        DependentInstanceStorage storage = getScopedStorageFor(scope); 
//generic lookup by name
        storage.add(new DependentInstanceEntry(instance, creationalContext));

        target.inject(instance, creationalContext);
    }
{code}

and outside of this method, we have to store the instance in the same storage.
with that we could even support custom scopes later on (in case of cdi).

however, with #4 that's a bit easier since we would have:

{code}
    public void inject(Object instance, DependentInstanceStorage storage /*or a 
std. map/...*/) throws InjectionProviderException
    {
        AnnotatedType annoType = 
beanManager.createAnnotatedType(instance.getClass());
        InjectionTarget target = beanManager.createInjectionTarget(annoType);
        CreationalContext<?> creationalContext =  
beanManager.createCreationalContext(null);

        storage.add(new DependentInstanceEntry(instance, creationalContext));

        target.inject(instance, creationalContext);
    }
{code}

it looks similar, but you don't need #getScopedStorageFor in 2 places (inside 
and outside of InjectionProvider).
+ if we use the map interface, we don't need DependentInstanceStorage as a part 
of the spi (we just can wrap the storage instance in a map or 
DependentInstanceStorage just implements the map interface).
as a first step we just need to create a simple application-scoped map and add 
the whole logic with DependentInstanceStorage once we need to support custom 
scopes.

->
{code}
void inject(Object instance, Map storage) throws InjectionProviderException
public void postConstruct(Object instance, Map storage) throws 
InjectionProviderException
public void preDestroy(Object instance, Map storage) throws 
InjectionProviderException
{code}

@"who holds the context of the injected bean? cdi." (+ the paragraph before):
in the area we are in right now (which isn't the std. usage model) that isn't 
correct at all.
cdi is "context and dependency injection". if you manage instances on your own 
without javax.enterprise.inject.spi.Bean (which is the case here), you only 
have the "dependency injection" part handled by cdi. once you step out of 
javax.enterprise.inject.spi.Bean, you bypass parts of cdi.
-> what i said before is correct.


was (Author: gpetracek):
to avoid something like:

{code}
    public void inject(Object instance, String scope) throws 
InjectionProviderException
    {
        AnnotatedType annoType = 
beanManager.createAnnotatedType(instance.getClass());
        InjectionTarget target = beanManager.createInjectionTarget(annoType);
        CreationalContext<?> creationalContext =  
beanManager.createCreationalContext(null);

        DependentInstanceStorage storage;
        if ("application".equals(scope))
        {
            storage = getApplicationScopedDependentInstanceStorage();
        }
        else if ("request".equals(scope))
        {
            storage = getRequestScopedDependentInstanceStorage();
        }
        //else if -- for all known scopes
        else 
        {
            storage = getFallbackDependentInstanceStorage(); //that's the case 
for new scopes
        }

        storage.add(new DependentInstanceEntry(instance, creationalContext));

        target.inject(instance, creationalContext);
    }
{code}

with #2 and #3, we would need to register one instance of a 
(DependentInstance)Storage per scope (with a defined naming-convention for a 
generic lookup by name).
so we could do something like:

{code}
    public void inject(Object instance, String scope) throws 
InjectionProviderException
    {
        AnnotatedType annoType = 
beanManager.createAnnotatedType(instance.getClass());
        InjectionTarget target = beanManager.createInjectionTarget(annoType);
        CreationalContext<?> creationalContext =  
beanManager.createCreationalContext(null);

        DependentInstanceStorage storage = getScopedStorageFor(scope); 
//generic lookup by name
        storage.add(new DependentInstanceEntry(instance, creationalContext));

        target.inject(instance, creationalContext);
    }
{code}

and outside of this method, we have to store the instance in the same storage.
with that we could even support custom scopes later on (in case of cdi).

however, with #4 that's a bit easier since we would have:

{code}
    public void inject(Object instance, DependentInstanceStorage storage /*or a 
std. map/...*/) throws InjectionProviderException
    {
        AnnotatedType annoType = 
beanManager.createAnnotatedType(instance.getClass());
        InjectionTarget target = beanManager.createInjectionTarget(annoType);
        CreationalContext<?> creationalContext =  
beanManager.createCreationalContext(null);

        storage.add(new DependentInstanceEntry(instance, creationalContext));

        target.inject(instance, creationalContext);
    }
{code}

it looks similar, but you don't need #getScopedStorageFor in 2 places (inside 
and outside of InjectionProvider).
+ if we use the map interface, we don't need DependentInstanceStorage as a part 
of the spi (we just can wrap the storage instance in a map or 
DependentInstanceStorage just implements the map interface).
as a first step we just need to create a simple application-scoped map and add 
the whole logic with DependentInstanceStorage once we need to support custom 
scopes.

->
{code}
void inject(Object instance, Map storage) throws InjectionProviderException
{code}

@"who holds the context of the injected bean? cdi." (+ the paragraph before):
in the area we are in right now (which isn't the std. usage model) that isn't 
correct at all.
cdi is "context and dependency injection". if you manage instances on your own 
without javax.enterprise.inject.spi.Bean (which is the case here), you only 
have the "dependency injection" part handled by cdi. once you step out of 
javax.enterprise.inject.spi.Bean, you bypass parts of cdi.
-> what i said before is correct.

> Web Container injection support should be provided for additional lifecycle 
> artifacts (not just managed beans)
> --------------------------------------------------------------------------------------------------------------
>
>                 Key: MYFACES-3786
>                 URL: https://issues.apache.org/jira/browse/MYFACES-3786
>             Project: MyFaces Core
>          Issue Type: Task
>          Components: JSR-344
>            Reporter: Leonardo Uribe
>            Assignee: Leonardo Uribe
>             Fix For: 2.2.0
>
>         Attachments: cdiELresolverWeb.zip, cdiELResolver.zip, 
> cdiPartialViewContext.war, cdiPartialViewContext.zip, cdi.patch, 
> cdiphaselistener1.patch, cdiphaselistener2.patch, cdirevised.patch, 
> cdiValidatorSource.zip, cdiValidator.war, MYFACES-3786-1.patch, 
> MYFACES-3786-2.patch
>
>
>  This issue is all about how to inject beans into jsf artifacts.
> See JSF 2.2 section 5.4.1
> The problem here is in some point we need to give the control to the 
> underlying environment to inject beans into the artifacts, but we don't know 
> much about how to properly do it, so we need to try with examples.



--
This message was sent by Atlassian JIRA
(v6.1#6144)

Reply via email to