Class MicronautFactory
java.lang.Object
io.micronaut.configuration.picocli.MicronautFactory
- All Implemented Interfaces:
AutoCloseable
,picocli.CommandLine.IFactory
An
ApplicationContext
-based implementation of the picocli IFactory
interface.
Specifying this factory when instantiating a CommandLine
or invoking the
CommandLine.run
or CommandLine.call
methods allows picocli to
leverage Micronaut dependency injection.
Closing this factory will close the underlying ApplicationContext
.
- Since:
- 1.0
- Author:
- Remko Popma
-
Constructor Summary
ConstructorDescriptionConstructs aMicronautFactory
with the result of callingApplicationContext.run("cli")
.MicronautFactory
(io.micronaut.context.ApplicationContext applicationContext) Constructs aMicronautFactory
with the specifiedApplicationContext
. -
Method Summary
-
Constructor Details
-
MicronautFactory
public MicronautFactory()Constructs aMicronautFactory
with the result of callingApplicationContext.run("cli")
. -
MicronautFactory
public MicronautFactory(io.micronaut.context.ApplicationContext applicationContext) Constructs aMicronautFactory
with the specifiedApplicationContext
.- Parameters:
applicationContext
- the context to use to look up or instantiate beans
-
-
Method Details
-
create
Delegates to theApplicationContext
to either find or instantiate a bean of the specified type.- Specified by:
create
in interfacepicocli.CommandLine.IFactory
- Type Parameters:
K
- the type of the bean to return- Parameters:
cls
- the class of the bean to return- Returns:
- an instance of the specified class
- Throws:
io.micronaut.context.exceptions.NoSuchBeanException
- if no bean of the specified type existsException
- if a problem occurred during lookup or instantiation
-
close
public void close()Closes the underlyingApplicationContext
.- Specified by:
close
in interfaceAutoCloseable
-