greenrobot/EventBus

About how EventBus#getDefault() is used

tenyears94 opened this issue · 4 comments

For the EventBus#getDefault() method to get EventBus, do you recommend using EventBus.getDefault() directly to get it, or hand it over to the Spring container for management and injection upon invocation?

andob commented

this is not a library-related question. there's no right answer, depends on your code style.

If you want to follow DI principles to the letter, you should instantiate EventBus object on a @ Bean factory method, then inject it.

this is not a library-related question. there's no right answer, depends on your code style.

If you want to follow DI principles to the letter, you should instantiate EventBus object on a @ Bean factory method, then inject it.

I'm glad to receive your answer. I'm using what you said right now, but I'm not sure if I see examples on the official website that are being used by EventBus.getDefault().

andob commented

I don't think there's a need for such documentation. This library is written in pure Java SE, doesn't depend on any other library and it is framework agnostic. That means you can use it on top of any java framework you want, anyway you want.

Usually when you see documentation online on "how to integrate technology X with spring", it's about libraries that deeply and magically integrates with spring, via annotations. It's not the case here. A quick example: the Jedis library is a Redis client, it's framework agnostic, it doesn't tell you how to use it with spring, or force you to use it with spring or other framework in a very specific way. On the other hand, the @ Cacheable annotation, tells you specifically how to cache on Redis with spring, but you can't reuse the same code outside of spring.

I don't think there's a need for such documentation. This library is written in pure Java SE, doesn't depend on any other library and it is framework agnostic. That means you can use it on top of any java framework you want, anyway you want.

Usually when you see documentation online on "how to integrate technology X with spring", it's about libraries that deeply and magically integrates with spring, via annotations. It's not the case here. A quick example: the Jedis library is a Redis client, it's framework agnostic, it doesn't tell you how to use it with spring, or force you to use it with spring or other framework in a very specific way. On the other hand, the @ Cacheable annotation, tells you specifically how to cache on Redis with spring, but you can't reuse the same code outside of spring.

I think I understand what you mean. Thank you very much for your answer. I will close this Issues and thank you again