using LinFx.Data;using LinFx.Index;using LinFx.Plugin.Caching;using LinFx.Plugin.Lucene.Services;using LinFx.Plugin.Search.Services;using LinFx.Security;using LinFx.Web;using YLSPay.Data;using YLSPay.Data.Service;[assembly: WebActivator.PreApplicationStartMethod(typeof(YLSPay.App_Start.NinjectWebCommon), "Start")][assembly: WebActivator.ApplicationShutdownMethodAttribute(typeof(YLSPay.App_Start.NinjectWebCommon), "Stop")]namespace YLSPay.App_Start{ using System; using System.Web; using Microsoft.Web.Infrastructure.DynamicModuleHelper; using Ninject; using Ninject.Web.Common; using System.Data.Entity; public static class NinjectWebCommon { static readonly Bootstrapper bootstrapper = new Bootstrapper(); ////// Starts the application /// public static void Start() { DynamicModuleUtility.RegisterModule(typeof(OnePerRequestHttpModule)); DynamicModuleUtility.RegisterModule(typeof(NinjectHttpModule)); bootstrapper.Initialize(CreateKernel); } ////// Stops the application. /// public static void Stop() { bootstrapper.ShutDown(); } ////// Creates the kernel that will manage your application. /// ///The created kernel. private static IKernel CreateKernel() { var kernel = new StandardKernel(); kernel.Bind>().ToMethod(ctx => () => new Bootstrapper().Kernel); kernel.Bind ().To (); RegisterServices(kernel); return kernel; } /// /// Load your modules or register your services here! /// /// The kernel. private static void RegisterServices(IKernel kernel) { var aa = new HttpContextWrapper(HttpContext.Current) as HttpContextBase; kernel.Bind().ToMethod(ctx => HttpContext.Current).InRequestScope(); kernel.Bind ().ToMethod(ctx => new HttpContextWrapper(HttpContext.Current)).InRequestScope(); //kernel.Register(c => // //register FakeHttpContext when HttpContext is not available // HttpContext.Current != null ? // (new HttpContextWrapper(HttpContext.Current) as HttpContextBase) : // (new FakeHttpContext("~/") as HttpContextBase)) // .As () // .InstancePerHttpRequest(); //var httpContext = new FakeHttpContext("~/") as HttpContextBase; kernel.Bind ().ToMethod(ctx => HttpContext.Current != null ? (new HttpContextWrapper(HttpContext.Current) as HttpContextBase) : (new LinFx.Web.Fakes.FakeHttpContext("~/") as HttpContextBase)); kernel.Bind ().To ().InRequestScope(); kernel.Bind ().To ().InRequestScope(); kernel.Bind ().ToSelf().InRequestScope(); kernel.Bind ().ToSelf().InRequestScope(); kernel.Bind ().ToSelf().InRequestScope(); kernel.Bind ().ToSelf().InRequestScope(); kernel.Bind ().To ().InRequestScope(); kernel.Bind ().To ().InSingletonScope(); kernel.Bind ().To ().InRequestScope(); kernel.Bind ().To ().InRequestScope(); //kernel.Bind ().To ().InRequestScope(); kernel.Bind(typeof(IRepository<>)).To(typeof(Repository<>)).InRequestScope(); ; //search kernel.Bind ().To (); kernel.Bind ().To (); kernel.Bind ().To (); kernel.Bind ().To (); } }}
引用
Ninject
Ninject.Web.Common
Ninject.Web.Mvc
不知道为什么,,我总不能成功.
这里出问题了吗?
kernel.Bind().ToMethod(ctx => HttpContext.Current).InRequestScope(); kernel.Bind ().ToMethod(ctx => new HttpContextWrapper(HttpContext.Current)).InRequestScope();