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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T05:00:10+00:00 2026-05-19T05:00:10+00:00

I have 3 project files webui – controllers and views framework – service layer

  • 0

I have 3 project files

webui - controllers and views
framework - service layer and repos
tests- unit tests

So how I see it is that my controllers will only talk to my service layer(that contains my business logic). The service layer will talk to the repos and get database data.

My repo will just talk do the database and return data.

Now if I want to unit test this I need to have fake service layers and fake repositories.

this way I can test the controllers in isolation and the service layers in isolation.

So where do I put my ninject code in my framework class library so that I can use it with my service layer?

Edit

Steven are you saying I should be doing something like this

//setup ninject in global aspx with mvc extension

// now bind the stuff

private class SportsStoreServices : NinjectModule
        {
            public override void Load()
            {

                Bind<IAdminService>().To<AdminService>();
                Bind<IAdminRepo>().To<AdminRepo>();
            }
        }

// controller

public class AccountController : Controller
    {
        //
        // GET: /Account/

   private IAdminService adminService;

 public AccountController(IAdminService adminService)
        {
   this.adminService = adminService;
 }


        public ActionResult Login()
        {
            var getAllAdmins = adminService.GetAllAdmins();
            return View();
        }

    }

// Service Layer

public class AdminService : IAdminService
{

   private IAdminRepo adminRepo;
   public AdminService(IAdminRepo adminRepo)
   {
      this.adminRepo = adminRepo;
   }

   public List<Admins> GetAllAdmins()
   {

       return adminRepo.GetAllAdmins();
   }   

}


//Repo
    public class AdminRepo : IAdminRepo
    {
       public List<Admins> GetAllAdmins()
       {
          // some query to get all admins
       }
    } 
  • 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-19T05:00:11+00:00Added an answer on May 19, 2026 at 5:00 am

    When you follow the Dependency Injection pattern correctly (and completely) the only place you need to reference your IoC container is in your application root (in your case your web project). For MVC you would typically have a ControllerFactory that knows how to create new controllers using your particular IoC framework. Your controllers will be designed around constructor injection so your IoC framework is able to automatically inject all the dependencies. You will typically use constructor injection throughout the whole project. This allows you to let the rest of your code stay ignorant of the choosen IoC implementation.

    For unit tests you would normally use constructor injection to manually inject the dependencies. This saves you from having to configure your IoC framework for your unit tests. Using an IoC library in your test project is painful, because you often want different dependencies to be returned per test case and testing frameworks often run your tests in parallel. So best is to not use any IoC framework in your tests, but call the constructor of a type under test yourself.

    The trick for unit tests with DI is to keep your unit tests maintainable. You can do this for instance, by extracting the creation of a type under test into a factory method. This allows you to call such a constructor just in one place in your code. When the constructor changes, you would will have to change your test code in one place. I learned a lot about writing maintainable unit tests by the book The Art of Unit Testing. I can recommend it.

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

Sidebar

Related Questions

I have a structure like this WebUI project - controllers, views Framework project- repositories,service
I have a project with Crystal Reports files that doesn't seem to build correctly
I have a WiX project that installs a few EXE files. One is the
We have a project with many dll files which get loaded when the application
I have a project consisting of two files, main.c and logoff.c. When I try
In a project we have text files looking like this: mv A, R3 mv
For a small project I have to parse pdf files and take a specific
I have a very large C project with many separate C files and headers
I have a free standing set of files not affiliated with any C# project
I have a bunch of Velocity template files in a Visual Studio 2008 project,

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.