2

我刚刚将 MiniProfiler 集成到我一直在研究的产品中。

它很棒,也很简单,但是对于超出最普通用法的东西,我发现的文档并不多。

例如,下面的示例代码。(我知道它可能会被重构以减少嵌套级别,但假设这对于这个问题是不可能的)

嵌套有 3 级,低于整体操作。据我所知,MiniProfiler 只会显示前两个深度级别。真的是这样吗,即它是一个功能吗?还是我没有正确使用它?

private MiniProfiler Profiler { get; set; }

public ThingController()
{
    Profiler = MiniProfiler.Current;
}

public ActionResult GetPageSection(User user)
{
    List<RecordViewModel> viewModel;
    using (Profiler.Step("Get Section"))
    {
        using (Profiler.Step("Get Records from user"))
            {
                viewModel = user.Records.Where(r => r.Active).Select(
                    r =>
                        {
                            Item item
                            using (Profiler.Step("Get Item from service"))
                            {
                                item = GetItem(r);
                            }

                            using (Profiler.Step("Build record view model"))
                            {
                                return new RecordViewModel(r, item);
                            }
                        }).ToList();
            }
    }
    return PartialView(viewModel);
}

另一个问题是尝试从 ModelBinder 中使用 MiniProfiler 时,例如:

public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
    using (Profiler.Step("Bind user"))
    {
        // Do stuff
    }
}

MiniProfiler 为空。

有什么方法可以让 MiniProfiler 在这两种情况下工作?

注意:我没有使用 MiniProfiler.MVC3。我只是在使用 MiniProfiler。我不确定这是否会有所作为。

4

0 回答 0