rory.ap
rory.ap

Reputation: 35318

Is running an external document part of the presentation layer?

I have an application that creates an MS Word document and runs it. I'm trying to figure out which layer to put that code in.

Would running the external document be part of the presentation layer or part of the business logic layer?

One the one hand, it seems like it should be part of the presentation layer since it ultimately results in something being "presented" to the user (albeit within an external application). On the other hand, it seems more like a business logic layer concern since the presentation layer might only want to be concerned with the current application's UI, and because all it's really doing when it comes down to it is running an external process -- something that could be used for multiple external processes which don't all have a "presentation" aspect to them.

Also, I'm not sure if SO is the right place for this question. I checked https://softwareengineering.stackexchange.com/ but there were only a handful of followers on those tags.

Upvotes: 0

Views: 151

Answers (1)

Maksym Strukov
Maksym Strukov

Reputation: 2689

It depends what you mean by "part of the presentation layer". If you mean actual implementation then it's definitely not. Yes, the result is an opened Word document but this has nothing to do with the presentation layer of your application.

  1. The actual implementation should go to the Infrastructure layer where should go all code to deal with databases, files and third party applications.
  2. You might have different implementation of the document generation logic. For example for console application it should just write a file to a folder, for a web application write a file to the response so it is then downloaded by a user, etc.
  3. As the actual logic is application specific it should be INJECTED on the application layer, if you don't have it presentation layer should be ok here as well.
  4. I assume you also want to make sure a document is always generated for a specific business case. Then you should pass the injected document generation service to your business layer. In this case if you want to move your business logic to a different application you will not forget to implement a new document generation logic if required.

So your code should be the following:

public class BusinessLayerService
{
    private IDocumentGenerator _documentGenerator;

    public BusinessLayerService(IDocumentGenerator documentGenerator)
    {
        _documentGenerator = documentGenerator;
    }

    public void DoBusinessCase1()
    {
        // Do work here
        _documentGenerator.GenerateDocument();
    }
}

If you use any IoC container just register the required implementation (for web, windows, mobil or console application) on your application starup.

Hope it helps!

Upvotes: 0

Related Questions