Skip to content

The types registered for MvcOptions and MvcViewOptions conflicts with other libraries. #162

Closed
@jasselin

Description

@jasselin

AddMiniProfiler registers a type for MvcOptions and MvcViewOptions that can override or be overidden by another library.

Depending on what library is called first, the last registered type is used by MVC.

For example, FluentValidation does the same and conflicts with MiniProfiler, preventing ProfilingViewEngine from being used.
https://github.com/JeremySkinner/FluentValidation/blob/237ccfd581dcecf72209acdaabd4c41122fad98d/src/FluentValidation.AspNetCore/FluentValidationMvcExtensions.cs#L63

A workaround could be to register the ViewEngine using IServiceCollection.Configure()

services.Configure<MvcViewOptions>(options =>
{
    for (var i = 0; i < options.ViewEngines.Count; i++)
    {
        options.ViewEngines[i] = new ProfilingViewEngine(options.ViewEngines[i]);
    }
});

The same thing applies to MvcOptions which adds ProfilerActionFilter to the Filters collection. Here is my current workaround.

services.AddMvc(cfg =>
{
    cfg.Filters.Add(new ProfilingActionFilter());
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions