Best Practices for Static Construct Methods [AX 2012]

Updated: December 2, 2011

Applies To: Microsoft Dynamics AX 2012 R3, Microsoft Dynamics AX 2012 R2, Microsoft Dynamics AX 2012 Feature Pack, Microsoft Dynamics AX 2012

You should create a static construct method for each class. Warning icon The method should return an instance of the class.

The construct method must be:

  • static

  • named "construct"

In most cases the construct method should be public. If the class is instantiated using a newParameter method, then declare the construct method as private. The method should return an instance of the class and contain no other code. construct methods should not have any parameters, or else should have the same parameters as the default new constructor (it is recommended that you do not have parameters on new). Warning icon

If your class declaration contains parameters, use a static new method as the constructor and use the construct method within the static new method to create an instance of the class.

For partners and customizers, this is the point to add construction functionality for new subclasses (in higher layers), without mixing code with the construct method in the original layer.

TipTip

You can use a code editor script to create the construct method for you. In the code editor, press Alt + M to open the editor scripts menu, and then select template > method > construct.

static CustPaymManFileOpen construct()
{
    return new CustPaymManFileOpen();
}

Announcements: New book: "Inside Microsoft Dynamics AX 2012 R3" now available. Get your copy at the MS Press Store.

Community Additions

ADD
Show: