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 6563549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:51:52+00:00 2026-05-25T13:51:52+00:00

I am having a Repository, Interface, Controller …. that looks something like this.. Interface

  • 0

I am having a Repository, Interface, Controller …. that looks something like this..

Interface – IUSer

public interface IUserRepositories
    {
       bool CreateUser(User newUser);

       bool CheckUniqueEmail(string Email);

       bool CheckUserLoginDetails(string email, string password); 
    }

User Repository
=============
which is implementing all the methods ..

1) CreateUSer
2) CheckLoginDetails
3) CheckUniqueEmail

Controller – Not sure what it does…

private IUserRepositories _userRepo;

        public UserController() : this(new UserRepositories())
        {
        }

        public UserController(IUserRepositories userRepo)
        {
            this._userRepo = userRepo;
        }

Is this looks OK…if yes… what benefit i can get by implementing this way…

Please explain… confusion from last 3 hours….

Thanks…

  • 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-05-25T13:51:53+00:00Added an answer on May 25, 2026 at 1:51 pm

    Is this looks OK

    Almost. What you have is often referred to as poor man’s DI. The correct way is the following (notice that the default constructor has been removed):

    private IUserRepositories _userRepo;
    public UserController(IUserRepositories userRepo)
    {
        this._userRepo = userRepo;
    }
    

    The benefit you have by using inversion of control that way is that your controller is weakly coupled to the repository making it easier to unit test in isolation and making different layers of your application more reusable and maintainable.

    By removing the default constructor you are clearly indicating to the consumers of a given class that this class depends and requires a repository which must implement a given contract (interface). This makes your code clearly auto document itself to the consumer.

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

Sidebar

Related Questions

Having a heckuva time with this one, though I feel I'm missing something obvious.
Having this route: map.foo 'foo/*path', :controller => 'foo', :action => 'index' I have the
I am having a generic interface as: public IRepository< T > { void Add(T
So far I've resisted having a central repository that I push/pull the changes from
Having programmed through emacs and vi for years and years at this point, I
Having difficulty articulating this correlated subquery. I have two tables fictitious tables, foo and
I'm having a couple of problems with circular reference/dependency that I've been sitting on
I'm having trouble finding examples of ASP.NET MVC solutions that use EF4 in their
We are having a local repository which is accessible to a large number of
Having the code below in my Global.asax.cs and two controller (one based on a

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.