MvcMiniProfiler 是否需要 Web 应用程序才能工作,或者可以在纯库中使用,例如在单元测试中?
我真的很喜欢我所看到的有关 MvcMiniProfiler 的内容。我很想在非 Web 应用程序(Windows 服务、单元测试等)上使用 SQL 监控功能。这可能吗,还是需要HTTP环境?明显的区别是结果交付,但如果我可以将结果序列化为 JSON 或类似的东西,那就没问题了。
我拼凑了一个简单的单元测试,试图让它工作,但即使在执行 MiniProfiler.Start() 后,MiniProfiler.Current 似乎始终为空。
我是不是找错树了?
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.
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()
.
Am I barking up the wrong tree here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
很好的问题。 核心(分析器实例和连接包装器)不依赖于 http。如果您可以创建自己的实例,那么它应该可以正常工作。然而,所有 UI 代码都是围绕 Web 应用程序设计的。
我知道有人在 WPF、winforms 等中使用它 - 所以它应该可以正常工作。但是,您还需要找出一个逻辑上的“对我来说测量的事物单位”。在网络应用程序中,这是显而易见的:请求。
请注意,MiniProfiler.Current 纯粹是为了方便(您可以将实例放在任何地方),但我很确定我们可以创建您自己的抽象(而不是 http 上下文)。
(去检查代码)
啊是的,我们开始:
这样你就可以提供自己的
ProfileProvider
然后.Current
应该可以工作。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.
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.
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).(goes to check the code)
ah yes, here we go:
so you can provide your own
ProfileProvider
and then.Current
should work.