Replies: 3 comments
-
Can you describe it a bit more? you don't need to know the classes. Just the packages so that might help. The goal for 3.0 is to do all the mapping work as part of the build and generate codecs so there's very little reflection at runtime. So a purely dynamic scenario starts to get tricky but there are options to consider while those details are getting worked. So I'd love to know bit more about how your setup works so I can do my best to not break it. |
Beta Was this translation helpful? Give feedback.
-
(I'm on my phone now so if something isn't clear I'll edit it tomorrow when I'll be on a computer 😅) We're working with a main project named "core" that group all the specific methods (like connecting to a database, rabbitmq etc.). These classes are then provided via dependency injection to any other class that needs to do something. A small example of this class using morphia: // Morphia imports
@Provides
public final class MongoService {
private Datastore datastore;
public void initialize() {
// ...
}
public void registerClass(Class<?> clazz) {
this.datastore.getMapper().map(clazz);
}
public <T> T get(Class<T> tClass, Object id) {
// ...
}
}
=====
import core.MongoService;
// No need to import any morphia classes here, we can even don't add it's dependency
public class AClassSomewhere {
@Inject
private static MongoService mongoService;
public void start() {
mongoService.registerClass(Z.class);
Z z = mongoService.get(Z.class, "someid");
}
} The "core" library is just a library that we use in many places. There is no way for it to know any class, and even any package, that we will use. |
Beta Was this translation helpful? Give feedback.
-
Just a note because you probably didn't see it, but based on feedback this transition to file based configs is getting a rethink. Ultimately, I think we'll end up with support for both since programmatic configuration turned out to be a much more important feature than anticipated. The API will like likely center around a new class for various reasons but in the end, programmatic config is almost certainly here to stay. |
Beta Was this translation helpful? Give feedback.
-
I've seen that starting with 2.4.0, the configuration and mappings should be done via a configuration file.
Due to the structure of my project, I can't have a static configuration for mappings, as the load of Morphia is done by a separate library that provides "wrapper" methods to the other parts of my application. The issue is that the part that does the loading does not know which classes will be used, so I can't even generate the config file at the app's start.
Will there still be a way to register mapped classes at runtime or add new configurations to the already loaded ones?
Beta Was this translation helpful? Give feedback.
All reactions