AzureFunction class abstract

Abstract Azure Function, that acts as a container to instantiate and run components and expose them via external entry point.

When handling calls 'cmd' parameter determines which what action shall be called, while other parameters are passed to the action itself.

Container configuration for this Azure function is stored in './config/config.yml' file. But this path can be overriden by CONFIG_PATH environment variable.

References

  • *:logger:*:*:1.0 (optional) ILogger components to pass log messages
  • *:counters:*:*:1.0 (optional) ICounters components to pass collected measurements
  • *:controller:azurefunc:*:1.0 (optional) IAzureFunctionController controllers to handle action requests
  • *:controller:commandable-azurefunc:*:1.0 (optional) IAzureFunctionController controllers to handle action requests

See AzureFunctionClient

Example

    class MyAzureFunction extends AzureFunction {
        IMyService _service;
        ...
        MyAzureFunction()
            super('mygroup', 'MyGroup Azure function'){
            dependencyResolver.put(
                'service',
                Descriptor('mygroup','service','*','*','1.0')
            );
        }

        void setReferences(IReferences references) {
            super.setReferences(references);
            _service = dependencyResolver.getRequired<IMyService>('service');
        }

        Future getMyData(params) async {
          return await _service.getMyData(params['trace_id'],
            params['id']),
        }

        void register() {
        registerAction(
          'get_mydata',
          ObjectSchema(true).withOptionalProperty('id', TypeCode.String),
          getMyData);
        }
            ...
    }

    var azureFunction = MyAzureFunction();

    await azureFunction.run();
    print('MyAzureFunction is started');

    var result = await azureFunction.act({'cmd': 'get_dummies'});
    print(result);
Inheritance
Implementers

Constructors

AzureFunction([String? name, String? description])
Creates a new instance of this Azure function.

Properties

actions Map<String, Future Function(Map<String, dynamic>)>
The map of registered actions.
read / write
config ContainerConfig?
read / writeinherited
configPath String
The default path to config file.
read / write
counters CompositeCounters
The performanc counters.
final
dependencyResolver DependencyResolver
The dependency resolver.
final
factories DefaultContainerFactory
read / writeinherited
hashCode int
The hash code for this object.
read-onlyinherited
info ContextInfo?
read / writeinherited
logger ILogger
read / writeinherited
references ContainerReferences?
read / writeinherited
runtimeType Type
A representation of the runtime type of the object.
read-onlyinherited
schemas Map<String, Schema>
The map of registred validation schemas.
read / write
tracer CompositeTracer
final

Methods

act(Map<String, dynamic> context) Future
Calls registered action in this Azure function. 'cmd' parameter in the action parameters determin what action shall be called.
addFactory(IFactory factory) → void
Adds a factory to the container. The factory is used to create components added to the container by their locators (descriptors).
inherited
close(IContext? context) Future
Closes component and frees used resources.
inherited
configure(ConfigParams config) → void
Configures component by passing configuration parameters.
inherited
getCommand(Map<String, dynamic> context) String
Returns command from Azure Function context. This method can be overloaded in child classes
getHandler() Future Function(Map<String, dynamic> context)
Gets entry point into this Azure function.
getTraceId(Map<String, dynamic> context) String
Returns context from Azure Function context. This method can be overloaded in child classes
instrument(IContext? context, String name) InstrumentTiming
Adds instrumentation to log calls and measure call time. It returns a Timing object that is used to end the time measurement.
isOpen() bool
Checks if the component is opened.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
open(IContext? context) Future
Opens the component.
override
readConfigFromFile(IContext? context, String path, ConfigParams parameters) Future
Reads container configuration from JSON or YAML file and parameterizes it with given values.
inherited
register() → void
Registers all actions in this Azure function.
registerAction(String? cmd, Schema? schema, Future action(Map<String, dynamic>)) → void
Registers an action in this Azure function.
registerControllers() → void
Registers all Azure controllers in the container.
run() Future
Runs this Azure function, loads container configuration, instantiate components and manage their lifecycle, makes this function ready to access action calls.
setReferences(IReferences references) → void
Sets references to dependent components.
override
toString() String
A string representation of this object.
inherited
unsetReferences() → void
Unsets (clears) previously set references to dependent components.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited