Avectra.netForum.Data.DataUtils.InstantiateFacadeObject

Method to instantiate a FacadeClass based on its Object metadata reference.

Parameters

Object Name or Key:

  • Name (string). The object name.
  • Key (string). The Key (guid) of the Object.

Usage and Examples

For baseline Avectra objects, the ideal way to instantiate the object is by using its method in the Avectra.netForum.Data.FacadeObjectFactory singleton class:

CreditDetail oCreditDetail = (CreditDetail)FacadeObjectFactory.CreateCreditDetail();
   

If there isn't a method for the particular class in FacadeObjectFactory, then the correct usage for a Static Facade Object is:

FacadeClass oRegistrant = (Registration)DataUtils.InstantiateFacadeObject("EventsRegistrant");
   

The correct usage for a Dynamic Facade Object is:

FacadeClass oFacade = DataUtils.InstantiateFacadeObject("NameOfObject");
   

Incorrect way to instantiate a static facade object:

/// Do NOT instantiate directly from baseline static facade class!
Avectra.netForum.EV.Registration oRegistrant = new Avectra.netForum.EV.Registration();
   

Always instantiate objects through DataUtils.InstantiateFacadeObject with the object name as the parameter; do NOT directly instantiate the object from the class (as shown in the 3rd example).

Why? Because the Object definition in the metadata might actually reference a different class, such as a customized sub-class that inherits from the base class. For example, in a particular netFORUM instance, the baseline Registration class may have been overridden by a customized ABCRegistration class. If you instantiate the object from metadata using InstantiateFacadeObject, then the netFORUM framework will correctly instantiate the object from the ABCRegistration class. But if you follow the last example, you will obviously circumvent any custom business rules in the ABCRegistration class and that will lead to problems when custom code does not fire as expected.

Observe how in the first and second examples we cast the object to a Registration object. This may be needed if you need to call specialized methods in the Registration object and not a more generic FacadeClass object. Even though you instantiate to a Registration object, if the metadata specified a ABCRegistration object, the casted object will still be of the ABCRegistration type (note: this is not a netFORUM-specific rule, this is classic object inheritance in .NET).

Technically, if you have customized a baseline class, you could instantiate the custom object directly, as in:

ABCRegistrant oRegistrant = new ABCRegistrant();
   

Although this will work, we still recommend using the first example above both for consistency and because there's always the chance that a custom object will be replaced with a different custom object in the metadata, or even reverted back to the baseline object.

See Also