I have an entity type which, when loaded from the db (or indeed any time they are created) need to have an additional class placed into them, a class chosen based on the content of a property of the entity (corresponding to a column in the database).
My thought was that the new
afterMarshal event would be a good trigger for the examination process and the dependency injection. But I can’t seem to confirm that this actually runs as part of the process of querying the db and creating entities.
It may be that I have some detail wrong in my event set-up. Or it may be that the
patchEntity() method is not used to convert the fetched data into entities. (
newEntity() are the methods that trigger the
Does anyone know for sure that
patchEntity() is or is not used to produce entities from query data?
As an alternative I think I might be able to use the entity constructor to do my injection after the parent constructor has populated the entity object.
This is not my first choice because it will make the entity classes heavier and it just doesn’t feel right.
Though I guess I could trigger my own event in the constructor. This would give me the opportunity to put the required code out in a nice DRY class outside the entities. (This one has promise).
There is of course the map/reduce process that can be added to the queries. This isn’t very attractive though because I need the extra classes inserted into the entities ALWAYS, even when they are contained in another entity.
With this requirement, insuring I get the mapper/reducers added in every case and getting them written to do the job where ever my entities appear in the query result structure is not an attractive prospect.