不使用MEF等依賴注入技術的架構設計
- Views,按功能劃分組織用戶控件文件
- Business,業務邏輯
- DAL,數據庫ORM中間層
- Infrastructure,基礎架構工具
- Log facility
- Json Helper classes
- Design Pattern Helper classes
- Basic Converters
關于Resource Dictionary
Resource dictionaries are usually defined in the App.xaml. 不過根據[Ref-2]的方式,我們在架構中希望將資源定義在獨立的模塊中,然后從其他模塊引用它。與[Ref-2]不一樣的是,我們將資源統一包含在Shell項目的App.xaml中,所以我們還需要解決設計期資源字典訪問問題。
why views can consume app.xaml even if they’re defined on a separate project
[Ref-1].
Resources defined in the App.xaml become available in the Application.Resources ResourceDictionary of the current Application class (which can be accessed through the Application.Current static property.) Once they’re available there, they can be consumed from within the XAML as static resources. Since modules are loaded into the same application domain as the Shell project, views defined there can access resources as long as they can be found in the corresponding Application.Resources dictionary.
在模塊中定義資源,在其他模塊(Shell)中訪問
[Ref-2]中是任意的UserControl中自定義資源引用,我們需要在Shell中統一引用資源,則在Shell的App.xaml中添加如下代碼:
<pre><ResourceDictionary Source="pack://application:,,,/TradeStation.Infrastructure;component/Resources/Generic.xaml"></ResourceDictionary></pre>
值得注意的是,[Ref-2]說使用“Generic.xaml
”作為名字有“huge benifits”,這個好像
設計期資源引用
在Shell的App.xaml中統一定義資源字典的一個問題是,VS在設計期無法正確的處理。
[Ref-3]涉及到了這個問題,但是好像沒有太簡單、一次性的解決方案。最終的解決方案還是在每一個UserControl中的Resources中添加與App.xaml中一樣的一行:
<pre><ResourceDictionary Source="pack://application:,,,/TradeStation.Infrastructure;component/Resources/Generic.xaml"></ResourceDictionary></pre>
題外話:define resource dictionaries that are specific to a certain module
[Ref-1]
參考資料
[1]《How to: define module-specific resource dictionaries in Prism》介紹了利用模塊中的app.xaml來實現
[2] https://stackoverflow.com/a/8594334/351993
[3] How to use resource dictionary in prism modules at design time?