我正在使用Ninject和MVC3一起注入我的控制器依赖项。有时甚至在执行控制器操作之前,我在MVC Mini Profiler中得到的定时很慢。由于在此之前我没有做太多的工作,我认为这可能是我使用Ninject时遇到的一个问题。有没有一种方法可以从ninject获取一些时间信息?也许是一个配置选项来记录依赖性解决需要多长时间,或者如果不是,我自己可以添加一个类是否可以扩展或包装?在mvc3 web应用程序中配置文件ninject
回答
您可以通过实现IDependencyResolver接口并将其替换到DependencyResolver上来编写NinjectDependencyResolver的装饰器。
DependencyResolver.SetResolver(new ProfilingResolver(DependencyResolver.Current));
public class ProfilingResolver : IDependencyResolver
{
private readonly IDependencyResolver decoratedResolver;
public ProfilingResolver(IDependencyResolver decoratedResolver)
{
this.decoratedResolver = decoratedResolver;
}
public object GetService(Type serviceType)
{
using (MiniProfiler.Current.Step("Get_" + serviceType.Name))
{
return this.decoratedResolver.GetService(serviceType);
}
}
public IEnumerable<object> GetServices(Type serviceType)
{
using (MiniProfiler.Current.Step("GetAll_" + serviceType.Name))
{
return this.decoratedResolver.GetServices(serviceType);
}
}
}
首先,我的默认的答案是: -
我从来没有见过DI显示为的配置文件中的任何有趣统计学显著比例。 Go Compose!
(这篇文章以评论开始: - @olle你看过源代码吗?有一些相对简单的扩展可以“解决”解决过程,不应该太复杂。使用Mini Profiler并且很容易插入东西,这似乎是一个相对直接的扩展,我知道这是PITA在论坛上的回应,但我个人非常感激被告知要使用几年前的源代码 - Ninject代码库和它的测试是真正的快乐阅读。)
不,我明确地意识到答案。我偷看了源,我也想检查是否已经有一个现有的包装/功能等......我可能错过了。 – olle 2012-04-04 10:49:48
@olle酷。很高兴有一个圣雷莫给予真正的答案,但:D – 2012-04-04 10:52:32
- 1. 未在ASP.NET中使用Web应用程序的配置文件
- 2. 在web应用程序中配置log4j2
- 3. 在Spring Web应用程序中处理配置文件
- 4. 在wpf web应用程序中加载配置文件
- 5. 将Ninject IKernel存储在Web应用程序中的位置?
- 6. Maven + Web应用程序中的Pgsql配置文件
- 7. MVC3 Web应用程序直接在index.cshtml
- 8. PersistenceUnit在JAR文件中配置在web应用程序上下文
- 9. 如何使用Ninject(MVC3 Web应用程序)在构造函数中设置属性或变量?
- 10. 将ServiceLoader配置文件放在Web应用程序中的位置
- 11. 使用web应用程序配置PrimeUI
- 12. 移动web应用程序的配置文件
- 13. 如何在ASP.NET MVC Web应用程序中使用Ninject?
- 14. 在Web应用程序的AppDomain中使用Ninject和WCF服务?
- 15. iPhone应用程序配置文件
- 16. iOS应用程序配置文件
- 17. IIS Web应用程序和类库配置 - 配置文件部署时丢失
- 18. AngularJS应用程序配置文件
- 19. 应用程序文件缺失配置
- 20. Flask应用程序的配置文件
- 21. java web应用程序配置
- 22. 应用程序配置文件形成
- 23. 在asp.net web应用程序中处理配置设置
- 24. MIX应用程序的配置文件为OTP应用程序
- 25. 部署MVC3 web应用程序
- 26. 配置ninject以使用azure
- 27. 在多个环境中部署Web应用程序的配置文件
- 28. 供应配置文件中的应用程序ID用于iPhone应用程序
- 29. 什么文件用于配置整个Web应用程序并影响整个Web应用程序?
- 30. 在Web应用程序中保留设置文件
+1 Doh!尼斯... – 2012-04-04 07:52:12
为了将来的参考,它确实不是ninject! – olle 2012-04-05 18:01:39