use of keywhiz.inject.ContextModule in project keywhiz by square.
the class ServiceDataSourceModuleTest method injectsDataSources.
@Test
public void injectsDataSources() {
class Holder {
@Inject
ManagedDataSource readWrite;
@Inject
@Readonly
ManagedDataSource readonly;
}
Holder holder = new Holder();
ServiceContext context = ServiceContext.create();
Guice.createInjector(new ContextModule(context.getConfig(), context.getEnvironment()), new ServiceDataSourceModule()).injectMembers(holder);
assertNotNull(holder.readWrite);
assertNotNull(holder.readonly);
}
use of keywhiz.inject.ContextModule in project keywhiz by square.
the class ServiceModule method configure.
@Override
protected void configure() {
// Initialize the BouncyCastle security provider for cryptography support.
BouncyCastle.require();
bind(ClientCertificateFilter.class).toProvider(ClientCertificateFilter::new);
bind(Clock.class).toInstance(Clock.systemUTC());
bind(CookieConfig.class).annotatedWith(SessionCookie.class).toInstance(config.getSessionCookieConfig());
bind(SecurityHeadersFilter.class).toProvider(SecurityHeadersFilter::new);
bind(SessionMeResource.class).toProvider(SessionMeResource::new);
install(new ContextModule(config, environment));
install(new CookieModule(config.getCookieKey()));
install(new CryptoModule(config.getDerivationProviderClass(), config.getContentKeyStore()));
install(new DaoModule());
install(new StrictGuiceModule());
}
use of keywhiz.inject.ContextModule in project keywhiz by square.
the class ServiceDataSourceModuleTest method dataSourcesAreSingletons.
@Test
public void dataSourcesAreSingletons() {
class Holder {
@Inject
ManagedDataSource readWrite;
@Inject
@Readonly
ManagedDataSource readonly;
}
Holder holder1 = new Holder();
Holder holder2 = new Holder();
ServiceContext context = ServiceContext.create();
Injector injector = Guice.createInjector(new ContextModule(context.getConfig(), context.getEnvironment()), new ServiceDataSourceModule());
injector.injectMembers(holder1);
injector.injectMembers(holder2);
assertSame(holder1.readWrite, holder2.readWrite);
assertSame(holder1.readonly, holder2.readonly);
}
Aggregations