File tree Expand file tree Collapse file tree 3 files changed +40
-1
lines changed Expand file tree Collapse file tree 3 files changed +40
-1
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ dependencies {
35
35
implementation " com.google.protobuf:protobuf-java:$protobufVersion "
36
36
37
37
implementation(' org.glassfish.jersey.containers:jersey-container-servlet:3.1.0' )
38
+ implementation(' org.glassfish.jersey.inject:jersey-hk2:3.1.0' )
38
39
39
40
// jOOQ & Postgres impl deps
40
41
implementation " org.jooq:jooq:$jooqVersion "
@@ -44,6 +45,10 @@ dependencies {
44
45
jooqGenerator " org.postgresql:postgresql:$postgresVersion "
45
46
46
47
implementation " com.google.inject:guice:$guiceVersion "
48
+ implementation " org.glassfish.hk2:guice-bridge:3.0.3"
49
+
50
+ compileOnly ' org.projectlombok:lombok:1.18.24'
51
+ annotationProcessor ' org.projectlombok:lombok:1.18.24'
47
52
48
53
compileOnly ' org.projectlombok:lombok:1.18.24'
49
54
annotationProcessor ' org.projectlombok:lombok:1.18.24'
Original file line number Diff line number Diff line change 1
1
package org .vss ;
2
2
3
+ import com .google .inject .Guice ;
4
+ import com .google .inject .Injector ;
5
+ import jakarta .inject .Inject ;
3
6
import jakarta .ws .rs .ApplicationPath ;
7
+ import org .glassfish .hk2 .api .ServiceLocator ;
4
8
import org .glassfish .jersey .server .ResourceConfig ;
9
+ import org .jvnet .hk2 .guice .bridge .api .GuiceBridge ;
10
+ import org .jvnet .hk2 .guice .bridge .api .GuiceIntoHK2Bridge ;
11
+ import org .vss .guice .BaseModule ;
5
12
6
13
@ ApplicationPath ("/" )
7
14
public class VSSApplication extends ResourceConfig {
8
- public VSSApplication () {
15
+
16
+ @ Inject
17
+ public VSSApplication (ServiceLocator serviceLocator ) {
18
+ packages ("org.vss" );
19
+ Injector injector = Guice .createInjector (new BaseModule ());
20
+ initGuiceIntoHK2Bridge (serviceLocator , injector );
21
+ }
22
+
23
+ // By default, Jersey framework uses HK2 for dependency injection.
24
+ // To use Guice as our dependency injection framework, we provide guice injector to hk2-bridge.
25
+ // So that hk2 can query guice injector for creating/injecting objects.
26
+ private void initGuiceIntoHK2Bridge (ServiceLocator serviceLocator , Injector injector ) {
27
+ GuiceBridge .getGuiceBridge ().initializeGuiceBridge (serviceLocator );
28
+ GuiceIntoHK2Bridge guiceBridge = serviceLocator .getService (GuiceIntoHK2Bridge .class );
29
+ guiceBridge .bridgeGuiceInjector (injector );
9
30
}
10
31
}
Original file line number Diff line number Diff line change
1
+ package org .vss .guice ;
2
+
3
+ import com .google .inject .AbstractModule ;
4
+ import com .google .inject .Singleton ;
5
+ import org .vss .KVStore ;
6
+ import org .vss .impl .postgres .PostgresBackendImpl ;
7
+
8
+ public class BaseModule extends AbstractModule {
9
+ @ Override
10
+ protected void configure () {
11
+ bind (KVStore .class ).to (PostgresBackendImpl .class ).in (Singleton .class );
12
+ }
13
+ }
You can’t perform that action at this time.
0 commit comments