سؤال

I read that Repositories should not refer to other repositories. I have a method ProcessFile that refers to multiple repositories, it parses a file, and inserts into many table models in different databases.

If ProcessFile cannot be part of a repository, what should the containing class be called, or in other words, what layer should it belong to? ProcessFile Service, ProcessFile Business layer?

https://stackoverflow.com/questions/30118599/having-a-repository-dependent-on-another-repository

هل كانت مفيدة؟

المحلول

I would have the following structure

public class FileProcessor : IFileProcessor
{
    IDatabaseRepo repoDB;
    Func<string,IFileRepo> createFileRepo; //I want to use constructor injection for the filename so I need a factory

    public void ProcessFile(string filename)
    {
        IFileRepo repoFile = this.createFileRepo(filename);
        var data = repoFile.Read();
        repoDB.Write(data);
    }
}

You could call it a service if you like, but I think its best to avoid generic terms like 'service' 'manager' etc where possible. Even 'Processor' is a bit generic, you might consider 'Importer' or some other term that more closely matches what the business calls this process.

Its single responsibility is to transfer data from a File Repository to a Database Repository (or several DB repos if you require).

It can encapsulate the business logic of this process, so would regard it as being in the Business Logic Layer. We should use an interface to allow it to be replaced by alternative business logic if required at a later date.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى softwareengineering.stackexchange
scroll top