Open NuckNuck opened 6 years ago
I thought about this use case. But didn't came up with a good reason. Why can you not do it in one go, where you register your properties?
Hi, I develop persistence layers with your beautiful RTTR lib. For this I use the reflection info to map objects to tables or json structs. Currently I have to insert persistence metainfos like "ColumnName", "ColumnType",... during the type registration. But I should't known during the type registration, which type of persistence layer will be used.
My workaround is, to register ALL persistence metainfos during the type registration. To separate the different persistence infos a naming convention is used:
...
.add_metainfo("SQL::ColumnName", "id")
.add_metainfo("SQL::IsPrimaryKey", true)
.add_metainfo("JSON::Key", "id");
...
If it would be possible to add metainfos after the registration, my different persistence layer libs can add metainfos from config files at runtime. This would be great.
Thanks for your great and intuitive library, Bastian
The question is, how do you know where to add the metadata (i.e. to which property?) Do you not repeat yourself again?
The drawback of this feature would be, I would need to make the setter and getter thread safe for the meta data. Because it would be possible to set the data from multiple threads.
It seems to be that you can do what you want (no blocker), but you would like to have some logical separation.
The question is, how do you know where to add the metadata (i.e. to which property?) Do you not repeat yourself again?
My plan is to use an UI to define the persistence metadata. The UI should load all the registered types, properties and provide the possibility to add metadata.
The UI should store the metadata in an JSON file which my application can load and add the loaded metadata.
{
"Class 1": {
"IsPersistent": true,
"Property 1": {
"IsPersistent": true,
"MySQL::ColumnName": "property1",
"MySQL::Datatype": "Varchar",
"MySQL::Size": 100
}
}
}
rttr::type::get_by_name("Class 1").get_property("Property 1").add_metainfo("MySQL::ColumnName", "property1");
I hope this explains my use case a bit better.
The drawback of this feature would be, I would need to make the setter and getter thread safe for the meta data. Because it would be possible to set the data from multiple threads.
Sure...this is a drawback. But this would be a very powerful feature.
Hi,
is it possible to add additional metadata after a type is registered? This would be great. Here is my use case:
Base registration for Model:
In an other library I want to add some persistence infos. Pseudo code:
Currently I add this infos during the initial type registration. But this is not nice ;-)
Greetings Bastian