Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //snippet 1:
- 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);
- }
- //snippet 2:
- 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);
- }
- //snippet 3:
- 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);
- }
Advertisement
Add Comment
Please, Sign In to add comment