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; }
public FeatureViewLocationExpander(FeatureFolderOptions options) { _placeholder = options.FeatureNameConvention; }