C# 服务类应该引用其他服务类还是只引用其他存储库类?

C# 服务类应该引用其他服务类还是只引用其他存储库类?,c#,wcf,architecture,repository,C#,Wcf,Architecture,Repository,我有一个WCF服务类PersonService,它可以将个人及其地址信息保存到数据库中的个人和地址表中。 以下是实现的两个版本: 版本1(存储库版本) 版本2(服务版本) 哪一种做法更好?像PersonService这样的服务类应该与其同一层中的接口或较低层(如存储库层)耦合得更多吗?为什么?两个版本都是一样的。 接口名称不应暗示实现细节 PersonService类不关心谁在实现接口(存储库或服务),只要它得到一个实现接口的对象 最后,这就是为什么使用接口而不是直接使用实现它的类的原因 如果您

我有一个WCF服务类PersonService,它可以将个人及其地址信息保存到数据库中的个人和地址表中。
以下是实现的两个版本:

版本1(存储库版本)

版本2(服务版本)


哪一种做法更好?像PersonService这样的服务类应该与其同一层中的接口或较低层(如存储库层)耦合得更多吗?为什么?两个版本都是一样的。 接口名称不应暗示实现细节

PersonService类不关心谁在实现接口(存储库或服务),只要它得到一个实现接口的对象

最后,这就是为什么使用接口而不是直接使用实现它的类的原因


如果您正在指导如何进行依赖项注入,我将通过该服务,以防您在AddressService中进行缓存或其他处理。

我的意思是,IAddressService位于IadDressResistory层之上的一层,如果像PersonService这样的服务类与其同一层中的接口更多地耦合,还是较低的层,如存储库层?
    [ServiceContract]
    class PersonService
    {
        private IPersonRepository _personRepository;

        //by referencing other **repository**
        private IAddressRepository _addressRepository;

        private PersonService(IPersonRepository personRepository, IAddressRepository addressRepository)
        {
            _personRepository = personRepository;
            _addressRepository = addressRepository;
        }

        public void Add(Person person){
            _personRepository.Add(person);

            //by calling method from the **repository** layer
            if(!_addressRepository.Contains(person.Address))
            {
                _addressRepository.Add(person.Address);
            }
        }
    }
[ServiceContract]
    class PersonService
    {
        private IPersonRepository _personRepository;

        //by referencing other **service**;
        private IAddressService _addressService;

        private PersonService(IPersonRepository personRepository, IAddressService addressService)
        {
            _personRepository = personRepository;
            _addressService = addressService;
        }
        public void Add(Person person)
        {
            _personRepository.Add(person);

            //by calling method from the **service** layer
            if (!_addressService.Contains(person.Address))
            {
                _addressService.Add(person.Address);
            }
        }
    }