Exemplo n.º 1
0
        public static IKernel GetKernel()
        {
            if (NinjectWebCommon.kernel == default(IKernel))
            {
                NinjectWebCommon.kernel = NinjectWebCommon.CreateKernel();
            }

            return(NinjectWebCommon.kernel);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates the kernel that will manage your application.
        /// </summary>
        /// <returns>The created kernel.</returns>
        private static IKernel CreateKernel()
        {
            NinjectWebCommon.kernel = new StandardKernel();
            try
            {
                NinjectWebCommon.kernel.Bind <Func <IKernel> >().ToMethod(ctx => () => new Bootstrapper().Kernel);
                NinjectWebCommon.kernel.Bind <IHttpModule>().To <HttpApplicationInitializationHttpModule>();

                NinjectWebCommon.RegisterServices(NinjectWebCommon.kernel);
                GlobalConfiguration.Configuration.DependencyResolver = new NinjectDependencyResolver(NinjectWebCommon.kernel);
                return(NinjectWebCommon.kernel);
            }
            catch
            {
                NinjectWebCommon.kernel.Dispose();
                throw;
            }
        }