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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:47:18+00:00 2026-06-02T12:47:18+00:00

I tried the following solution found in How can I implement Ninject or DI

  • 0

I tried the following solution found in How can I implement Ninject or DI on asp.net Web Forms? (Jason’s answer)

  1. Create a new ASP.NET WebForms project
  2. Use NuGet to add the Ninject.Web lib (which will also bring down the Ninject.Web.Common and Ninject libs)
  3. Register your custom bindings in App_Start / NinjectWebCommon.cs / RegisterServices method
  4. Use attribute injection on your pages

Works great in ASP.NET web applications.

The problem is I want to use Ninject for DI in an ASP.NET web site, not a web application.

I registered custom bindings in NinjectWebCommon / RegisterServices:

private static void RegisterServices(IKernel kernel)
{
    kernel.Bind<ITestRepository>().To<TestRepository>();
}

In a web page I inject it:

public partial class _Default : System.Web.UI.Page
{
    [Inject]
    public ITestRepository _repository { get; set; }

    protected void Page_Load(object sender, EventArgs e)
    {
        System.Diagnostics.Trace.WriteLine(_repository.ExecuteOperation());
    }
}

It always throws a null reference exception and the breakpoint inside NinjectWebCommon.cs is never reached – unlike in a web application.

What else should be done to make Ninject 3 work in a web site?

  • 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-02T12:47:25+00:00Added an answer on June 2, 2026 at 12:47 pm

    My first advice to you is…

    Don’t use ASP.NET Web Sites. Forget they exist. Avoid them at all costs. They are an anachronistic throwback to days of yore that are only still here for legacy reasons.

    My second piece of advice would be…

    If you insist on continuing to use a Web Site project, invest heavily in headache medicine, as you will need it.

    My third piece of advice would be…

    See First Advice.

    My fourth piece of advice would be…

    If you have absolutely no control over whether or not it’s a Web Site project or not, then just give up on the idea of using Ninject or any other DI container. Website projects inherit from a different set of base classes than Web Application sites. You won’t get it to work the same way, and you will probably spend way too much time trying to make it fit.

    EDIT:

    Basically, the code model works very differently between Web Sites and Web Applications. You need only look no further than the fact that Web Site apps don’t have namespaces while Web Application apps do. This should tell you how vastly different these are.

    I’m not entirely sure the activation process even works the same in both.

    However, having said all that. There is a glaring problem with your code. Your page derives from System.Web.UI.Page rather than Ninject.Web.PageBase

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

Sidebar

Related Questions

UPDATE: I found a solution. See my Answer below. My Question How can I
I tried to find an easy solution for the following. I have a main
gem install heroku failed with following message and I have tried the solution here
I tried following the answer to this question , but could not get xsd.exe
I tried following the README file in Ruby 1.9.1 but I can't compile it
I am working on a ASP.NET MVC web site that has multiple submit buttons.
I'm using asp.net 3.5, my solution currently has 2 projects, an API class project
I'm building a web app using EF Code First and ASP.NET MVC. I have
I'm new to Linq. I have searched and searched the web for a solution,
Having tried several solutions to get NHibernate to delete orphan records. Given the following

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.