# ModelBuilders - BuilderManagers
In the previous examples ModelBuilders were registered directly in the CustomizeTypesInfo method. As the number of ModelBuilders in an XAF module grows this has the potential to become a serious maintenace issue. To avoid this problem Xenial.Framework provides BuilderManagers.
# XafBuilderManager
To utilze BuilderManagers create a new class (by convention name it {ModuleName}BuilderManager) and derive it from the XafBuilderManager class. Within the class override the GetBuilders method to create an instance of the DemoTaskModelBuilder.
using System;
using System.Collections.Generic;
using System.Text;
using DevExpress.ExpressApp.DC;
using Xenial.Framework.ModelBuilders;
namespace MainDemo.Module.BusinessObjects
{
public class MainDemoBuilderManager : XafBuilderManager
{
public MainDemoBuilderManager(ITypesInfo typesInfo)
: base(typesInfo) { }
public MainDemoBuilderManager(ITypesInfo typesInfo, IEnumerable<IBuilder> builders)
: base(typesInfo, builders) { }
protected override IEnumerable<IBuilder> GetBuilders() => new IBuilder[]
{
TypesInfo.CreateModelBuilder<DemoTaskModelBuilder>()
};
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Registration
With that done register the DemoTaskModelBuilderManager in the CustomizeTypesInfo method and call Build.
using System;
using System.Collections.Generic;
using System.Linq;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.DC;
using Xenial.Framework;
using Xenial.Framework.ModelBuilders;
using MainDemo.Module.BusinessObjects;
namespace MyApplication.Module
{
public class MyApplicationModule : ModuleBase
{
public override void CustomizeTypesInfo(ITypesInfo typesInfo)
{
base.CustomizeTypesInfo(typesInfo);
new MainDemoBuilderManager(typesInfo)
.Build();
}
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# Summary
BuilderManagers are simple to use and the recommended way of working with ModelBuilders.
TIP
BuilderManagers have built-in optimizations to minimize any performance overhead.