Access to RestServer in RestResources class #90
-
RestResources in older versions seem to inherit the RestServer (Server property) from a base class. I run multiple instances of RestServer and need the RestResources to behave a little different for each RestServer instance. Any hints on how to pass RestServer into RestResources? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Seems Scott has already answered my question on another thread; #Helps to read discussion #50You can use a constructor and a field... thats it. "Because the instance of IRestServer is already registered in the service collection used by the router (this happens automatically) as a singleton, you don't need to do any more wiring up for this to work." |
Beta Was this translation helpful? Give feedback.
-
You can inject the server via your constructor, as seen in the private readonly IRestServer _server;
public YourResource(IRestServer server)
{
_server = server;
} |
Beta Was this translation helpful? Give feedback.
You can inject the server via your constructor, as seen in the
HelloResource
in the sample project.