c# – Autofac singleton dispose
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了c# – Autofac singleton dispose,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含952字,纯文字阅读大概需要2分钟。
内容图文
![c# – Autofac singleton dispose](/upload/InfoBanner/zyjiaocheng/810/6cc7c716177f4218b074b21b3858dd9c.jpg)
我只是想确保在Autofac中处理单身人士.如果我在Autofac中将组件注册为单例,那么在关闭应用程序时会触发Dispose方法吗?
目前,我在Startup中持有该组件,并在OnShutDown中调用它,我在OnAppDisposing中注册.认为用Autofac设置这个东西会更优雅
解决方法:
If you have singleton components (registered as SingleInstance()) they will live for the life of the container. Since container lifetimes are usually the application lifetime, it means the component won’t be disposed until the end of the application.
> 07001
如果希望Autofac在SingleInstance注册上调用Dispose方法,则必须在应用程序关闭时调用容器的Dispose方法.
这个github问题讨论了它:Should UseAutofacMiddleware dispose container on OWIN shutdown.
在Autofac Owin Integration的测试版中,您有一个DisposeContainerOnShutdown扩展方法.
从4.0版本的Autofac.Owin开始,您可以这样做:
app.DisposeContainerOnShutdown(container);
使用旧版本,您可以从AutofacAppBuilderExtensions.cs源代码复制/粘贴DisposeContainerOnShutdown方法
内容总结
以上是互联网集市为您收集整理的c# – Autofac singleton dispose全部内容,希望文章能够帮你解决c# – Autofac singleton dispose所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。