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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:10:38+00:00 2026-05-26T23:10:38+00:00

Hi I’m using ninject with an MVC app. I’m sure I have it setup

  • 0

Hi I’m using ninject with an MVC app.

I’m sure I have it setup correctly as I’m able to get it working for my controllers. Here is an example for a controller and it is working correctly:

public class GstRateController : Controller
    {
        private readonly IUnitOfWork _unitOfWork;

        public GstRateController(IUnitOfWork unitOfWork)
        {
            _unitOfWork = unitOfWork;
        }
...

Then I thought it would also be good on a viewModel so I tried that with:

public class SettingController : Controller
    {
        private readonly IUnitOfWork _unitOfWork;

        public SettingController(IUnitOfWork unitOfWork)
        {
            _unitOfWork = unitOfWork;
        }

So then I instantiated the view model in a controller by:

public ActionResult Index()
        {
            return View("Index", Activator.CreateInstance<SettingViewModel>());
        }

But this is giving me the error:

No parameterless constructor defined for this object.

I’m new to DI. Could someone please tell me how to achieve this for viewmodels?

  • 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-26T23:10:38+00:00Added an answer on May 26, 2026 at 11:10 pm

    The reason it works for controllers and not view models is because when you install the NInject NuGet it registers a custom dependency resolver and the ASP.NET MVC framework uses either the controller factory or the dependency resolver to instantiate controllers. You can read more about dependency resolvers in this article.

    View models on the other hand are classes that you have specifically designed to meet the requirements of a given view. Since you are manually instantiating them a DI framework can never intercept and inject any dependencies into them. They should not have dependencies. They should be simple POCO objects that are mapped from domain models. They represent a project of on or more domain models.

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

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I have thousands of HTML files to process using Groovy/Java and I need to
I am using Paperclip to handle profile photo uploads in my app. They upload
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,

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.