Пример #1
0
        /// <summary>
        /// Use flat area folders with custom options
        /// </summary>
        public static IMvcBuilder AddFlatAreas(this IMvcBuilder services, FlatAreaOptions options)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }
            if (options == null)
            {
                throw new ArgumentException(nameof(options));
            }

            var expander = new FlatAreaExpander(options);

            services.AddMvcOptions(o =>
            {
                o.Conventions.Add(new FlatAreaConvention(options));
            })
            .AddRazorOptions(o =>
            {
                // Helps finding shared and other fully qualified resources
                o.ViewLocationFormats.Clear();
                o.ViewLocationFormats.Add(options.AreaPlaceholder + @"\{0}.cshtml");
                o.ViewLocationFormats.Add(options.RootFolderName + @"\_Base\{0}.cshtml");
                o.ViewLocationFormats.Add(options.RootFolderName + @"\_Related\{0}.cshtml");
                o.ViewLocationFormats.Add(options.RootFolderName + @"\{0}.cshtml"); // locates fully-qualified partial views
                o.ViewLocationExpanders.Add(expander);
            });

            return(services);
        }
Пример #2
0
 public FlatAreaExpander(FlatAreaOptions options)
 {
     _placeholder = options.AreaPlaceholder;
 }
Пример #3
0
 public FlatAreaConvention(FlatAreaOptions options)
 {
     _folderName             = options.RootFolderName;
     _nameDerivationStrategy = options.DeriveFolderName ?? DeriveAreaFolderName;
 }