-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How do you depend on another module from another JAR? #193
Comments
Yes, that is outdated, I need to update those docs. so including the javadoc we have: /**
* Used to explicitly specify if it depends on externally provided beans or provides.
*
* <h3>External dependencies</h3>
* <p>
* Use {@code requires} to specify dependencies that will be provided externally.
*
* <pre>{@code
*
* // tell the annotation processor Pump and Grinder are provided externally
* // otherwise it will think we have missing dependencies at compile time
*
* @InjectModule(requires = {Pump.class, Grinder.class})
*
* }</pre>
*
* <h3>Custom scope depending on another scope</h3>
* <p>
* When using custom scopes we can have the case where we desire one scope to depend
* on another. In this case we put the custom scope annotation in requires.
* <p>
* For example lets say we have a custom scope called {@code StoreComponent} and that
* depends on {@code QueueComponent} custom scope.
*
* <pre>{@code
*
* @Scope
* @InjectModule(requires = {QueueComponent.class})
* public @interface StoreComponent {
* }
*
*
* }</pre>
*/
public @interface InjectModule {
/**
* Explicitly specify the name of the module.
*/
String name() default "";
/**
* Explicitly define features that are provided by this module and required by other modules.
* <p>
* This is used to order wiring across multiple modules. Modules that provide dependencies
* should be wired before modules that require dependencies.
*/
Class<?>[] provides() default {};
/**
* The dependencies that are provided externally or by other modules and that are required
* when wiring this module.
* <p>
* This effectively tells the annotation processor that these types are expected to be
* provided and to not treat them as missing dependencies. If we don't do this the annotation
* processor thinks the dependency is missing and will error the compilation saying there is
* a missing dependency.
*/
Class<?>[] requires() default {};
/**
* Internal use only - identifies the custom scope annotation associated to this module.
* <p>
* When a module is generated for a custom scope this is set to link the module back to the
* custom scope annotation and support partial compilation.
*/
String customScopeType() default "";
}
Yes, so something like: @InjectModule(name="core", provides=CoreParent.class) and ... @InjectModule(name="gui", requires=CoreParent.class) avaje-inject uses ServiceLoader to find and load all the modules (gui, core and api) .. and orders those modules based on requires and provides. So should wire the |
A really really old example is at https://github.com/dinject/examples/tree/master/modular-coffee-app ... and I need to move that and update it. (the library used to be called "dinject") |
@rbygrave Okay, got it. That makes sense. Either way, appreciate the response. I'll follow what you have said then. |
Yes. That would not be fun.
Yes, I'm sure we can. I'll give that a go. What I'm pondering is:
So yes, I'll have a play around and see how that goes. |
…requires/provides This means that we don't need to reference each and every dependency in requires and instead can put one into requiresPackages such that any dependency in that package or a subpackage of that package is deemed to be supplied by another module.
With the referenced PR we have ended up adding a When a class is put into Note that I'll look to release this as version |
Moved the example project to: https://github.com/avaje/avaje-inject-examples/tree/main/modular-coffee-app |
Awesome, thank you so much for the quick turnaround with this feature, @rbygrave! |
Oh, it is available already as |
Let's say I'm depending on another JAR which is also using avaje-inject for dependency injection, is it possible to inject those classes in my module?
According to the "Module dependsOn" section, I can use the
dependsOn
attribute of the@InjectModule
annotation to achieve this (I think). However, it appears this was removed in an earlier commit. How can I go about this now?If an example is helpful, here's what I'm trying to do: I have a maven project with multiple submodules. There are three submodules -
gui
,api
, andcore
. Thegui
andapi
submodule each have their own main() method and they do not depend on each other, however, both of them ultimately make calls to classes in thecore
submodule.Here's the very simplified structure:
In the
core
submodule,CoreParent
injectsCoreChild
creating a very small dependency graph.Now in the
gui
submodule, I would likeParent
to injectChild
ANDCoreParent
(from thecore
submodule), andMain
sets everything up viaBeanScope
.Based on the docs, it appears I can use the
@Factory
and@Bean
annotations to constructCoreParent
within thegui
submodule, but I do not wish to initialize it manually.Is it possible to achieve what I'm trying to do? Hopefully my example is helpful, but let me know if I need to clarify anything. Thank you!
The text was updated successfully, but these errors were encountered: