S SOLID stands for SRP (Single Responsibility Principle). You will not violate it using System.IO.File inside the class directly, once you save this class with one responsibility.
This is a good idea trying to distract the purpose of using System.IO.File . Suppose you need this to create a log. Then you will probably do something like:
public interface IMyLogger { void GenerateLog(IEnumerable<string> content); } public class FileLogger: IMyLogger { public void GenerateLog(IEnumerable<string> content) { System.IO.File.WriteAllLines("C:/Log", content); } }
Perhaps this is not just a journal, it is something more important, for example, creating a file, so that another system / application (even an external one) reads it and does some work.
If you are trying to use the DDD approach, the interface may belong to your domain, and the implementation may belong to the application. Then you register your interface as a service and enter it.
For a class that needs IMyLogger , it does not need to know how the log is created, it just needs to complete the task.
You can apply the same idea when you need to send an email inside any business logic in your domain. Instead of connecting directly to Exchange inside your domain, create an INotifier and MailNotifier that implements it for input.
Alisson
source share