c# - Create a Notification Object (Email or Page) At Run Time -- Dependency Injection or Factory -



c# - Create a Notification Object (Email or Page) At Run Time -- Dependency Injection or Factory -

i have code emails me notification when happens. trying add together page , also remove dependency on email.

for reference; have name of notification want send stored string in database. @ runtime have list of people , string representation of want receive.

i thought dependency injection ninject, kernel bindings got big , seemed hacking together.

then thought simple factory, activator.createinstance(email/page) inotifcation, don't know how handle differing constructor parameters (unless utilize common, complex property, employee, has info need).

so far have this:

public interface inotification { void sendmessage(); } public class email: inotification { private readonly string _toemailaddress; private string body { { homecoming "email"; } } private static string smtphost { { homecoming configurationmanager.appsettings["smtphost"]; } } public email( string toemailaddress) { _toemailaddress = toemailaddress; } public void sendmessage() { var requestemail = new mailmessage { = new mailaddress(fromemailaddress, fromdisplayname), }; requestemail.to.add(new mailaddress(_toemailaddress)); var smtp = new smtpclient { host = smtphost }; smtp.send(requestemail); } } public class page : inotification { private string topagernumber; public page(string topagernumber) { topagernumber = topagernumber; } private static string ipaddress { { var host = new iphostentry(); homecoming host.addresslist.where(a => a.addressfamily == addressfamily.internetwork).tostring(); } } public void sendmessage() { var pageproxy = new pager(); var serviceresult = pageproxy.sendpage(topagernumber, "test", true, ipaddress); }

i appreciate feedback. sense have accomplished several times over, finding perfect solution (though contend there may not one) has proven onerous.

thanks everyone!

c# .net dependency-injection factory

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

Set Up Of Common Name Of SSL Certificate To Protect Plesk Panel -