I want to create a “modules” layout in my web application so I can easily add more modules of the same type, for example:
As an example, my WebApp handles subscriptions and email campaigns, and I want to create an interface to allow easily coupling multiple API’s, MailChimp, CampaignMonitor, iContact, etc…
so I will create an IMailingService interface where I set up the ground rules and all modules will implement it like
public class CampaignMonitorService : IMailingService
So far so good…
How about fire the interface method upon an action on my webapp?
Should I implement the Observer Design Pattern, should I simple create event handlers, or any other hook?
for example, upon a user subscription I would like to fire the AddSubscriber method on the interface
AddSubscriber(string email, string[] args);
some thing as creating a list, unsubscribing, etc, etc…
What would be the best approach to handle such scenario?
Event handlers are how the Observer pattern is normally implemented in .NET. The pattern is a first class citizen of the .NET world, very much like how the Iterator pattern is built in (with
foreachandyield return).If you do want to use the pattern without events/event handlers, you can use the new
IObserver<T>andIObservable<T>(introduced in .NET 4.0).