Inject extension into newly generated object [message #1832117] |
Wed, 09 September 2020 07:34  |
Eclipse User |
|
|
|
I want to augment my DSL framework to proved a factory for specific types that I want to be created.
To do this I configued a FactoryModuleBuilder in the runtime module like so:
class MyDslRuntimeModule extends AbstractMyDslRuntimeModule {
def configureMyDslFactory(Binder binder) {
binder.install(new FactoryModuleBuilder()
.build(IMyClassFactory)
)
}
}
The class that gets built in this example is declared like so, which is also using
the IQualifiedNameProvider as an extension that should be injected.
class MyClass {
@Inject extension IQualifiedNameProvider
String fqn
@Inject
new(@Assisted MyDslSymbol symbol) {
// at this point there is a problem later, because
// IQualifiedNameProvider does not get injected (_iQualifiedNameProvider remains "null"),
// so the method "fullyQualifiedName" generates a NullPointerException
this.fqn = symbol.fullyQualifiedName.toString(".")
}
}
The factory-interface to be used for the module-installation is defined like this:
interface IMyClassFactory {
def MyClass create(MyDslSymbol symbol)
}
In the end I would like use the factory e.g. in a validation method like so:
class MyDslValidator extends AbstractMyDslValidator {
@Inject IMyClassFactory factory
@Check
def void checkSymbol(MyDslSymbol symbol) {
val myClass = factory.create(symbol)
}
}
Now I'm encountering a huge problem upon creating objects with the factory:
When the MyClass object gets created by the factory,
the guice-injector does not inject the extensions as specified, but they remain null.
How can I make the default injector be used for the classes created by the factory configured by configureMyDslFactory?
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02798 seconds