0

I'm studying Adam Freeman's book on asp net mvc 4 which gives an example using Ninject.

using System;
using System.Web.Mvc;
using System.Web.Routing;
using Ninject;
namespace SportsStore.WebUI.Infrastructure
{
    public class NinjectControllerFactory : DefaultControllerFactory
    {
        private IKernel ninjectKernel;
        public NinjectControllerFactory()
        {
            ninjectKernel = new StandardKernel();
            AddBindings();
        }
        protected override IController GetControllerInstance(RequestContext requestContext,
        Type controllerType)
        {
            return controllerType == null
            ? null
            : (IController)ninjectKernel.Get(controllerType);
        }
        private void AddBindings()
        {

        }
    }
}

Unfortunately, his book is very difficult to apply to asp net core 6.

How can I implement such a factory using ninject in my project?

  • Have a look at the following answer on stackoverflow: https://stackoverflow.com/a/38261626/432074 – IceCode Aug 01 '22 at 13:48
  • There are [differences between ASP.NET MVC and ASP.NET Core](https://learn.microsoft.com/en-us/dotnet/architecture/porting-existing-aspnet-apps/architectural-differences), some methods can be shared, but some methods do not support both can be used. – Chen Aug 02 '22 at 09:44

0 Answers0