Pergunta

I have a desktop project in C# .NET that is structured in: gui, business and data access layers. Each business layer class represent an entity of the database. I am using linq to access the database. But the the way the project is implemented today does not allow to make many operations atomically, and i need this to be done in business layer.

I searched to some design patterns and found unitOfWork that makes all operation in data layer in the same context and after all the changes are submitted. This would work to make the operations atomic. But the problem is that the operations I want to do need to be validated before, that means, instead of calling a method from data layer i need to call a method from business layer to be validated before. This call in the business layer would create another unitOfWork and, consequently, create another context breaking the atomicity of the bigger operation I am trying to do.

The question is: What the best project pattern to call one or more methods of the business layer from the business layer in the same linq context?

Foi útil?

Solução

One way of doing it would be:

  • Create a service layer on top of your business layer.
  • This service layer consists of 2 services (can be real WCF services or just regular C# classes) : one for reading and one for writing.
  • The reading service is not transactional, it contains only methods that perform queries (i.e., read data).
  • The writing service is transactional; all its methods either create a transaction context or follow the unit of work pattern.
  • The writing service accesses the reading service for validation prior to executing C/U/D operations on its business layer.
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top