Server properties #50
-
Hi, in GV5, is it still possible to do : var prop = context.Server.GetPropertyValueAs<XXXX>("Prop"); I couldn't find anything like that... |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
These are called string prop1 = server.Locals.GetAs("Prop1");
string prop2 = context.Locals.GetAs("Prop2");
// or
var prop3 = server.Locals.GetAs<string>("Prop3");
var prop4 = context.Locals.GetAs<string>("Prop4"); However, as of the latest release, the [RestResource]
public class MyResource
{
private IRestServer _server;
public MyResource(IRestServer server)
{
_server = server;
}
[RestRoute("Get", "/prop")]
public async Task GetCookie(IHttpContext context)
{
var serverProp = _server.Locals.GetAs<string>("ServerPropertyName");
var ctxProp = context.Locals.GetAs<string>("ContextPropertyName");
}
} Because the instance of The intention is that this approach will allow you to attach any kind of arbitrary data to anything that has a Locals property on it, and retrieve it later. In the case of the server, you can attach anything that is specific to the server. In the case of the |
Beta Was this translation helpful? Give feedback.
These are called
Locals
now instead ofDynamicProperties
, to match the lingo used in ExpressJS from whence they are insipred. Locals are available on theIRestServer
interface and theIHttpContext
interface.However, as of the latest release, the
IHttpContext
interface does not contain anIRestServer
property. Which is to say that thecontext.Server
property you reference above doesn't exist anymore. But you can inject it into your class, and you already get this for free!