# ModelBuilders - Introduction

Xenial. Framework's Modelbuilders follow an imperative/procedural (opens new window) method to add metadata and attributes to the excelent XAF TypesInfo system (opens new window).

They are based upon a Fluent Interface Pattern (opens new window) highly influenced by EntityFramework's ModelBuilder's (opens new window).

ModelBuilders are one of the many NonVisual Components of Xenial.Framework designed to promote best practice and efficient working in large teams, which in turn are equally applicable to smaller teams and projects and even individuals working on a single application.

# Installation

In your platform agnostic module (opens new window) install the Xenial.Framework (opens new window) package.

INFORMATION

By convention the platform agnostic module is usually named <Your Application>.Module. If you're unfamiliar with the Command Line Interface (cli) you can always use the Nuget package manager.

Whilst the Xenial.Framework can of course be used in platform specific modules, for the purposes of this documentation emphasis will be given to its use in the platform agnostic module of your project.

# Using ModelBuilders

There are several ways to use ModelBuilders in your application ranging from a fluent inline approach to a complete buddy type (opens new window) (essentially a secondary utility class that specifies the metadata for a business object).

To illustrate these approaches to using ModelBuilders consider the following XPO business class (opens new window) based on the Contact/Task Management XAF Demo.

using System;
using DevExpress.ExpressApp.ConditionalAppearance;
using DevExpress.ExpressApp.Model;
using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl;
using DevExpress.Persistent.Validation;
using DevExpress.Xpo;

namespace MainDemo.Module.BusinessObjects
{
    [DefaultClassOptions]
    [ModelDefault("Caption", "Task")]
    public class DemoTask : BaseObject 
    {
        public DemoTask(Session session) : base(session) { }

        [ToolTip("View, assign or remove contacts for the current task")]
        [Association("Contact-DemoTask")]
        public XPCollection<Contact> Contacts
        {
            get
            {
                return GetCollection<Contact>(nameof(Contacts));
            }
        }
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

INFORMATION

Xenial.Framework ModelBuilders can also be used in NonPersistent classes and EntityFramework classes but for clarity this documentation will concentrate on expressPersistentObjects (XPO) business objects..

# Naming Conventions

Before continuing the following points about the naming conventions used in the code examples should be noted.

If the attribute is singular or it describes an attribute of a business object, it will start with the term Has.
If the attribute is plural or it describes the behavior of a business object, it will start with the term With.

TIP

There are a lot of Built-in Attributes provided by Xenial. If you are missing one, that should be built into the framework, let us know (opens new window)!