|
You can call to Repositories from the Domain-Model Layer (from Domain-Services, and only for queries, usually), there's no problem about that.
Why would yo need to add a reference to the Infrastructure-Persistence Layer from the Domain Layer?. You shouldn't do that.
Take into account that if you are using DI (Dependency Injection), the only reference you will have is to the Repositories' Contracts/Interfaces. And those Repositories' interfaces are already within the Domain-Model Layer. Therefore, you don't need
to add any reference to the Infrastructure-Persistence Layer (And you shouldn't even if you could, the Domain-Model Layer must be isolated from the Infrastructure Layers). So, NO CIRCULAR DEPENDENCY!! :-)
The procedure is easy, just add the Repository contract/interface to the Domain-Service constructor. Then, the IoC container will inject the Repository object for you, like any other object in the constructor.
Here you have a simple test:
... //using to Repositories' Interfaces/Contracts within the Domain
using Microsoft.Samples.NLayerApp.Domain.MainBoundedContext.ERPModule.Aggregates.CustomerAgg;
...
public class SimpleDomainService : ISimpleDomainService { readonly ICustomerRepository _customerRepository; public SimpleDomainService(ICustomerRepository customerRepository) { if (customerRepository == null) throw new ArgumentNullException("customerRepository"); _customerRepository = customerRepository; } public void CallingRepository(Guid customerId) { //(CDLTLL - Repository Test) var associatedCustomer = _customerRepository.Get(customerId);
//(Other Domain-Logic)... } }
Of course, you need to add the mapping into the UNITY container, too:
Container.cs (WCF Project)
_currentContainer.RegisterType<ISimpleDomainService, SimpleDomainService>();
But, usually I would use Repositories within the Domain-Model Layer,
only for querying (if you need to do different actions depending on querys' values, etc.).
On the other hand, all the Transactions and UoW usage should be within the Application Layer, like in our BankTransfer example.
Cheers,
Cesar.
|