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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:55:06+00:00 2026-06-08T08:55:06+00:00

I created an mvc4 project in visual studio 2012 RC, and added the ninject.mvc3

  • 0

I created an mvc4 project in visual studio 2012 RC, and added the ninject.mvc3 package using nuget. It created the standard NinjectWebCommon.cs file and I edited the RegisterServices method like so:

private static void RegisterServices(IKernel kernel)
        {
            kernel.Bind<IProfileRepository>().To<ProfileRepository>().InSingletonScope(); 
        }    

Here is my interface and profile repository class:

public interface IProfileRepository
    {
        void CreateProfile(UserProfile profile);
    }



public class ProfileRepository : IProfileRepository
    {
        private EFDbContext context = new EFDbContext();

        public void CreateProfile(UserProfile userProfile)
        {
            context.UserProfiles.Add(userProfile);
            context.SaveChanges();
        }

    }

I want to access this my IProfileRepository in my Account Controller like so:

        private readonly IProfileRepository profileRepository;

        public AccountController(IProfileRepository repo){
            profileRepository = repo;
        }
        [AllowAnonymous]
        [HttpPost]
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                MembershipCreateStatus createStatus;
                Membership.CreateUser(model.UserName, model.Password, model.Email, passwordQuestion: null, passwordAnswer: null, isApproved: true, providerUserKey: null, status: out createStatus);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    profileRepository.CreateProfile(new UserProfile
                    {
                        UserId = (Guid)Membership.GetUser(HttpContext.User.Identity.Name).ProviderUserKey,
                        FirstName = model.FirstName,
                        LastName = model.LastName,
                        School = model.School,
                        Major = model.Major
                    });
                    FormsAuthentication.SetAuthCookie(model.UserName, createPersistentCookie: false);
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    ModelState.AddModelError("", ErrorCodeToString(createStatus));
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }

I get an Object reference not set to an instance of an object error when my profileRepostory object is called, hence its probably not being injected. Does anyone know whats wrong? Thanks!

EDIT:
Here is my global.asax file:

public class MvcApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }
    }
  • 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-08T08:55:07+00:00Added an answer on June 8, 2026 at 8:55 am

    Unless you changed the configuration, Ninject will throw an ActivationException rather than inject null for a dependency. You should check which object is really null.

    E.g. Allowing anonymous access is a huge hint that HttpContext.User is what is null.

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

Sidebar

Related Questions

I create a ASP.net MVC 4 project by using Visual Studio 2010 IDE. I
Created MVC4 project and updated jquery through Manage NuGet Packages to 1.7.1 - got
I've created an MVC3 application in Visual Studio 10. When editing views the @Model,
I have a simple asp.net MVC4 / EF 4.1 project created with VS 2011,
I've created a method using the new WebAPI features in MVC4 and have it
I am using MVC4's WEB API to expose a controller. Initially I created created
(Using MVC4 VB EF4 MSSQL Razor) I created a Stored Procedure in the MS
I created a new project of type Asp.net MVC 4 I installed the package
I am trying to build a test MVC4 project on OS X 10.7.4 using
I installed the MVC 4 beta and created a new project. The standard template

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.