Ninject 可以注入一个类并使其引用目标类作为反向引用吗?
我想将演示者注入到我的网络表单类中。这样做时,我希望注入的演示者包含对其所注入的视图的引用。注入一个类并引用它所注入的类。用 Ninject 可以做到这一点吗?注入webforms类时,注入是在构造函数执行之前执行的吗?我应该只注入演示者并使用构造函数来传递视图吗?
I want to inject a presenter into my webform class. While doing so I would like the injected presenter to contain a reference to the view it is being injected into. Inject a class with a reference to the class it is injected into. Is it possible to do this with Ninject? When injecting into a webforms class, is the injection performed before the constructor is executed? Should I rather just inject the presenter and use the constructor to pass the view?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于 Web 表单,这是不可能的,因为该表单不是由 ninject 创建的。您必须手动将其传递给演示者。
我认为解决方案是使用 MVC,您可以从框架中支持您的问题。 Webform 和 MVC 可以混合使用。您可以使用 MVC 创建新页面,并仍然使用旧的 Webform 页面。当您必须更改 Web 表单页面时,最好在更改之前将其重构为 MVC。
For webforms this is not possible because the form is not created by ninject. You have to pass it manually to the presenter.
I think the solution is to use MVC there you have support for your problem form the framework. Webforms and MVC can be mixed. You can create new pages with MVC and still use the old webform ones. Whenyou have to change a webforms page then you better refactor it to MVC befor the change.