C# programming model
Cloud Functions provides two models for programming in C#: using the YcFunction interface and an independent class with a compatible method. Both models involve writing their own interface implementations and let you provide a function with one argument and one return value of any type.
The difference between these models lies in the presence of the invocation context. For example, if you need to interact with Yandex Cloud services using the SDK, we recommend choosing YcFunction.
Regardless of the selected model, a project is uploaded in one of the following ways: as a publishedcsproj
project or as a set of *cs
files with source code. The second option is suitable for handlers that have no external dependencies. In addition, the following requirements apply to a class that contains a handler function:
- It must be public.
- It must have a public constructor with no arguments.
By default, it is present. But if you created your own constructor that accepts arguments, you should also create a constructor that does not accept any arguments. - It should not be generic
.
Regardless of the selected model, the handler can be an async methodTask
or Task<T>
. For the option with the independent class, the async void
value can be returned.
In this case, there are two separate types: byte[]
and String
. Using them is slightly different from using other types. If you use them as the handler function argument type, the runtime will not convert an incoming request to a JSON
interpretation for these types and will deliver it directly to the user handler function. The exception is when the parameter ?integration=raw.