Search code examples
caliburn

What is Caliburn Validation abstraction


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):

  1. Validation abstraction
  2. module framework
  3. ExpressionTree-Based runtime delegate generation
  4. ViewModelFactory
  5. 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.


Solution

    1. 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 actual IValidator service.

    2. 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;

    3. Caliburn doesn't use reflection to invoke action, but builds delegates on the fly leveraging Expression Trees to create a compiled lambda;
    4. The ViewModelFactory service is used by Caliburn to abstract the creation of VM, either by type or by Subject handled;
    5. ShellFramework contains a set of facility useful to build most applications; it includes some custom 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.