![]() In DDD, you'd have a repository for each aggregate. However, often times this creation process is done with reflection and doesn't go through a factory to prevent initialization that should only occur at creation time.Īt this time I have 2 repositories, one for Folder and another forįile, but it seems to me I should merge them together. Upon reconstitution, the repository will effectively create instances. So my first question is should I use a factory to create this aggregateĪ factory is responsible for creation while a repository is responsible for persistence. Or should the service just use a factory, which have the responsibility of creating the object and send the created object to the repository? What about dependency injection in the service, should I inject my services from the UI layer with IOC containers like Unity or should I just hardcode the dependencies in the service? ![]() Should I use the service for creating the folder object. ![]() Public void AddFile(UserReference userReference, Folder folder, FileData data, string name, string title = "", IEnumerable keywords = null, bool shared = false)įile.Keywords = keywords.Select(keyword => _folderRepository.InsertOrUpdate(folder) UserReferenceList.AddRange(userIds.Select(id => _userReferenceRepository.Find(id))) įolder.Keywords = keywords.Select(keyword => Public void AddFolder(UserReference userReference, string name, Folder parentFolder = null, IList userIds = null, IEnumerable keywords = null, bool share = false) / The given users represent who have access to the folder _userReferenceRepository = userReferenceRepository Throw new NullReferenceException("userReferenceRepository") Throw new NullReferenceException("fileRepository") Throw new NullReferenceException("folderRepository") Public IoService(IFolderRepository folderRepository, IFileRepository fileRepository, IUserReferenceRepository userReferenceRepository) Private readonly IUserReferenceRepository _userReferenceRepository Private readonly IFileRepository _fileRepository Private readonly IFolderRepository _folderRepository Should it be moved to the domain layer? public class IoService : IIoService I have my doubts about the location of the service. Next I have created a service in my application layer, this is called "IoService". Public int AmountOfFilesIncluded(Folder folder) Public void InsertOrUpdate(Folder entity) _context = _unitOfWork.Context as IFolderContext Public FolderRepository(IUnitOfWork unitOfWork) Private readonly IUnitOfWork _unitOfWork Private readonly IFolderContext _context The following code snippet, shows my Folder Repository, which is located in my infrastructure layer: public class FolderRepository : IFolderRepository So my first question is should I use a factory to create this aggreate or is it up to the repository? At this time I have 2 repositories, one for Folder and another for File, but it seems to me I should merge them together. In my opinion the "Folder" is an aggregate root and should have the responsibility of creating the File and FileData object. I have the following entities: Folder, file, FileData. I have some questions regarding factories, repositories and services in DDD.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |