public interface IOperationService { IEnumerable<OperationItem> GetItems(int operationId); } public class OperationService: IOperationService { public IEnumerable<OperationItemViewModel> GetItems(int operationId) { var items = getItems(operationId); //дальнейшие действия по преобразованию //OperationItem в OperationItemViewModel } private IEnumerable<OperationItem> getItems(int operatonId) { return _context.Set<OperationItem>().Where(x=>x.OperationId==OperationId) .Include(x=>x.File) .ToList(); } } Where
OperationItem- class of the domain model;OperationItemViewModel- view model
All this code is in my service layer.
I demanded to add a new IAssemblyService service in which currently there will be only one method: IEnumerable<AssemblyViewModel> GetAssemblies(int operationId) and the problem is that for this I need to get a list of the items included in the specified operation and for that I need access to getItems() method from the OperationService . I want to avoid duplication and leave the interface clean. Tell me how best to implement it?
UPD : you can try to do this:
public IEnumerable<AssemblyViewModel> GetAssemblies(int operationId) { var items = (OperationService)_operationService).getItems(operationId); //дальнейшие действия } but I'm not sure about this method
IOperationService.GetItems(...)is requested from the outside, so your newIAssemblyServicemust request them. - MonkgetItems&GetItemsreturn different collections: the first one returns DAO instances with navigation properties and other, and the second one is already displayed to the user - Bald