I've got a table which gets filled by another application. This table contains an attribute called IsMailSent.
EF builds my objects of Type Request based on the database data.
The object looks something like this:
public class Request {
int SomeInt;
bool IsMailSent;
SomeObject SomeObject;
}
Now I want to create a Service which will load all the entries with IsMailSent == false and send this mail to their recipients.
My current code works as follows:
A class called MailMessageService got a Start() and a Stop() method. The Start method looks like this:
public void Start(int delay) {
tokenSource = new CancellationTokenSource();
T = new Task(() => {
MailService ms = new MailService(Res.ServerAddress, int.Parse(Res.ServerPort));
while (true) {
var messages = GetMailMessages(_context.Requests.Where(o => !o.IsMailSent));
ms.Send(messages);
Thread.Sleep(delay);
}
}, tokenSource.Token);
}
The method GetMailMessages receives a Collection of Request and builds a Collection of MailMessages. Currently I created a class that inherits from MailMessage and contains a reference to the corresponding Request-object. The idea behind is that the MailService (which is responsible for sending the Mails) should set the IsMailSent property to true.
So the
Send()Method should setIsMailSent = true
But is this the best way to do it? As I understand the SOLID Principles, the MailService should not be responsible for setting this property (as it is responsible for sending the mails) - or am I wrong?