简体   繁体   中英

Mapping custom route to nested object properties

Given the following DTOs:

[DataContract]
public class Foo
{
    [DataMember]
    public string Boo { get; set; }
    [DataMember]
    public string Far { get; set; }
}

[DataContract]
public class Bar
{
    [DataMember]
    public Foo Test { get; set; }

    // other members
}

I would like to add a route like:

Add<Bar>("/...(other members).../{Test.Boo}/{Test.Far}/

Is this possible? If so, how would the situation change if

[DataMember]
public Foo Test { get; set; }

was changed to:

[DataMember]
public Foo[] Test { get; set; }

?

You can't map to nested properties in routes. For general service API design you should be aiming to keep your DTO as flat as possible, as it's more accessible to clients.

Although ServiceStack does allow you to send complex types via the QueryString using the JSV Format (ie JSON without quotes).

So you could do:

Routes.Add<Bar>("/bar");

And be able to call your service with:

/bar?Test={Foo:foo,Bar:bar}

See this answer on further details about Routing in ServiceStack .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM