MiniProfiler / dotnet

A simple but effective mini-profiler for ASP.NET (and Core) websites
https://miniprofiler.com/dotnet/
MIT License
2.9k stars 598 forks source link

MiniProfiler.AspNetCore missing service collection extensions for non mvc registration #382

Open NinoFloris opened 5 years ago

NinoFloris commented 5 years ago

I would imagine fixing this would mean breaking this out into two methods?

https://github.com/MiniProfiler/dotnet/blob/master/src/MiniProfiler.AspNetCore.Mvc/MvcExtensions.cs#L22

NickCraver commented 5 years ago

I'm not sure what's being asked for here - what sort of method are you looking for? Pretend I'm stupid about the non-MVC use case :)

NickCraver commented 5 years ago

Any update here?

NinoFloris commented 5 years ago

Sorry this one slipped my view!

One that'll just enable the middleware level services. I'll attach what we enable in a bit

NickCraver commented 5 years ago

Not sure which extensions we're after here still, so let me know please :)

NinoFloris commented 5 years ago

Yes we're using this as a minimal setup for middleware only

public class MiniProfilerOptionsDefaults: IConfigureOptions<MiniProfilerOptions>
{
    private IMemoryCache _cache;

    public MiniProfilerOptionsDefaults(IMemoryCache cache)
    {
       _cache = cache;
    }

    public void Configure(MiniProfilerOptions options)
    {
        if (options.Storage == null)
            options.Storage = new MemoryCacheStorage(_cache, TimeSpan.FromMinutes(60.0));
    }
}

/// services 
services.AddMemoryCache()
services.AddSingleton<IConfigureOptions<MiniProfilerOptions>, MiniProfilerOptionsDefaults>() 
services.Configure<MiniProfilerOptions>(o => // some config of MiniProfiler )

// middleware
app.UseMiniProfiler()
NickCraver commented 5 years ago

Gotcha - so you want to profile the overall request but not actions or views in said profiles? If so, why?

I'm having trouble picturing the use case here. I'm not sure if adding a more minimal .Add* here makes sense, but if I understood the use case more than it might.

NinoFloris commented 5 years ago

We don't use MVC 🙃 , we're interested in request and per request provider profiles (EFCore, pg). With our migration to endpoint routing in 3.0 we can add routing information without MVC as well

NickCraver commented 5 years ago

Ah gotcha! What would be a good pattern here do you think? I think MVC by default is still correct for most people. But due to ordering, I can't reliably detect it and swap it automatically. What about an optional arg, something like:

services.AddMiniProfiler(includeMvc: false);

...or something like that?

NinoFloris commented 4 years ago

That may be fine actually :) With framework references containing MVC anyway the dependency on it isn't really a problem, so that's good.

NickCraver commented 4 years ago

We're looking at this for Stack Overflow's ASP.NET Core port now (and seeing what fun there is in the migration at mass scale)...will report back and update on what solutions we find since it may adjust services and built-in options here a bit. Sorry for the delay, we for held up on some side work and thought I'd be to this in prod for SO by now.