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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:41:15+00:00 2026-06-08T19:41:15+00:00

I have a HomeController and a Referrence of a type-class.If I create a new

  • 0

I have a HomeController and a Referrence of a type-class.If I create a new object of the class it works fine for me. But I dont want to create new object in the Controller instead I want to pass a referrence of the class through the HomwController’s Constructor.Here is my code. I need to implement DI here.

//private readonly UnitOfWork<Student> _unitOfWork = new UnitOfWork<Student>();
    private readonly UnitOfWork<Student> _unitOfWork;

    //TODO ??
    public HomeController(UnitOfWork<Student> unitOfWork)
    {
        _unitOfWork = unitOfWork;
    }

    public ActionResult Index()
    {


        return View(_unitOfWork.GenericRepository.GetAll());
    }

Any help?

  • 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-08T19:41:17+00:00Added an answer on June 8, 2026 at 7:41 pm

    Are you talking ASP.NET MVC ?

    I have been working with Ninject for some time now, and am very happy with it! Take a look at the sample app in this repository to get an idea on how to use it in ASP.NET MVC 3:

    https://github.com/ninject/ninject.web.mvc/tree/master/mvc3

    To expand a bit on the reply, here’s a code snippet from where I set up the Ninject bindings

    kernel.Bind(typeof(IUnitOfWork<>).To(typeof(UnitOfWork<>));
    

    And my controller:

    public class MyController : Controller {
        private readonly IUnitOfWork<Student> uowStudent;
        public MyController(IUnitOfWork<Student> uowStudent) {
            this.uowStudent = uowStudent;
        }
    }
    

    Then all you need to do, is make sure any arguments in the constructor for the UnitOfWork class are also bound in the kernel.

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

Sidebar

Related Questions

I have the following action: public class HomeController : Controller { public ActionResult Index(int?
i have this timer in c#: public class HomeController : Controller { public int
I have a controller action as the below public class HomeController : BaseController {
have written this little class, which generates a UUID every time an object of
With the following code (using Moq 4.0.10501.6): HomeController controller = new HomeController(); ActionResult result
I have a simple controller test using MvcContrib's test helpers: var controller = new
I want to inject currentUser instance in HomeController class. so for every request, HomeController
I have this public class HomeController{ public ActionResult Index() { //do stuff return View();
I have this simple piece of coding in my Homecontroller.cs, but I receive the
I have an HomeController and in Index action i want work with multiple objects,

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.