不使用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?