Multi-Module ProjectsMulti-module projects are the place where Jeta shows the best. You can share metacode between modules, override behavior, substitute classes and many more. It also should be important for any project, since projects are frequently composed of at least couple of modules - main and test. And the helper methods can be used in any of these modules. As mentioned in Dependency Injection article, you are allowed to extend injection providers. To make that possible, you must create one metacode-base for all your modules. In this tutorial, we will stick to the approach that we used in the previous guides - MetaHelper, which holds singleton instance of the metasitory. To be able to add metacode from one module into another, e.g. from test to main one, metasitory provides a method for:
Nevertheless,
The only thing we need to do is to pass our test package name into this method during initialization, something like:
DI ScopesLet’s go through an example, in which we need to substitute an entity that’s injected in the main module. As it’s described in Dependency Injection guide, we must create a scope and provider that extends corresponding classes from the main module. With created scope you can provide different entities for old dependencies. There’s one problem though - how to replace the scope with the test one? We can use
Here, the implementation is provided by itself. In MetaHelper instead of creating
Finally, in a test module we set a test scope as the implementation of the main scope but with higher priority:
After the test metacode is added into the main metasitory, the main injection scope will be replaced with the test one. |
How it works:User's Guide:
AndrojetaAdvanced
|