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 function
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.
MyInitializer parameter must correspond to the
initializer field that you specify when you add the initializer function. For example, if you set
fcdotnetsample::fcdotnetsample.TestHandler::MyInitializer when you create a function, after the initializer function is configured, Function Compute loads the
MyInitializer function defined in the
InitializationTimeoutparameters that are contained in
IFcContextare 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.