I have the following interface
public interface ISender
{
void SendMessage(string msg);
}
along with the following implementation
public class EmailSender : ISender
{
private EmailSettings _emailSettings;
EmailSender(EmailSettings _emailSettings)
public SendMessage(string msg);
}
public class EventLogSender : ISender
{
void SendMessage(string msg);
}
public class QuerySetting
{
string statementToExecute;
int MStoWaitBeforeExecute;
// if set to true then use email settings to perform notification through email
bool UseEmail;
EmailSettings EmailSettings;
}
public class EmailSettings
{
string serverip;
int port;
string username;
string password;
string MailToAddress;
}
At runtime, a list of queries are loaded into the application. Each query contains information about how often to execute the query, information about when to fire an alarm for the query, and email information on who to email when an alarm occurs( or if not set, the alarm should just write to the event log ). How do i use dependency injection, at runtime, to know what instanation of ISender to create ( EmailSender or EventLogSender ) and also to new up the appropriate email settings for the query if they opted to use email notification instead of eventlog notification? **NOTE: Querys can have different notification methods, 1 can be evenlog notifications, while the others could be all email only.