【问题标题】:Is there way how to test the Lifetime of service resolved from DependecyResolver?有没有办法测试从 DependecyResolver 解析的服务生命周期?
【发布时间】:2012-11-07 15:30:17
【问题描述】:

在 Asp.Net WebApi 中是由 DependecyResolver 组成的 GlobalConfig 对象。 DependecyResolver 保存有关 DI 框架指定的实例的信息。

我只是好奇是否有人找到了从这个 DependecyResolver 测试已解决服务的生命周期的方法?

仅供参考...我使用 Castle.Windsor 作为 DI 框架。以与http://www.asp.net/web-api/overview/extensibility/using-the-web-api-dependency-resolver 中指定的类似方式实现

任何帮助表示赞赏。谢谢。

【问题讨论】:

    标签: dependency-injection asp.net-web-api


    【解决方案1】:

    MVC 和 WebApis DependencyResolver 的区别在于 WebApis 版本有一个范围定义。范围在请求到达时创建,在请求结束时释放。

    这意味着所有配置为作用域的服务仅在 HTTP 请求/响应期间存在。 (如果您的 IoC 容器没有错误)

    实际定义可以在这里找到:http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/2be68e50ed73#src%2fSystem.Web.Http%2fDependencies%2fIDependencyResolver.cs

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-27
      • 2015-08-11
      • 2012-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-22
      • 1970-01-01
      相关资源
      最近更新 更多