【问题标题】:Autofac integration with WCF : Passing BeginLifetimeScope() instead of ContainerAutofac 与 WCF 的集成:传递 BeginLifetimeScope() 而不是 Container
【发布时间】:2016-02-12 01:01:19
【问题描述】:

目前在我的应用程序代码中编写如下,我们面临内存泄漏问题

这里的容器保存了所有的图层对象,而不是重新释放它们。

var container = builder.Build()
host.AddDependencyInjectionBehavior(mainInterface, container);

我可以这样写吗,推荐吗

var container = builder.Build()
host.AddDependencyInjectionBehavior(mainInterface,container.BeginLifetimeScope()());

【问题讨论】:

  • @R J:你还没有提出你的问题?
  • 感谢您回答 CharithJ。我只想知道在 autofac 网站上,那里写着对于 WCF 与 autofac 的集成,需要编写以下代码。 var container = builder.Build() host.AddDependencyInjectionBehavior(mainInterface, container);我可以通过 container.BeginLifetimeScope() 而不是容器吗?
  • @R J:这两种/任何方法都适合你吗?我猜对你有用的东西应该没问题(不太确定)。在内存泄漏方面,请确保 Dispose LifetimeScope 。

标签: wcf memory-leaks autofac factory-pattern servicehost


【解决方案1】:

当您开始使用新的 LifetimeScope 时,请记住在完成后将其丢弃。在 LifetimeScope 释放期间,Autofac 释放它创建的所有 IDisposable 实例。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多