![](/img/trans.png)
[英]Castle.Windsor - why does the name needs to be similar to the interface?
[英]Castle.Windsor: ResolveAll with name
我不熟悉IoC使用Castle.Windsor。 現在,我想注冊UI元素以插入主表單(SWF)中的某些點。 因此,我有樹節點可將這些元素注入到其中,例如Application.MainWindow.Navigation.MyModule。 運用
container.Register(Component
.For<System.Windows.Forms.Control>()
.ImplementedBy<MyControlClass>()
.Named("Application.MainWindow.Navigation.MyModule") // this is the plug-in path
.LifestyleTransient());
應該做到這里。
在應用程序主窗體內部,我需要訪問容器內的控件並評估它們存儲的路徑。 但據我所知,通過迭代
container.ResolveAll<Control>()
我不會將路徑設置為每個UI元素的名稱。
有什么方法可以訪問這條路徑,或者甚至有更好的方法(使用Castle)嗎?
提前致謝。 :)
您可以使用OnCreate
自定義Castle.Windsor如何創建組件。可以為類MyControlClass
定義一個名為Path
的屬性,並像這樣初始化它(偽代碼)
container.Register(Component
.For<System.Windows.Forms.Control>()
.ImplementedBy<MyControlClass>()
.Named("Application.MainWindow.Navigation.MyModule") // this is the plug-in path
.LifestyleTransient()
.OnCreate((myControlClass) => myControlClass.Path = "Application.MainWindow.Navigation.MyModule")
);
這樣,您可以在注冊過程中自定義組件的創建。 您可以使用一系列操作,這些操作將在解析和將組件重新調整為代碼之間應用
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.