It seems that the controller must have a parameterless constructor in order for the framework to respond to calls. Is it possible to have a controller with parameters in the constructor ?
PS how are the two overloads of RegisterController used ? Can't find any example in the samples.
Here is my code:
public class RestController
{
private HttpServer httpServer;
public RestController(ILogger log, IRestControllerConfig config)
{
var restRouteHandler = new RestRouteHandler();
restRouteHandler.RegisterController<SubscribeController>(new { firstPortNumber = 9000});
var configuration = new HttpServerConfiguration()
.ListenOnPort(9000)
.RegisterRoute("api", restRouteHandler)
.EnableCors();
httpServer = new HttpServer(configuration);
}
public async Task StartServer()
{
await httpServer.StartServerAsync();
}
}
public class ServiceSubscription
{
public int PortNumber { get; set; }
public string[] Topics { get; set; }
}
[RestController(InstanceCreationType.Singleton)]
public class SubscribeController
{
private int nextPortNumber;
private List<ServiceSubscription> services;
public SubscribeController(int firstPortNumber) //No constructor parameters allowed ???
{
nextPortNumber = firstPortNumber;
services = new List<ServiceSubscription>();
}
[UriFormat("/subscribe")]
public IGetResponse Subscribe([FromContent]string[] topics)
{
var service = new ServiceSubscription
{
PortNumber = nextPortNumber++,
Topics = topics
};
//services.Add(service);
return new GetResponse(
GetResponse.ResponseStatus.OK,
1000/*service.PortNumber*/);
}
}
It seems that the controller must have a parameterless constructor in order for the framework to respond to calls. Is it possible to have a controller with parameters in the constructor ? PS how are the two overloads of
RegisterController
used ? Can't find any example in the samples.Here is my code: