Share via


Best Practices for Static Construct Methods

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.

Tip

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.

Example

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

See also

Best Practices for new and static new... Methods

Best Practices for Constructors

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