public static void Process() { Publisher publisher = new Publisher(); SubscriberAAA subscriberAAA = new SubscriberAAA(); SubscriberBBB subscriberBBB = new SubscriberBBB(); SubscriberCCC subscriberCCC = new SubscriberCCC(); SubscriberDDD subscriberDDD = new SubscriberDDD(); publisher.SubcriberHandler += subscriberAAA.OnSubcriberHandler; publisher.SubcriberHandler += subscriberBBB.OnSubcriberHandler; publisher.SubcriberHandler += subscriberCCC.OnSubcriberHandler; publisher.SubcriberHandler += subscriberDDD.OnSubcriberHandler; Console.WriteLine("Client:: Call Publisher.Process()..."); CreditApplication myCreditApplication = new CreditApplication() { CreditId = 1, FirstName = "John", LastName = "Rimes", CreditScore = 1002 }; publisher.Process(myCreditApplication); Console.WriteLine("Client:: Call Publisher.Process() done."); }
public void Process(CreditApplication creditApplication) { Console.WriteLine("Publisher:: Process()..."); Thread.Sleep(5000); Console.WriteLine("Publisher:: Process() done."); OnEventCompleted(creditApplication); }
// notify the subscribers that the event has been raised (which will call-back to the subscriber) protected virtual void OnEventCompleted(CreditApplication creditApplication) { if (SubcriberHandler != null) { Console.WriteLine("Publisher::OnEventCompleted()"); SubcriberHandler(this, new PublisherEventArgs() { MyCreditApplications = creditApplication }); } }