Skip to content

Instantly share code, notes, and snippets.

@lordofthejars
Last active August 29, 2015 14:06
Show Gist options
  • Select an option

  • Save lordofthejars/bb79d12840c8d18d1baf to your computer and use it in GitHub Desktop.

Select an option

Save lordofthejars/bb79d12840c8d18d1baf to your computer and use it in GitHub Desktop.
@ApplicationScoped
public class MongoCollectionProducer {
@Inject
DB mongoDb;
Jongo jongo;
@PostConstruct
public void initialize() throws UnknownHostException {
jongo = new Jongo(mongoDb);
}
@Produces
@JongoCollection
MongoCollection collection(InjectionPoint injectionPoint) {
JongoCollection jongoCollectionAnnotation = Reflection.annotation(injectionPoint
.getQualifiers(), JongoCollection.class);
if(jongoCollectionAnnotation != null) {
String collectionName = jongoCollectionAnnotation.value();
return jongo.getCollection(collectionName);
}
throw new IllegalArgumentException();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment