像这样将存储库接口注入实体对象是否违反了持久性知识。通过不使用界面,我清楚地看到了问题,但是使用界面时真的有问题吗?下面的代码是好的还是坏的模式,为什么?
public class Contact
{
private readonly IAddressRepository _addressRepository;
public Contact(IAddressRepository addressRepository)
{
_addressRepository = addressRepository;
}
private IEnumerable<Address> _addressBook;
public IEnumerable<Address> AddressBook
{
get
{
if(_addressBook == null)
{
_addressBook = _addressRepository.GetAddresses(this.Id);
}
return _addressBook;
}
}
}