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?


  • "FileProcessor" ? – Ewan Aug 18 '18 at 8:50
  • I took the freedom and tried to make your question understandable to the world. Please proofread if I got your intentions right. Still no guarantee it won't be closed as "too opinionated". – Doc Brown Aug 18 '18 at 8:56

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();

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.