Apllication structure:
Business layer
public interface IOrderDataService
{
void Save(Order order);
}
public interface IOrderLineDataService
{
void Save(OrderLine orderLine);
}
public class OrderManager
{
private IOrderDataService _OrderDataService;
private IOrderLineDataService _OrderLineDataService;
public void Create(Order order, List<OrderLine> lines)
{
_OrderDAtaService.Save(order);
foreach(var line In lines)
{
line.Id = order.Id;
// some other business logic
_OrderLineDataService(line);
}
}
}
Data layer implements "DataService" interefaces from the business layer
public class SqlOrderDataService : IOrderDataService
{
void Save(Order order) {};
}
public class SqlOrderLineDataService : IOrderLineDataService
{
void Save(OrderLine orderLine) {};
}
Now I want that creation of order will use SqlTransaction
for creating order and order lines. But..
If I wrap a method OrderManaget.Create
with SqlTransactionScope
- it will work, but then business layer will depend on sql database.
If I create a wrapper method which create both Order
and OrderLine
s. And use transaction there - it will work
public interface IOrderManagerDataService
{
void Save(OrderLine orderLine, OrderLine lines);
}
But in this case business logic will be in Sql implementation of data layer. Which violate a separation of concerns and I want keep it on business layer.
Do you have some advise for this problem?