It’s a weird question I know 🙂
I really like to do the things in the right way and I have a doubt.
I know about making a interface, using DI…
My question is:
Is better to have a method like “SaveChanges” that you have to call manually everytime you add / delete / whatever an object?:
_repo.Add(blah);
_repo.SaveChanges();
Or is better to save changes inside every method that modify the data?
On the other hand, should I have the connection always opened or have I to close it?
Im learning DB4O and I have a Close method that I call when I have to use the repo on another place (Like in another windows, I close before I open the window).
Thank you.
I personally like the SaveChanges method to be separated. I think it allows for more flexibility in the consuming applications. Which means it can have more reuse.
For example, having it separate allows a ‘transaction’ approach where the repository can be continually modified and then if everything is acceptable the save method is called.
On the other side, if you want to save immediately without a separate call, you can create another version of the repository which calls the save method during CRUD operations.