An initializer function is used to ensure certain business logic to be successfully executed on a Docker instance only once. This topic describes the structure and features of C# initializer functions.
Function Compute provides the Init method to initialize your business logic. The
Init method is automatically called when the container starts in the background. The Init
method is called only once for each container.
The following shows the definition of the
Init method for 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 must correspond to the
initializer field that you specify when you enable the initializer feature. For example, if you
fcdotnetsample::fcdotnetsample.TestHandler::MyInitializer when you create a function, after the initializer feature is configured, Function
Compute loads the
MyInitializer function defined in the
FunctionParamare designed specially for initializer functions. If these two fields are not specified, the initializer function will not be executed.
- Initializer functions do not return any value. Return logic appended to initializer functions does not take effect.