Skip to content

Instantly share code, notes, and snippets.

@Kotlin-Native
Created July 9, 2015 13:51
Show Gist options
  • Select an option

  • Save Kotlin-Native/31ab3430ea9582484b2e to your computer and use it in GitHub Desktop.

Select an option

Save Kotlin-Native/31ab3430ea9582484b2e to your computer and use it in GitHub Desktop.
CdiScope
public class CdiScope implements Scope {
private BeanManager beanManager;
private Map<string,><object>>beans;
public CdiScope(BeanManager beanManager,
Map<string,><object>>beans) {
this.beanManager = beanManager;
this.beans = beans;
}
public Object get(String name, ObjectFactory objectFactory) {
Bean<object> bean = beans.get(name);
CreationalContext<object> context
= beanManager.createCreationalContext(bean);
return beanManager.getReference(bean, bean.getBeanClass(), context);
}
public Object remove(String name) {
Object beanInstance = get(name, null);
Bean<object> bean = beans.get(name);
CreationalContext<object> context
= beanManager.createCreationalContext(bean);
bean.destroy(beanInstance, context);
return beanInstance;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment