@Component
@RequiredArgsConstructor
public class MaterialUnitMapper {
private final StockContainerRepository stockContainerRepository;
public MaterialUnit toEntity(MaterialUnitDTO dto) {
MaterialUnit unit = new MaterialUnit();
unit.setName(dto.getName());
StockContainer stockFromDb = stockContainerRepository.findById(
dto.getStockContainerId()
);
unit.setStockContainer(stockFromDb);
return unit;
}
}
Is it okay to hold repository inside mapper? I wonder wether repository should be accessable only from service layer.