Exemplo n.º 1
0
        public static void Register()
        {
            _extensionLoader = new ExtensionLoader();

            var viewProvider    = new EmbeddedViewFileProvider();
            var contentProvider = new EmbeddedFileProvider();

            var provider = new AggregateVirtualPathProvider(viewProvider, contentProvider);

            HostingEnvironment.RegisterVirtualPathProvider(provider);

            var config = CoreConfiguration.Current.Extensibility;

            if (config == null)
            {
                return;
            }

            // automatic extension discovery with '*.Extension.dll' convention
            if (config.AutomaticExtensionDiscovery)
            {
                _extensionLoader.LoadExtensions();

                foreach (var assembly in _extensionLoader.Assemblies)
                {
                    viewProvider.Add(assembly);
                    contentProvider.Add(assembly);
                }
            }
            else
            {
                // controlled extension discovery based on web.config (without conventions)
                foreach (var ext in config.Extensions
                         .OfType <ExtensionElement>()
                         .Distinct(new ExtensionElementNameComparer()))
                {
                    var assembly = _extensionLoader.TryLoadAssemblyByName(ext.Name);
                    if (assembly == null)
                    {
                        continue;
                    }

                    var mapping = new NamespaceMapping(assembly, ext.Namespace);
                    viewProvider.Add(mapping);
                    contentProvider.Add(mapping);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Register the content files used by the adminstration area.
        /// </summary>
        /// <param name="provider"><c>GriffinVirtualPathProvider.Current</c></param>
        /// <param name="layoutVirtualPath">Typically <c>"~/Views/Shared/_Layout.cshtml"</c></param>
        public static void RegisterAdminFiles(this GriffinVirtualPathProvider provider, string layoutVirtualPath)
        {
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }
            if (layoutVirtualPath == null)
            {
                throw new ArgumentNullException("layoutVirtualPath");
            }
            // you can assign a custom WebViewPage or a custom layout in EmbeddedViewFixer.
            var fixer = new ExternalViewFixer()
            {
                LayoutPath = layoutVirtualPath
            };

            var griffinAssembly = typeof(MvcContrib.Areas.Griffin.GriffinAreaRegistration).Assembly;

            // for view files
            var embeddedViews = new EmbeddedViewFileProvider(VirtualPathUtility.ToAbsolute("~/"), fixer);

            embeddedViews.Add(new NamespaceMapping(griffinAssembly, "Griffin.MvcContrib"));
            provider.Add(embeddedViews);

            // Add support for loading content files:
            var contentFilesProvider = new EmbeddedFileProvider(VirtualPathUtility.ToAbsolute("~/"));

            contentFilesProvider.Add(new NamespaceMapping(griffinAssembly, "Griffin.MvcContrib"));
            provider.Add(contentFilesProvider);
        }