admin管理员组文章数量:1122846
If I create a regular VSIX project(not a community one)
add a tool window,
and then add Autofac Dependency Injection infrastructure. This works fine as expected.
I basically picked up the idea from this article by Akos Nagy.
My full working example is here.
Note the tool window is derived from ToolWindowPane and it has a dependency on the UserControl as follows.
public class TrialToolWindow : ToolWindowPane
{
/// <summary>
/// Initializes a new instance of the <see cref="TrialToolWindow"/> class.
/// </summary>
public TrialToolWindow(TrialToolWindowControl trialToolWindowControl) : base(null)
{
this.Caption = "TrialToolWindow";
// This is the user control hosted by the tool window; Note that, even if this class implements IDisposable,
// we are not calling Dispose on this object. This is because ToolWindowPane calls Dispose on
// the object returned by the Content property.
this.Content = trialToolWindowControl;
}
}
But then, I wanted to explore the same with community tool kit extension packages.
So I created a Community tool kit project with Toolwindow as follows. This is different from the above.
Note here the tool window derives from Community.VisualStudio.Toolkit.BaseToolWindow and looks as follows.
public class MyToolWindow : BaseToolWindow<MyToolWindow>
{
}
In this case again, the tool window has a dependency on User Control, and if it is hard coded(no DI) then it works fine.
Now I want to add Autofac infrastructure, and here is where the problem begins. The tool window does not show up. My project for this case is here
As tried to dig deeper into the BaseToolWindow class, I found that the problem is here when an object is newed up as follows.
_package = package;
_implementation = new T() { Package = package };
We know newing up stuff like that is a cardinal sin in DI, so I think is the problem.
But I am not sure the community development team did a mistake?
Or am I missing something here?
Is there some other/better way to do DI, that I am missing here?
本文标签:
版权声明:本文标题:Dependency Injection into Community Toolkit Visual Studio Extension ToolWindow is not working - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736304936a1932411.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论