Представьте такой сценарий: у меня есть ServiceA, который вызывает свой репозиторий:
Код: Выделить всё
public class ServiceA : IServiceA
{
private readonly IRepositoryA _repositoryA;
public ServiceA(IRepositoryA repositoryA)
{
_repositoryA = repositoryA;
}
public async Task AddAsync(ObjADTO obj)
{
ObjA entity = obj.Map();
// business logic
await _repositoryA.AddAsync(entity);
}
}
Код: Выделить всё
internal class RepositoryA : IRepositoryA
{
public async Task AddAsync(ObjA obj)
{
// add to database
}
}
Следует ли мне использовать этот сервис (
Код: Выделить всё
ServiceAКод: Выделить всё
RepositoryA- Вызовите репозиторий напрямую:
Код: Выделить всё
public class ServiceB : IServiceB { private readonly IRepositoryA _repositoryA; public ServiceB(IRepositoryA repositoryA) { _repositoryA = repositoryA; } public async Task AddAsync(ObjBDTO obj) { // business logic await _repositoryA.AddAsync(entity); } } - Вызовите службу:
Код: Выделить всё
public class ServiceB : IServiceB { private readonly IServiceA _serviceA; public ServiceB(IServiceA serviceA) { _serviceA = serviceA; } public async Task AddAsync(ObjBDTO obj) { // business logic await _serviceA.AddAsync(entity); } }
Подробнее здесь: https://stackoverflow.com/questions/798 ... y-directly
Мобильная версия