【发布时间】:2021-10-21 14:11:24
【问题描述】:
ASP.Net Webforms 应用程序 (.Net Framework 4.7.2) 引用了用 .Net 标准 2.0 编写的 dll。在 dll 中,我有一个接口 ISomething,它具有对 IAnother 的属性依赖。
使用 Autofac。在Global.asax Application_Start 我正在注册实现ISomething 和IAnother 的类。
在执行时,我确实得到了 ISomtething 的正确解析;但它的依赖 IAnother 最终是 null (我猜是未解决)。
我没有在ISometing 中添加任何 Autofac 代码行;刚刚将IAnother 添加为公共属性;我希望两者都能被Autofac.Web 代码自动解决。 (这是正确的吗?)
编辑:
我更改了实现 ISomething 的类的实现,以接收 IAnother 作为构造函数中的参数(而不是作为属性)......并且有效。
ISomething 是 WebForm 页面上的属性依赖项。 IAnother 作为对 ISomething 实现的属性依赖
ISomething 是对 WebForm 页面的属性依赖项。 IAnother 作为构造函数依赖于 ISomething 的实现
我想了解为什么它以一种方式而不是另一种方式工作。
【问题讨论】:
标签: asp.net webforms autofac .net-standard-2.0