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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:14:30+00:00 2026-05-28T07:14:30+00:00

I am using ASP.NET MVC 3 + Ninject in my application which works great

  • 0

I am using ASP.NET MVC 3 + Ninject in my application which works great with my controllers.

I also have a custom base page class that inherits from WebViewPage and I have setup an interface that I’d like to be injected in that custom base page class.

However, it’s not working (my interfaces are null), and I assume that is because Ninject doesn’t know about System.Web.Mvc.MvcWebRazorHostFactory which I suspect it would have to override or intercept somehow.

Can anyone point me in the right direction on how to allow my custom WebViewPage to use DI?

  • 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-28T07:14:30+00:00Added an answer on May 28, 2026 at 7:14 am

    Here is a possible workaround…Use a KernelPersister to state the kernel, and reference it directly from within your base View. It’s not as pretty and seamless as constructor injection, but it does the trick.

    KernelPersister might look like this…

    public static class KernelPersister
    {
         static IKernel persistedKernel;
    
         /// <summary>
         /// Persists the provided kernel
         /// </summary>
         public static void Set(IKernel kernel)
         {
              if(persistedKernel == null)
              {
                   throw new ArgumentNullException("kernel");
              }
    
              persistedKernel = kernel;
         }
    
         /// <summary>
         /// Gets the persisted kernel
         /// </summary>
         public static IKernel Get()
         {
              if(persistedKernel == null)
              {
                   throw new Exception("The kernel must be actively set in the persister");
              }
              return persistedKernel;
         }
    }
    

    Base view might look like this…

    public abstract class MyBaseView : System.Web.Mvc.WebViewPage
    {
         /// <summary>
         /// Gets access to the MyService
         /// </summary>
         protected IMyService MyService {get; private set;}
    
         /// <summary>
         /// ctor the Mighty
         /// </summary>
         public MyBaseView()
         {
              var kernel = KernelPersister.Get();
              this.MyService = kernel.GetService(typeof(IMyService)) as IMyService;          
         }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET MVC 3 application and am using Ninject for injecting dependencies
We are using ASP.net MVC. Which of these is the best DI framework Ninject
using ASP.NET MVC 2 I have a navigation menu inside my Master Page. In
I have a web application which was using Asp.net MVC2 . I Upgraded it
I've got a simple web application using ASP.NET MVC3 and Ninject.Web.MVC (the MVC3 version).
using ASP.NET MVC, I have a Model, to which I'm attaching attributes so that
I am building an application using Ninject and ASP.NET MVC 3. Is it possible
I have Ninject configured to do DI in an ASP.NET MVC 3 application. This
I am using Ninject 2 with Asp.Net MVC 3. I have following module. public
I am using NHibernate and ninject in ASP.Net MVC, using this page as 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.