Implementing validation rules

All business rules must be implemented in the Business layer. Validation rules that are related to business entities can be implemented in two ways:

  • If the rule only applies to a single entity and doesn’t need to access other entities of the unit of work in order to be checked then it shall be defined in the Validation.Extensions namespace, in an extension method for the validated entity type with the following signature: Validate(fieldName : string) : IEnumerable<ValidationError>. The keepitsoftvalidationextension snippet may be used to create such a class.
  • If the rule needs to access other entities of the unit of work in order to be checked then it shall be defined in the Business.Validation namespace, in a class that implements the IValidator<TEntity> interface. For more information about this interface, please refer to the source code help file. The keepitsoftvalidator snippet may be used to create such a class.

Extending generated repositories

All generated repositories (one for each entity type) inherit the same base class which implements the KeepItSoft.Fwk.Core.Data.IRepository interface. In order to add a method to a repository, please follow the following steps :

  • Under the Partial folder of the Data.Repository.Interfaces project, create a partial interface for the repository you want to extend.
  • Define your method in this interface.
  • Under the Partial folder of the Data.Repository project, create a partial class for the repository you want to extend.

Implement your method in this class.

Creating a classic collection view

To display a collection of records in the UI.WPF.Views project, please follow the following steps :

  • Under the Collection Views folder, create a new UserControl
  • Modify the new class’ namespace so that it matches the value of the _viewsNamespace field of the MainWindow class.
  • Make your class inherit from the CollectionViewUserControl<TModel, TViewModel, TDetailView> class, which is implemented in the WPF.Core namespace.
  • Replace the generic parameters with types that relate to the entities you want to display (e.g. : to display a collection of Person entities, inherit from CollectionViewUserControl<Person, PersonViewModelBase, PersonDetailView>).
  • In the base constructor call, you can inject filter parameters.
  • In the constructor, call the LoadData method with your datagrid instance as a parameter.

In a next post, I’ll show you how to use the alternate version of the CollectionViewUserControl class in order to either improve performance or just to have different ViewModel types between your collection and detail views.

Message boxes from a ViewModel

WPF, Silverlight and Windows portable technologies all have their own implementation of a message box. In order to keep the ViewModels project technology-independent, any reference to a specific message box type is prohibited. If you want to show a message box from the ViewModels project, you can use the MessageBoxHelper.Show method. It is a service locator that needs to be initialized with the type you want to use for your message boxes. The method has one single parameter of type KeepItSoft.Fwk.Core.DialogEventArgs.

Naming conventions

Naming conventions are very important to ease application maintenance. Good naming conventions allow developers to quickly know the type of object they are working on. All types and their members shall be named in English so that any team member can understand them. You’ll find here below the conventions that we use in our framework and application templates. Given that C# is case-sensitive, it is important to respect the case of the following naming conventions to avoid any confusion.

Classes

  • Convention : Pascal case
  • Example : MyClass

Methods

  • Convention : Pascal case
  • Example : MyMethod

Properties

  • Convention : Pascal case
  • Example : MyProperty

Fields

  • Convention : Camel case
  • Prefix : _
  • Example : _myField

Parameters

  • Convention : Camel case
  • Example : myParameter

Constants

  • Convention : Uppercase
  • Word separator : _
  • Example : MY_CONSTANT

Language Resources

  • Convention : Pascal case
  • Resource types :
    • Inline text
      • Common use : TextBlock, Label
      • Prefix : Label_
      • Example : Label_MyText
    • Header :
      • Common use : DataGrid header, TabItem header
      • Prefix : Header_
      • Example : Header_MyTextHeader
    • Button :
      • Common use : Button text
      • Prefix : Button_
      • Example : Button_MyButtonLabel
    • Menu :
      • Common use : Menu labels
      • Prefix : Menu_
      • Example : Menu_MyMenuLabel
    • Error :
      • Common use : Error messages that are displayed in a message box or in a view
      • Prefix : Error_
      • Example : Error_MyErrorMessage
    • Enumeration value :
      • Common use : ComboBox
      • Prefix : Enum_
      • Parameter separator : _
      • Parameters : Enumeration type name, enumeration value name
      • Example : Enum_MyEnumerationType_MyEnumerationValue1