/// <summary> /// Initializes a new instance of <see cref="ViewToStringRenderer"/> class. /// </summary> /// <param name="razorViewEngine">Razor view engine.</param> /// <param name="tempDataProvider">Temporary data provider.</param> /// <param name="serviceProvider">Service provider.</param> public ViewToStringRenderer(IHostingEnvironment hostingEnvironment, IRazorViewEngine razorViewEngine, ITempDataProvider tempDataProvider, IServiceProvider serviceProvider, IOptions <ViewToStringRendererOptions> options) { m_hostingEnvironment = hostingEnvironment; m_razorViewEngine = razorViewEngine; m_tempDataProvider = tempDataProvider; m_serviceProvider = serviceProvider; m_options = options.Value; }
/// <summary> /// Adds <see cref="IViewToStringRenderer"/> service to the service collection. /// </summary> /// <param name="services">Service collection.</param> /// <param name="options">Options.</param> /// <returns><see cref="IServiceCollection"/>.</returns> public static IServiceCollection AddRazorViewToStringRenderer(this IServiceCollection services, Action <ViewToStringRendererOptions> options) { ViewToStringRendererOptions viewToStringrendererOptions = new ViewToStringRendererOptions(); options(viewToStringrendererOptions); services.Configure <RazorViewEngineOptions>(o => o.ViewLocationExpanders.Add(new ViewLocationExpander(viewToStringrendererOptions))); services.Configure(options); services.AddTransient <IViewToStringRenderer, ViewToStringRenderer>(); return(services); }
/// <summary> /// Initializes a new instance of <see cref="ViewLocationExpander"/> class. /// </summary> /// <param name="options">Options.</param> public ViewLocationExpander(ViewToStringRendererOptions options) { var root = Directory.GetCurrentDirectory(); // Find all 'Emails' folders in the directory m_directoryLocations = Directory.GetDirectories(root, options.EmailsFolder, SearchOption.AllDirectories); // Only include the ones in the running directory, remove the root path (the view engine uses relative paths) // and append the file name m_directoryLocations = m_directoryLocations.Where(s => s.Contains(options.ContentRoot)) .Select(s => s.Replace(root, "")) .Select(s => s.Insert(s.Length, "\\{0}.cshtml")); }