Assume an application with a layered architecture, i.e. presentation, business/domain/logic, data access: it makes sense to plug access to external APIs in at the data layer if what they do resembles data operations. For instance, a DLL that simply performs CRUD operations against a particular data repository would go in the data access layer.
What I'm a little confused about is where to incorporate actions that don't perform data operations in the strict sense, i.e. they perform operations that somewhat resemble "data" in a more-loose sense because they work on remote or networked resources. Here are a few examples:
- a web service that downloads a PDF of a SQL Server Reporting Services (SSRS) report.
- a library that sends email via SMTP or connects to a Microsoft Exchange mailbox and downloads messages in a folder structure
- direct interactions with the file system, such as writing to a log file, using built-in programming language functionality
I'm tempted to put these in the data layer since a lot of resources I've read indicate this. For instance, this MSDN article about "Data Layer Guidelines" has both "Data Sources" and "Services" hanging off the data layer, and it states about "Services":
When a business component must access data provided by an external service, you might need to implement code to manage the semantics of communicating with that particular service. Service agents implement data access components that isolate the varying requirements for calling services from your application, and may provide additional services such as caching, offline support, and basic mapping between the format of the data exposed by the service and the format your application requires.
However, this is talking about external services which are specifically performing data operations and makes no mention of the other types of somewhat-data-like operations like I have listed above.
The alternative is to put the them into the business or domain logic layer, but it doesn't feel right to be accessing external network or server resources like this from the business or domain logic layer.
Can someone please offer guidance or some of their experiences on this topic?