什么是 Caliburn 验证抽象
最近我看到这个文档指定了如何Caliburn 很棒(并不是真的将它与微框架进行比较,这就足够了)。 我在 Caliburn 工作了一年多,对它了解不多。
所以也许有人可以解释以下内容(其中一些我可以理解,但不知道与 caliburn 的关系):
- 验证抽象
- 模块框架
- 基于 ExpressionTree 的运行时委托生成
- ViewModelFactory
- ShellFramework
我正在使用 V1.1,所以如果有新内容2.0就说属于新版本吧,以后大概会学习的。
Recently I saw this document that specify how great is Caliburn(Not really it compares it to the micro framework, and thats enough).
I'm working with Caliburn for more than a year and don't know many things about it.
So maybe someone can explain the following(Some of it I can understand but have no iea about the relation to caliburn):
- Validation abstraction
- module framework
- ExpressionTree-Based runtime delegate generation
- ViewModelFactory
- ShellFramework
I'm working with V1.1 so if something is new in 2.0, just say it belong to the new version I'll learn it probably in the future.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
验证抽象的目的是在 ViewModel 中插入验证基础设施。
Caliburn 的
DefaultValidator
使用 System.ComponentModel.DataAnnotations,但也可以使用 Fluent Validation 的适配器。虽然验证可以直接从应用程序代码中使用,但框架主要在 AOP 验证行为中使用它,该行为为模型提供自动
IDataErrorInfo
实现。如果您的模型已经实现了
IDataErrorInfo
,Caliburn 就能够利用普通 WPF 绑定来挂钩验证(作为传统绑定过程的一部分)。然而,手动实现
IDataErrorInfo
很无聊,并且可能会导致难以维护的代码,因此引入了 AOP[ValidateAttribute]
。要启用它,您必须配置容器以使用可用的代理工厂(基于 Castle.DynamicProxy):
myContainerAdapter()
.WithProxyFactory
这指示容器适配器检查应用于从容器中拉出的 ViewModel(和其他组件)的行为属性,并创建它们的子类来实现指定的行为。
[Validate]
行为实现只是将“IDataErrorInfo”调用委托给实际的IValidator
服务。Caliburn 本身使用模块框架来管理其自身模块的配置和初始化。它还可以用于创建独立的应用程序模块:Caliburn 将负责发现它们(如果它们的程序集在 IAssemblySource 中注册)并驱动它们的初始化;
The validation abstraction is aimed to plug a validation infrastructure in ViewModels.
Caliburn's
DefaultValidator
uses System.ComponentModel.DataAnnotations, but an adapter for Fluent Validation is also available.While the validation could be used directly from application code, it is used by the framework mainly in the AOP validation behavior, which provides an automatic
IDataErrorInfo
implementation for models.If your models already implement
IDataErrorInfo
, Caliburn is able to hook the validation (as a part of conventional binding process) leveraging plain WPF binding.Yet, implementing
IDataErrorInfo
manually is boring and likely to lead to hardly mantainable code, so the AOP[ValidateAttribute]
was introduced.To enable it, you have to configure your container to use the available proxy factory (which is based upon Castle.DynamicProxy):
myContainerAdapter
.WithProxyFactory<Caliburn.DynamicProxy.DynamicProxyFactory>()
This instructs the container adapter to inspect behaviors attribute applied on the ViewModels (and other components) pulled from the container, and to create a subclass of them implementing the specified behavior.
The
[Validate]
behavior implementation just delegates 'IDataErrorInfo' calls to the actualIValidator
service.Module framework is used by Caliburn itself to manage configuration and initialization of its own modules. It could also be used to create independent application modules: Caliburn will take care of discovering them (if their assemblies are registered in IAssemblySource) an drive their initialization;
IResult
(along with fluent-style static methods to create them) and some pre-built ViewModels (Menus and Question/Message dialog) to accomplish common application tasks.