I have a DAL to CRUD product data.
For example:
Order someOrder = new Order();
someOrder.Description = "Test";
someOrder.Save();
someOrder.Remove();
I need to design the DAL so that only users who have a lock on an Order type object can carry out CRUD operations.
My idea is to pass the session to the CRUD methods. Once I pass the session, the method will check whether that user has a lock on that specific object, and if yes, it will carry proceed with executing that method.
For example:
someOrder.Save(sessionThatContainsLockInformation);
// Pseudo-code
public void Save(Session session)
{
1. Get user GUID from the session.
2. Get lock details from the session.
3. Check that the provided user has a lock.
4. On success, proceed with saving the order.
}
I’m concerned with the fact that I’m using Sessions in the data access layer. My intuition tells me that I shouldn’t be doing this. My goal is to write as little code as possible to promote the re-usability of code, but I seem to be stuck with the same ideas.
Can somebody please advise me on whether this is a sensible approach, or whether it has some fundamental disadvantages or maintenance overheads?
Any alternative solutions are welcome. I’m not interested in the code, just some ideas please.
Thank you
Ok, thanks for your clarification, I think I understand your concerns now more clearly.
I faced a similar issue some time ago. My solution was a common superclass (in your classes it would be a superclass for Order, Item, Customer) with all parameters that are the same (timestamp changed, who did the change etc). I then created a utility class where all the checks you mention were taken care of.
So this “maintenance” logic is implemented in one place only.
I am not saying this is the best way to do it, it’s just something that worked for me…
Hope this helps,
Jan