-
Notifications
You must be signed in to change notification settings - Fork 0
Services
Module Services provides the ability to expose simple C# class as the endpoint on the internet. There are to main ideas in design of these classes. First, each class acts as single-action-controller, so every action needs one class. And second, such a class is simple tagged with interfaces to decorate it with functionality. Let start with examples...
At first, we need the execute method, so the Services module will know what to call on the class.
public class HelloWorldHandler : IGet
{
public void Execute()
{
// Process request and provide response...
}
}
Implementing IGet
, we also notify module to execute this method when HTTP GET request arrives. For other HTTP methods, there are interfaces IPost
, IPut
and IDelete
(and others can be easily added).
So, we have the execute method, but we need to provide some output. This is realized using IWithOutput<T>
interface.
public class HelloWorldHandler : IGet, IWithOutput<string>
{
public string Output { get; private set; }
public void Execute()
{
Output = "Hello, World!";
}
}
...
Some tutorials and design ideas description...