use of jakarta.inject.Singleton in project micronaut-views by micronaut-projects.
the class ThymeleafFactory method templateEngine.
/**
* Constructs the template engine.
*
* @param templateResolver The template resolver
* @param engineContextFactory The engine context factory
* @param linkBuilder The link builder
* @param messageSourceMessageResolver The message resolver
* @return The template engine
*/
@Singleton
public TemplateEngine templateEngine(ITemplateResolver templateResolver, IEngineContextFactory engineContextFactory, ILinkBuilder linkBuilder, MessageSourceMessageResolver messageSourceMessageResolver) {
TemplateEngine engine = new TemplateEngine();
engine.setEngineContextFactory(engineContextFactory);
engine.setLinkBuilder(linkBuilder);
engine.setTemplateResolver(templateResolver);
engine.addDialect(new Java8TimeDialect());
engine.addMessageResolver(messageSourceMessageResolver);
return engine;
}
use of jakarta.inject.Singleton in project micronaut-graphql by micronaut-projects.
the class GraphQLFactory method graphQL.
@Bean
@Singleton
public GraphQL graphQL(ResourceResolver resourceResolver, HelloDataFetcher helloDataFetcher) {
// <2>
SchemaParser schemaParser = new SchemaParser();
SchemaGenerator schemaGenerator = new SchemaGenerator();
// Parse the schema.
TypeDefinitionRegistry typeRegistry = new TypeDefinitionRegistry();
typeRegistry.merge(schemaParser.parse(new BufferedReader(new InputStreamReader(resourceResolver.getResourceAsStream("classpath:schema.graphqls").get()))));
// Create the runtime wiring.
RuntimeWiring runtimeWiring = RuntimeWiring.newRuntimeWiring().type("Query", typeWiring -> typeWiring.dataFetcher("hello", helloDataFetcher)).build();
// Create the executable schema.
GraphQLSchema graphQLSchema = schemaGenerator.makeExecutableSchema(typeRegistry, runtimeWiring);
// Return the GraphQL bean.
return GraphQL.newGraphQL(graphQLSchema).build();
}
use of jakarta.inject.Singleton in project core by weld.
the class GetContextUtilMethodsTest method getActiveContextsTest.
@Test
public void getActiveContextsTest() {
try (WeldContainer container = new Weld().initialize()) {
// TheLoneBean is just to have some bean in the archive
container.select(TheLoneBean.class).get().ping();
WeldManager manager = container.select(WeldManager.class).get();
// there are 7 scopes by default in SE, only 3 have active contexts by default
// it is dependent, singleton and application
Collection<Context> activeContexts = manager.getActiveContexts();
Assert.assertEquals(3, activeContexts.size());
Set<Class<? extends Annotation>> scopes = activeContexts.stream().map(t -> t.getScope()).collect(Collectors.toSet());
Assert.assertTrue(scopes.contains(Dependent.class));
Assert.assertTrue(scopes.contains(Singleton.class));
Assert.assertTrue(scopes.contains(ApplicationScoped.class));
}
}
use of jakarta.inject.Singleton in project micronaut-kafka by micronaut-projects.
the class OptimizationStream method optimizationOn.
@Singleton
@Named(STREAM_OPTIMIZATION_ON)
KStream<String, String> optimizationOn(@Named(STREAM_OPTIMIZATION_ON) ConfiguredStreamBuilder builder) {
// set default serdes
Properties props = builder.getConfiguration();
props.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.String().getClass().getName());
props.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, Serdes.String().getClass().getName());
props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
KTable<String, String> table = builder.table(OPTIMIZATION_ON_INPUT, Materialized.as(OPTIMIZATION_ON_STORE));
return table.toStream();
}
use of jakarta.inject.Singleton in project micronaut-gcp by micronaut-projects.
the class GoogleCredentialsFactory method defaultGoogleCredentials.
/**
* Method used to return the default {@link GoogleCredentials} and provide it as a bean.
*
* It will determine which credential in the following way:
* <ol>
* <li>If <pre>gcp.credentials.location</pre> is specified, use its location</li>
* <li>Otherwise, if <pre>gcp.credentials.encodedKey</pre> is specified, decode it and use its content</li>
* <li>None of the 2 properties were specified, use Application Default credential resolution. See
* <a href="https://github.com/googleapis/google-cloud-java#authentication">Google Cloud Java authentication</a>.
* This will resolve credential in the following order:
* <ol>
* <li>The credentials file pointed to by the <pre>GOOGLE_APPLICATION_CREDENTIALS</pre> environment variable</li>
* <li>Credentials provided by the Google Cloud SDK <pre>gcloud auth application-default login</pre> command</li>
* <li>Google App Engine built-in credentials when running inside of Google App Engine</li>
* <li>Google Cloud Shell built-in credentials when running inside of Google Cloud Shell</li>
* <li>Google Compute Engine built-in credentials when running inside of Google Compute Engine or Kubernetes Engine</li>
* </ol>
* </li>
* </ol>
*
* @return The {@link GoogleCredentials}
* @throws IOException An exception if an error occurs
*/
@Requires(missingBeans = GoogleCredentials.class)
@Requires(classes = com.google.auth.oauth2.GoogleCredentials.class)
@Primary
@Singleton
protected GoogleCredentials defaultGoogleCredentials() throws IOException {
final List<String> scopes = configuration.getScopes().stream().map(URI::toString).collect(Collectors.toList());
GoogleCredentials credentials;
if (configuration.getLocation().isPresent() && configuration.getEncodedKey().isPresent()) {
throw new ConfigurationException("Please specify only one of gcp.credentials.location or gcp.credentials.encodedKey");
} else if (configuration.getLocation().isPresent()) {
LOG.info("Google Credentials from gcp.credentials.location = " + configuration.getLocation());
FileInputStream fis = new FileInputStream(configuration.getLocation().get());
credentials = GoogleCredentials.fromStream(fis);
fis.close();
} else if (configuration.getEncodedKey().isPresent()) {
LOG.info("Google Credentials from gcp.credentials.encodedKey");
Base64.Decoder decoder = Base64.getDecoder();
byte[] bytes = decoder.decode(configuration.getEncodedKey().get());
ByteArrayInputStream is = new ByteArrayInputStream(bytes);
credentials = GoogleCredentials.fromStream(is);
is.close();
} else {
LOG.info("Google Credentials from Application Default Credentials");
credentials = GoogleCredentials.getApplicationDefault();
}
return credentials.createScoped(scopes);
}
Aggregations