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 {
3535 implementation " com.google.protobuf:protobuf-java:$protobufVersion "
3636
3737 implementation(' org.glassfish.jersey.containers:jersey-container-servlet:3.1.0' )
38+ implementation(' org.glassfish.jersey.inject:jersey-hk2:3.1.0' )
3839
3940 // jOOQ & Postgres impl deps
4041 implementation " org.jooq:jooq:$jooqVersion "
@@ -44,6 +45,10 @@ dependencies {
4445 jooqGenerator " org.postgresql:postgresql:$postgresVersion "
4546
4647 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'
4752
4853 compileOnly ' org.projectlombok:lombok:1.18.24'
4954 annotationProcessor ' org.projectlombok:lombok:1.18.24'
Original file line number Diff line number Diff line change 11package org .vss ;
22
3+ import com .google .inject .Guice ;
4+ import com .google .inject .Injector ;
5+ import jakarta .inject .Inject ;
36import jakarta .ws .rs .ApplicationPath ;
7+ import org .glassfish .hk2 .api .ServiceLocator ;
48import 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 ;
512
613@ ApplicationPath ("/" )
714public 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 );
930 }
1031}
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