代码之家  ›  专栏  ›  技术社区  ›  zerkms

global.asax中应用程序的物理路径

  •  4
  • zerkms  · 技术社区  · 16 年前

    升级版
    这是我现在的一个草图:

    public class MvcApplication : System.Web.HttpApplication 
    {
        ...
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
    
            RegisterRoutes(RouteTable.Routes);
    
            ControllerBuilder.Current.SetControllerFactory(typeof(IOCControllerFactory));
        }
    }
    
    public class IOCControllerFactory : DefaultControllerFactory
    {
        private readonly IKernel kernel;
    
        public IOCControllerFactory()
        {
            kernel = new StandardKernel(new NanocrmContainer());
        }
    
        protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
        {
            var controller = kernel.TryGet(controllerType) as IController;
    
            if (controller == null)
                return base.GetControllerInstance(requestContext, controllerType);
    
            var standartController = controller as Controller;
    
            return standartController;
        }
    
        class NanocrmContainer : Ninject.Modules.NinjectModule
        {
            public override void Load()
            {
                Bind<IFileService>().To<BusinessLogic.Services.FileService>().InRequestScope().WithConstructorArgument("temp", "Temp").WithConstructorArgument("docs", "Documents"); // Temp and Documents should be replaced with corresponding paths
            }
        }
    }
    
    1 回复  |  直到 16 年前
        1
  •  13
  •   SLaks    16 年前
    推荐文章