예제 #1
0
        protected void Application_Start()
        {
            var container = new WindsorContainer();

            Saltarelle.CastleWindsor.ContainerFactory.PrepareWindsorContainer(container);

            RegisterSaltarelleCoreServices(container, SaltarelleConfig.GetFromWebConfig());
            container.RegisterPluginsFromAssembly(typeof(CopyrightNodeProcessor).Assembly);
            container.RegisterControlsFromAssembly(typeof(Lesson1Control).Assembly);
            container.RegisterControlsFromAssembly(typeof(Label).Assembly);
            container.Register(AllTypes.FromAssemblyContaining <HomeController>().BasedOn <IController>().WithService.Self().LifestylePerWebRequest());
            container.Register(Component.For <ILesson7Service>().ImplementedBy <DefaultLesson7Provider>());

            RegisterRoutes(RouteTable.Routes);

            DependencyResolver.SetResolver(container.Resolve, s => (object[])container.ResolveAll(s));
        }
예제 #2
0
        public static void RegisterRoutes(RouteCollection routes)
        {
            var config = SaltarelleConfig.GetFromWebConfig();

            if (config == null)
            {
                throw new ConfigurationErrorsException("The <saltarelle> section is missing from web.config.");
            }
            bool debugScripts = config.Scripts.Debug;

            if (string.IsNullOrEmpty(config.Routes.AssemblyScripts))
            {
                throw new ConfigurationErrorsException("The saltarelle/routes/@assemblyScripts configuration attribute must be specified.");
            }
            if (!config.Routes.AssemblyScripts.Contains("{" + SaltarelleController.AssemblyNameParam + "}"))
            {
                throw new ConfigurationErrorsException("The saltarelle/routes/@assemblyScripts configuration attribute must contain the route value placeholder {" + SaltarelleController.AssemblyNameParam + "}.");
            }

            if (string.IsNullOrEmpty(config.Routes.AssemblyCss))
            {
                throw new ConfigurationErrorsException("The saltarelle/routes/@assemblyCss configuration attribute must be specified.");
            }
            if (!config.Routes.AssemblyCss.Contains("{" + SaltarelleController.AssemblyNameParam + "}"))
            {
                throw new ConfigurationErrorsException("The saltarelle/routes/@assemblyCss configuration attribute must contain the route value placeholder {" + SaltarelleController.AssemblyNameParam + "}.");
            }

            if (string.IsNullOrEmpty(config.Routes.AssemblyResources))
            {
                throw new ConfigurationErrorsException("The saltarelle/routes/@assemblyResources configuration attribute must be specified.");
            }
            if (!config.Routes.AssemblyResources.Contains("{" + SaltarelleController.AssemblyNameParam + "}") || !config.Routes.AssemblyResources.Contains("{version}") || !config.Routes.AssemblyResources.Contains("{*" + SaltarelleController.ResourceNameParam + "}"))
            {
                throw new ConfigurationErrorsException("The saltarelle/routes/@assemblyResources configuration attribute must contain the route value placeholders {" + SaltarelleController.AssemblyNameParam + "}, {version} and {*" + SaltarelleController.ResourceNameParam + "}.");
            }

            if (string.IsNullOrEmpty(config.Routes.Delegate))
            {
                throw new ConfigurationErrorsException("The saltarelle/routes/@delegate configuration attribute must be specified.");
            }
            if (!config.Routes.Delegate.Contains("{" + SaltarelleController.DelegateTypeNameParam + "}") || !config.Routes.Delegate.Contains("{" + SaltarelleController.DelegateMethodParam + "}"))
            {
                throw new ConfigurationErrorsException("The saltarelle/routes/@delegate configuration attribute must contain the route value placeholders {" + SaltarelleController.DelegateTypeNameParam + "} and {" + SaltarelleController.DelegateMethodParam + "}.");
            }

            RegisterSingle(routes, AssemblyScriptsRouteName, config.Routes.AssemblyScripts, (SaltarelleController c) => c.GetAssemblyScript(null, null), debugScripts ? new Dictionary <string, Func <RouteValueDictionary, string> >()
            {
                { "version", assemblyVersionDependency }, { SaltarelleController.ScriptDebugParam, _ => "1" }
            } : new Dictionary <string, Func <RouteValueDictionary, string> >()
            {
                { "version", assemblyVersionDependency }
            });
            RegisterSingle(routes, AssemblyCssRouteName, config.Routes.AssemblyCss, (SaltarelleController c) => c.GetAssemblyCss(null), new Dictionary <string, Func <RouteValueDictionary, string> >()
            {
                { "version", assemblyVersionDependency }
            });
            RegisterSingle(routes, AssemblyResourcesRouteName, config.Routes.AssemblyResources, (SaltarelleController c) => c.GetAssemblyResource(null, null), new Dictionary <string, Func <RouteValueDictionary, string> >()
            {
                { "version", assemblyVersionDependency }
            });
            RegisterSingle(routes, DelegateRouteName, config.Routes.Delegate, (SaltarelleController c) => c.Delegate(null, null), null);
        }