IPageRequestHook

All registered IPageRequestHook implementations are executed each time a page is requested on the front end.  By implementing a Page request hook, you can access the current pageRequest object to do various things, such as add links to custom JS/CSS files, modify page properties for the request etc.  There is one method you need to implement, which is the OnRequestAsync() method.  You also need to define a OrderIndex which is a number.  This controls the order in which registered page request hooks are invoked.  The page request hook with the lowest number will be executed first.

Interface declaration

public interface IPageRequestHook
{
	int OrderIndex { get; }
	Task OnRequestAsync(PageRequest pageRequest);
}

Example

This example page request hook adds a reference to the animate.css library.

public class TestPageRequestHook : IPageRequestHook
{
	public int OrderIndex => 1000;

	public async Task OnRequestAsync(PageRequest pageRequest)
	{
		pageRequest.Styles.Add(new StyleReference() { Href = "//cdnjs.cloudflare.com/ajax/libs/animate.css/3.7.2/animate.min.css", Rel = "stylesheet" });
	}
}

Registration

This is how the implementation is registered into the DI container in Veva, this should be done in your module config file (The class which implements IModule).

public void ConfigureServices(IServiceCollection services, IConfiguration configuration)
{
	services.AddScoped<IPageRequestHook, TestPageRequestHook>();
}