I am using NHibernate, DI / IoC and the work pattern.
In most UoW examples I've seen, make sure that there can only be one active UoW / session at a time, for example this and this .
Unfortunately, I still do not quite understand how I should handle two services that use UoW, but one calls the other.
Take this example:
Logger that uses UoW:
public class LoggerService : ILoggerService
{
private ILoggerRepository repo;
public LoggerService(ILoggerRepository Repo)
{
this.repo = Repo;
}
public void WriteLog(string message)
{
using (UnitOfWork.Start())
{
}
}
}
... and another service that also uses UoW AND calls the log:
public class PlaceOrderService : IPlaceOrderService
{
private IOrderRepository repo;
private ILoggerService service;
public PlaceOrderService(IOrderRepository Repo, ILoggerService Service)
{
this.repo = Repo;
this.service = Service;
}
public int PlaceOrder(int orderNumber)
{
using (UnitOfWork.Start())
{
this.service.WriteLog("Order placed!");
}
}
}
UoW , UoW ( , , ), this.service.WriteLog PlaceOrder:
UoW, PlaceOrder, WriteLog , UoW - .
, ?
, - "" .
UoW LoggerService, , .
, . using (UnitOfWork.Start()) LoggerService , LoggerService .
, , LoggerService , UoW, LoggerService , .
, UoW.Start() :
) UoW,
) UoW,
LoggerService AND , , UoW .
.
( . , PlaceSpecialOrderService, , PlaceOrderService.PlaceOrder()...)
?
!
EDIT:
.
, , .
, .
, .
, , PlaceSpecialOrderService, .
, , UoW - , :
, , , , , , , .
, , - (: , , , ).
( UoW ) ?
UoW ?