This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hello, Consider an entity with numerous relationships, including security, preferences and those lovely things. When the entity is created for the very first time, default values need to be populated. In principal something similar to this
However doing so by overriding the OnSaving method of the entity doesn't work, nothing gets added. Since I'm working against a IUnitOfWork to improve the reuse of the entity across projects, doing so in the SaveChanges method of an IUnitOfWork is less than ideal. Thanks, Werner |
|
|
OnSaving is fired when we are actually in the process of saving the entity, so this is too late to commit any further changes to the UnitOfWork as we have already built up the change-set. If you called SaveChanges twice I suspect this would work. I will have a look at adding in a new event which is hooked earlier in the lifecycle which would allow you the control you are looking for here - this does seem like a reasonable scenario. Hopefully I should have this in tomorrow for you, will keep you posted.
|
|
|
I have added a new event on Entity called Enlisted which will be fired for every entity in the UnitOfWork when SaveChanges is called, so this will allow you to perform any pre-save logic as were hoping to do in the saving event. As this fires just before we decide what entities to persist you can make further modifications to the UnitOfWork at this point. To use this you will need to grab the next nightly build and then set the following compatibility flag to enable the functionality - e.g.
You can then wire up to the event - e.g.
I would be keen to get your feedback to understand if this caters appropriately for your scenario before I look at making this more generally available.
|
|
|
Thanks Jeremy. It seems to work for my original problem. Feedback
Background: Consider a solution with several applications that use a single data access assembly. The applications may have their own entities which may extend entities in the data access assembly. The data access assembly contains entities common to many applications, including entities related to security and auditing which uses features described in posts LightSpeed and Generics and Injecting expressions into UnitOfWork Query. Lets consider entities that require security. In the data access assembly an interface ISecurable is defined that has the following:
For any entity that requires security, the following additional logic is required.
I have other interfaces to represent a wealth of requirements:
The challenge is to handle these requirements transparently while minimizing configuration, boilerplate code and minimizing dependent code scattered across classes, projects and configuration. The feature "Injecting expressions into UnitOfWork Query" has helped a great deal to reuse queries. I'd like to see LightSpeed expand that feature to inject logic when entities that implement an interface are being created, updated and deleted. |
|