All of the enterprise projects I work on seem to follow the same pattern.
- A request is issued to the server (from a client or Api)
- The server side loads some data from a database
- Modifies the data in some way
- Commits the changes to the database
//Client after user click cancel on the order screen _apiClient.Execute(new CancelOrder(_orderId)) ; //On server in CancelOrderHandler var order =_db.Orders.Single(o => o.Id == command.OrderId); order.Cancel(); _db.Orders.Update(order); _db.CommitTransaction(); _db.SaveChanges();
This is pretty simple and easy to understand, but given this method (pattern?) is used everywhere I wonder if we are doing something wrong in some cases?
In this case could you consider the database to effectively be global state? Given 2 clients could access the same data at the same time?although they would have different instances.
Are there better ways to handle a command and commit some action because of it? Or is loading the latest domain object from a database, changing it and committing the changes always the way to go?