是否MvcMiniProfiler需要一个Web应用程序的工作,或者可以在纯库就可以使用,比如在单元测试? [英] Does MvcMiniProfiler require a web application to work, or can it be used in pure libraries, such as in unit tests?

查看:246
本文介绍了是否MvcMiniProfiler需要一个Web应用程序的工作,或者可以在纯库就可以使用,比如在单元测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的很喜欢我所看到的关于 MvcMiniProfiler 。我喜欢使用非Web应用程序(Windows服务,单元测试等)的SQL监控功能。这是可能的,还是需要一个HTTP环境?最明显的区别是成果交付,但如果我可以序列化的结果,JSON或诸如此类,这将是很好。

I really like what I've seen regarding MvcMiniProfiler. I'd love to use the SQL monitoring features on non-web applications (windows services, unit tests, etc). Is this possible, or does it require an HTTP environment? The obvious difference would be results delivery, but if I can serialize the results to JSON or somesuch, that would be fine.

我一起扔一个简单的单元测试设法得到它的工作,但 MiniProfiler.Current 似乎总是为空,即使执行 MiniProfiler 。开始()

I threw together a simple unit test trying to get it to work, but MiniProfiler.Current appears to always be null, even after executing MiniProfiler.Start().

我是找错了树在这里?

推荐答案

非常好的问题。在内核的(分析器实例和连接包装)是不依赖于HTTP。如果你可以创建自己的实例,它应该所有的工作。然而,所有的UI code是面向各地的Web应用程序。

Excellent question. The core (the profiler instance and the connection wrappers) are not tied to http. If you can create your own instance, it should all work. However, all of the UI code is geared around web applications.

我知道用它在WPF中,的WinForms等人 - 因此它应该工作的罚款。但是,你也需要找出一个合乎逻辑的东西部给我测。在一个web应用程序是显而易见的:一个请求

I know of people using it in WPF, winforms, etc - so it should work fine. However, you would also need to figure out a logical "unit of thing to me measured". In a web app it is obvious: a request.

注意 MiniProfiler.Current 完全是出于方便(你可以把一个实例的任何地方),但我pretty的肯定,我们提出,可以创建你的自己的抽象(而不是HTTP上下文)。

Note that MiniProfiler.Current is purely a convenience (you could put an instance anywhere), but I'm pretty sure we made that possible to create your own abstraction (rather than http context).

(去检查code)

是啊,在这里我们去:

public static MiniProfiler Current
{
  get
  {
    MiniProfiler.Settings.EnsureProfilerProvider();
    return MiniProfiler.Settings.ProfilerProvider.GetCurrentProfiler();
  }
}

这样你就可以提供自己的 ProfileProvider 然后 .Current 应该工作。

这篇关于是否MvcMiniProfiler需要一个Web应用程序的工作,或者可以在纯库就可以使用,比如在单元测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆