Your unit of work must exist at your service level. Each service call contains a business transaction within one unit of work.
public ServiceResponse<Patient> Save(Patient patient, string userName)
{
Func<Patient> func = delegate
{
Authorize(patient, userName);
Validate(patient, new PatientValidator());
using (var context = _contextFactory())
{
return context.Save(patient, userName);
}
};
return this.Execute(func);
}
The service level should return your business entities, any mapping for network communication / json formatting should be done in the web api. This allows you to make the most of your services.
DTO , wire/json, , Web Api. , . Web Api, , FluentValidation.
https://github.com/carbonrobot/FullStackEF #, EF, Web Api