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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:05:15+00:00 2026-05-17T02:05:15+00:00

I am trying to convert some actions within a controller to run asynchronously in

  • 0

I am trying to convert some actions within a controller to run asynchronously in an mvc project that is using ninject for dependency injection. I’m following the steps by inheriting AsyncController and changing the methods that correspond to the ‘X’ action to ‘XAsync’ and ‘XCompleted’ but the async action is not getting resolved. I’m confident that the issue has to do with ninject. I have tried to explicitly set ninject’s Controller Action Invoker to ‘AsyncControllerActionInvoker’:

Bind<IActionInvoker>().To<AsyncControllerActionInvoker>().InSingletonScope();

but no luck. Has anyone managed to get Async actions working with ninject?

cheers,

  • 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-17T02:05:15+00:00Added an answer on May 17, 2026 at 2:05 am

    Essentially the problem i was facing was that the default action invoker that is used by ninject doesnt support async actions and when you try to set the action invoker in a controller the default ninjectControllerFactory overrides it. I took the following steps to fix the problem:

    1.In the injection mapping i added the following association:

    Bind<IActionInvoker>().To<AsyncControllerActionInvoker>().InSingletonScope();
    

    2.I created a custom controller factory that is basically ninject’s controller factory with the only difference being that it doesn’t overwrite the action invoker.

    public class CustomNinjectControllerFactory : DefaultControllerFactory {
        /// <summary>
        /// Gets the kernel that will be used to create controllers.
        /// </summary>
        public IKernel Kernel { get; private set; }
    
        /// <summary>
        /// Initializes a new instance of the <see cref="NinjectControllerFactory"/> class.
        /// </summary>
        /// <param name="kernel">The kernel that should be used to create controllers.</param>
        public CustomNinjectControllerFactory(IKernel kernel) {
            Kernel = kernel;
        }
    
        /// <summary>
        /// Gets a controller instance of type controllerType.
        /// </summary>
        /// <param name="requestContext">The request context.</param>
        /// <param name="controllerType">Type of controller to create.</param>
        /// <returns>The controller instance.</returns>
        protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType) {
            if (controllerType == null) {
                // let the base handle 404 errors with proper culture information
                return base.GetControllerInstance(requestContext, controllerType);
            }
    
            var controller = Kernel.TryGet(controllerType) as IController;
    
            if (controller == null)
                return base.GetControllerInstance(requestContext, controllerType);
    
            var standardController = controller as Controller;
    
            if (standardController != null && standardController.ActionInvoker == null)
                standardController.ActionInvoker = CreateActionInvoker();
    
            return controller;
        }
    
        /// <summary>
        /// Creates the action invoker.
        /// </summary>
        /// <returns>The action invoker.</returns>
        protected virtual NinjectActionInvoker CreateActionInvoker() {
            return new NinjectActionInvoker(Kernel);
        }
    
    }
    

    3.In OnApplicationStarted() method I set the controller factory to my custom one:

    ControllerBuilder.Current.SetControllerFactory(new customNinjectControllerFactory(Kernel));`
    

    Hope this helps.

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

Sidebar

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.