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

  • SEARCH
  • Home
  • 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 8953933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:12:17+00:00 2026-06-15T14:12:17+00:00

Need one design suggestion. Please see the class below. Class has just one method

  • 0

Need one design suggestion.
Please see the class below.
Class has just one method
Class has constructor that takes userName and passWord as parameters.
Question is – Whats the difference if
— If i remove the username and pwd from constructor
— And send (userName, password) to the AuthoriseUser method

All this in the background of injecting dependency

 public class UserNameAuthorisationService : IUserNameAuthorisationService
{
    private readonly string _userName;
    private readonly string _password;
    private readonly IUserNameAuthorisationRepository _usernameAuthRepository;

    public UserNameAuthorisationService(string UserName, string Password, IUserNameAuthorisationRepository UsernameAuthRepository)
    {
        _userName = UserName;
        _password = Password;
        _usernameAuthRepository = UsernameAuthRepository;
    }

    public IUser AuthoriseUser()
    {
        throw new NotImplementedException();
    }
}

Thanks in advance.

  • 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. Editorial Team
    Editorial Team
    2026-06-15T14:12:18+00:00Added an answer on June 15, 2026 at 2:12 pm

    Passing initial parameters in constructor is good for non-mutable objects, as if you dont provide setter method it is “impossible” (if not considering any reflection tricks) to change them.

    If you plan to not allow this values to change via your API, this is the only way to achieve this requirement. Otherwise you can implement setters. Even implementing setters you may think that this object cant exist (is pointless to exist) without a username and a password, in this case I would keep both setters and constructor initiation.

    As I see this object has no meaning to exist without password/username/repository, so I would keep their initialization at constructor.

    I would move username and password params to AuthoriseUser method if UserNameAuthorisationService were supposed to act as a component, and have for example, one unique application instance (your DI container should manage this). In this scenario I would inject this object in client objects via DI.

    The key point is to keep your object at a consistent state all the times, not using init() nor populate() methods. So as @Maxim pointed out, alway fully initialize your objects and keep them always at a usable state, in a way you dont have to throw an exception if AuthoriseUser() is called without mandatory parameters that were supposed to be pre-populated.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a large script that has no database connection yet. I need one
I have a class that contains objects of two other classes. I need one
I need just one callback at the and of multiple callbacks. With a simple
Can I please have a design suggestion for the following problem: I am using
I need some design suggestions for an Image class hierarchy. Currently, I have 2
I need one hidden iframe for all opened Firefox windows. For now I'm creating
I need one of my .exe to always run as administrator without UAC prompt.
I am working on one joomla(2.5.1) site and i need one module for one
I have 2 strings. and I need one Regex for both. s1=The 8481D provides
I have a Flex button. I need one color on the left and another

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.