Exemplo n.º 1
0
        public static IMvcBuilder AddFeatureFolders(this IMvcBuilder services, FeatureFolderOptions options)
        {
            Guard.ThrowIfNull(services, nameof(services));
            Guard.ThrowIfNull(options, nameof(options));

            var expander = new FeatureViewLocationExpander(options);

            services.AddMvcOptions(o =>
            {
                if (options.ViewExtractionOption == ViewExtractionOption.Convention ||
                    options.ViewExtractionOption == ViewExtractionOption.All)
                {
                    o.Conventions.Add(new FeatureFolderControllerModelConvention(options));
                }
            });

            services.AddRazorOptions(o =>
            {
                o.ViewLocationFormats.Clear();

                if (options.ViewExtractionOption == ViewExtractionOption.Explicits ||
                    options.ViewExtractionOption == ViewExtractionOption.All)
                {
                    o.ViewLocationFormats.Add($@"{options.FeatureFolderName}\{{0}}.cshtml");
                }

                if (options.ViewExtractionOption == ViewExtractionOption.Convention ||
                    options.ViewExtractionOption == ViewExtractionOption.All)
                {
                    o.ViewLocationFormats.Add($@"{options.FeatureNameConvention}\{{0}}.cshtml");
                    o.ViewLocationExpanders.Add(expander);
                }
            });

            return(services);
        }
 public FeatureFolderControllerModelConvention(FeatureFolderOptions options)
 {
     _folderName = options.FeatureFolderName;
 }
Exemplo n.º 3
0
 public FeatureViewLocationExpander(FeatureFolderOptions options)
 {
     _placeholder = options.FeatureNameConvention;
 }