Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Mounhim Tahtahi 41 posts 62 karma points
    May 17, 2013 @ 20:36
    Mounhim Tahtahi
    0

    Using NInject with Umbraco 6.0.5

    I have been wrapping my head around this and thus far existing questions and answers did not help. So I will try it as well. I am trying to hook up Ninject in Umbraco. What do I have so far:

    A class called NinjectWebCommon. This Class was created by NuGet when installing Ninject.

    In this class I have added register service like Ninject and NLog document:

            private static void RegisterServices(IKernel kernel)
            {
                kernel.Bind<ILogger>().To<NLogger>().InSingletonScope();
            }
    
    I have also a class called StartupHandler:
        [Application("MyApp", "MyApp", "app.gif", 8)]
        public class StartupHandler: IApplicationEventHandler
    I see that both the code in NinjectWebCommon is run as well as the code in StartupHandler. Yet when I use the following line I get a nullreferenceexception because it can not find the registered service:
    DependencyResolver.Current.GetService<ILogger>().LogInfo("Application Started");

     

    Also when I call an action on my controller that has the iLogger injected I receive an error that there is no parameterless constructor. But if I do that my dependency is never injected.

    Any thought, starting points, etc for using IoC in Umbraco 6


Please Sign in or register to post replies

Write your reply to:

Draft