public static IMvcBuilder AddRazorByFeatures(this IMvcBuilder services, RazorFeaturesOptions options) { if (services == null) { throw new ArgumentNullException(nameof(services)); } if (options == null) { throw new ArgumentException(nameof(options)); } var expander = new RazorFeaturesViewLocationExpander(options); services.AddMvcOptions(o => { o.Conventions.Add(new RazorFeaturesControllerModelConvention(options)); }) .AddRazorOptions(o => { if (!options.KeepDefaultViewLocation) { o.ViewLocationFormats.Clear(); } o.ViewLocationFormats.Insert(0, options.FeatureNamePlaceholder + @"\{0}.cshtml"); o.ViewLocationFormats.Insert(0, options.FeatureNamePlaceholder + @"\Shared\{0}.cshtml"); o.ViewLocationFormats.Insert(0, options.FeatureFolderName + @"\Shared\{0}.cshtml"); o.ViewLocationExpanders.Add(expander); }); return(services); }
public void CanGetPathFromControllerWithDeafultOptions(Type controller, string expected) { var defaultOptions = new RazorFeaturesOptions(); var convention = new RazorFeaturesControllerModelConvention(defaultOptions); var controllerModel = new ControllerModel(controller.GetTypeInfo(), new List <string>()); convention.Apply(controllerModel); Assert.Equal(expected, controllerModel.Properties[RazorFeaturesControllerModelConvention.FeatureControllerPropertyName]); }