If I understand your question correctly, you're only wanting to call MiniProfiler's .Step()
extension method when running locally (or debugging), correct?
If so, this kinda defeats the purpose of MiniProfiler, which is to have all this instrumentation available for production code, without impacting production.
I'm confident you can simply do this in your code:
using (MiniProfiler.Current.Step("SelectUserDetail Function"))
{
user = UserService.SelectUserDetail(userId);
}
and it will have virtually no impact on your app; we literally do this hundreds of times in our code here on Stack Overflow without issue (as well as every single database query).
You should only need to have your checks when a new request comes in:
protected void Application_BeginRequest()
{
if (Request.IsLocal) { MiniProfiler.Start(); }
}
When you're running in production, any calls to MiniProfiler.Current.Step()
will return nothing, since the profiler is null
(the beauty of extension methods).
If you still want to prevent any using
statements from appearing in your production code, you should familiarize yourself with preprocessor directives. See this question, as well. However, I would strongly advise against them for this purpose, as it isn't necessary.