Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 142745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:59:08+00:00 2026-05-11T07:59:08+00:00

I would like to provide a deafult implementation for an event generated by an

  • 0

I would like to provide a deafult implementation for an event generated by an instance of “Authenticator” (hereafter “objAuthenticator”).

Is this an acceptable practice to provide such method that registers for handling objAuthenticator’s own event to provide a deafult implementation?

And also, if it is an acceptable pratice, I have two follow-up questions. I have two overloaded methods for “SendEmailOnAuthenticationFailed”.

  • Which one should I expose to the outside world?
  • Which one would cause less coupling between classes?

    public class Authenticator {         public event EventHandler AuthenticationFailed = delegate { };         protected virtual void OnAuthenticationFailed()         {             var handler = AuthenticationFailed;             handler(this, EventArgs.Empty);         }          public void IsAuthenticated()         {             // Some logic...             // ...             // Woops authentication failed             OnAuthenticationFailed();         }           // Is this a better option?         public void SendEmailOnAuthenticationFailed()         {             SendEmailOnAuthenticationFailed(EmailSender);         }          // Or is this?         public void SendEmailOnAuthenticationFailed(EventHandler emailSender)         {             AuthenticationFailed += emailSender;         }          private void EmailSender(object sender, EventArgs e)         {             Console.WriteLine('Send email: EmailSender');         }     } 

[UPDATE]: Answer to Marc Gravell’s question

I’m very confused about what your code is trying to do

So far, ‘SendEmailOnAuthenticationFailed’ is not exposed to the outside world. What I am trying to do is that (I just added IsAuthenticated) within ‘IsAuthenticated’, when an authentication fails, I would like to send an email without having to write the same event handler everywhere.

[UPDATE2]: I have realized that there is no need to expose ‘AuthenticationFailed’. I will keep the class as closed as possible without exposing the event.

Why can’t we mark more than one answers as ‘answer’? …

[UPDATE3]: Final output: Here is the how I decided to implement.

public class Authenticator {     private readonly IEmailResponder _EmailResponder;      public Authenticator(IEmailResponder emailResponder)     {         _EmailResponder = emailResponder;     }      public void IsAuthenticated()     {         // Some logic...         // ...          // Woops authentication failed         SendEmailForAuthenticationFailure();     }      private void SendEmailForAuthenticationFailure()     {         _EmailResponder.SendEmail(...);     } } 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T07:59:08+00:00Added an answer on May 11, 2026 at 7:59 am

    The answer to the first question is that it is acceptable. For your follow-ups, the answer is it depends. The first one internalizes the email process. If you choose to do this, make sure that you’re injecting the email logic. If you choose the latter, it allows you to inject the behavior. If you do the second one, however, I would suggest that you change the name, since it doesn’t matter if it’s email, or MQ, or tiddlywinks. In fact, the second method isn’t really needed, since they can subscribe directly to the event.

    If you’re concerned about decoupling, you need to think about the single responsibility of the Authenticator class. It should be to authenticate, not to send emails. Try this:

    public class Authenticator {     public event EventHandler AuthenticationFailed = delegate { };      protected virtual void OnAuthenticationFailed()     {         AuthenticationFailed(this, EventArgs.Empty);     } } 

    now, consume authenticator:

    AuthenticationEmailResponder responder = new AuthenticationEmailResponder(emailAddress, emailServer); objAuthenticator.AuthenticationFailed += responder.SendFailureMessage; 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 207k
  • Answers 207k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer No, it is only called enough times to output SDLAudioSpec.freq… May 12, 2026 at 9:26 pm
  • Editorial Team
    Editorial Team added an answer You can put parameters into the body of the request.… May 12, 2026 at 9:26 pm
  • Editorial Team
    Editorial Team added an answer This has to do with how your browser handles resource… May 12, 2026 at 9:26 pm

Related Questions

I need to add some extension points to our existing code, and I've been
When creating a designable .NET component, you are required to provide a default constructor.
I would like to be able to delay the default action of an event
Has anyone looked at Yahoo's ASTRA ? It's fairly nifty, but I had some

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.