public void WrapViewEngines_HasProfiledEngine_AddsSameInstance()
        {
            var profiledEngine          = new ProfilingViewEngine(new PluginViewEngine());
            IList <IViewEngine> engines = new List <IViewEngine>
            {
                profiledEngine
            };

            WebInitialComponent.WrapViewEngines(engines);

            Assert.That(engines[0], Is.SameAs(profiledEngine));
        }
Beispiel #2
0
        protected void Application_Start()
        {
            // we use our own mobile devices support (".Mobile" is reserved). that's why we disable it.
            var mobileDisplayMode = DisplayModeProvider.Instance.Modes.FirstOrDefault(x => x.DisplayModeId == DisplayModeProvider.MobileDisplayModeId);

            if (mobileDisplayMode != null)
            {
                DisplayModeProvider.Instance.Modes.Remove(mobileDisplayMode);
            }

            bool installed = DataSettings.DatabaseIsInstalled();

            if (installed)
            {
                // remove all view engines
                ViewEngines.Engines.Clear();
            }

            // initialize engine context
            EngineContext.Initialize(false);

            // model binders
            ModelBinders.Binders.DefaultBinder = new SmartModelBinder();

            // Add some functionality on top of the default ModelMetadataProvider
            ModelMetadataProviders.Current = new SmartMetadataProvider();

            // Registering some regular mvc stuff
            AreaRegistration.RegisterAllAreas();

            // fluent validation
            DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false;
            ModelValidatorProviders.Providers.Add(new FluentValidationModelValidatorProvider(new SmartValidatorFactory()));

            // Routes
            RegisterRoutes(RouteTable.Routes, installed);

            if (installed)
            {
                var profilingEnabled = this.ProfilingEnabled;

                // register our themeable razor view engine we use
                IViewEngine viewEngine = new ThemeableRazorViewEngine();
                if (profilingEnabled)
                {
                    // ...and wrap, if profiling is active
                    viewEngine = new ProfilingViewEngine(viewEngine);
                    GlobalFilters.Filters.Add(new ProfilingActionFilter());
                }
                ViewEngines.Engines.Add(viewEngine);

                // Global filters
                RegisterGlobalFilters(GlobalFilters.Filters);

                // Bundles
                RegisterBundles(BundleTable.Bundles);

                // register virtual path provider for theme variables
                HostingEnvironment.RegisterVirtualPathProvider(new ThemeVarsVirtualPathProvider(HostingEnvironment.VirtualPathProvider));
                BundleTable.VirtualPathProvider = HostingEnvironment.VirtualPathProvider;

                // register virtual path provider for embedded views
                var embeddedViewResolver = EngineContext.Current.Resolve <IEmbeddedViewResolver>();
                var embeddedProvider     = new EmbeddedViewVirtualPathProvider(embeddedViewResolver.GetEmbeddedViews());
                HostingEnvironment.RegisterVirtualPathProvider(embeddedProvider);

                // start scheduled tasks
                TaskManager.Instance.Initialize();
                TaskManager.Instance.Start();
            }
            else
            {
                // app not installed

                // Install filter
                GlobalFilters.Filters.Add(new HandleInstallFilter());
            }
        }