示例#1
0
        protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
        {
            string controllerName = GetControllerName(requestContext, controllerType);
            string path           = pathProvider.GetPath(requestContext, controllerName);
            CSharpControllerFile controllerFile = CSharpControllerFile.Parse(File.ReadAllText(path));

            var parameters = new CompilerParameters();

            addReferencedAssemblies(parameters);

            var codeProvider = new CSharpCodeProvider().CompileAssemblyFromSource(parameters, controllerFile.ClassSource);

            if (denpedencyInjector == null)
            {
                object controllerInstance = codeProvider.CompiledAssembly.CreateInstance(controllerFile.FullClassName);
                return((IController)controllerInstance ?? base.GetControllerInstance(requestContext, controllerType));
            }
            else
            {
                return(denpedencyInjector.CreateControllerInstance(codeProvider.CompiledAssembly.GetType(controllerFile.FullClassName)));
            }
        }