1

I am writing a framework on top of it where other teams develop applications.

I want to provide Dependency Injection as part of it. I am making developers uses JSR 330 annotations and my framework can work on DI.

Still i have the following problem

Developer need to write module if i use Guice, beans.xml if I use WELD. This couples specific DI with my developer app code. I want to switch underlying dependency injection in framework without touching any of the application code.

Is there anyway to do it?

naveen
  • 124
  • 9
  • possible duplicate of [Spring and Guice together, or just Spring](http://stackoverflow.com/questions/21056063/spring-and-guice-together-or-just-spring) – durron597 Jul 01 '15 at 14:22
  • That question talks about which framework is best. But this question is about providing a common configuration for all 3 frameworks. – naveen Jul 03 '15 at 04:03

2 Answers2

4

If you strictly stick to JSR330 features, it is possible to provide a framework jar that can be used by all three implementing DI-frameworks you mentioned. To allow CDI to scan the module, you should provide a bean.xml, but I wouldn't call that code invasive.

If you need to provide something more than just JSR330, like modules, factories, producer-methods, AutoConfigurations, ... you could offer custom extension modules, so you have "myframework-core" for the implemantation agnostic stuff and "myframework-guice" on top of it providing helpers and modules for guice and so on.

Jan Galinski
  • 11,768
  • 8
  • 54
  • 77
0

I do not think JSR-330 has enough information about how the system starts in order for it to be truly switchable. For example, if you are using Guice you will need to create an Injector. If you are using Spring you will need to use its JavaConfig. If you are using HK2 you'll need to use either the inhabitant generator or use Modules. If you are using CDI you do only need a beans.xml (and in the later CDI you don't even need that) but you will almost definitely find that you need other features of CDI such as Producers.

I think JSR-330 is too minimal to be portable for these reasons

jwells131313
  • 2,364
  • 1
  • 16
  • 26