An initializer function is used to ensure specific business logic is successfully executed on the same instance only once. This topic describes the structure and features of C# initializer functions.
The Init method
Function Compute provides the Init method to initialize your services. The Init
method is automatically called when a container starts in the background. The Init
method is called only once for each container.
The following code defines a simple Initializer functionInit
method:
public void Init(); //No context objects are contained.
public void Init(IFcContext context); //The context object is contained.
public static void Init(); //No context objects are contained.
public static void Init(IFcContext context); //The context object is contained.
Function name
The MyInitializer
parameter must correspond to the initializer
field that you specify when you add the initializer function. For example, if you
set initializer
to fcdotnetsample::fcdotnetsample.TestHandler::MyInitializer
when you create a function, after the initializer function is configured, Function
Compute loads the MyInitializer
function defined in the fcdotnetsample.TestHandler
file.
Features
- The
FunctionInitializer
andInitializationTimeout
parameters that are contained inFunctionParam
ofIFcContext
are specifically designed for initializer functions. If these two parameters are not specified, the initializer function is not executed. - Initializer functions do not return any value. Return logic appended to initializer functions does not take effect.