0
/Person/1 및/Person/Blair가 사람을 구하려면 어떻게 할 수 있습니까?OpenRasta Route Constraints
구성 클래스 :
public class RastaConfiguration : IConfigurationSource
{
public void Configure()
{
using (OpenRastaConfiguration.Manual)
{
ResourceSpace.Has.ResourcesOfType<List<Subject>>()
.AtUri("/Subject")
.HandledBy<SubjectHandler>()
.TranscodedBy<JsonDataContractCodec>();
ResourceSpace.Has.ResourcesOfType<List<Person>>()
.AtUri("/Person").And.AtUri("/Person/{name}")
.HandledBy<PersonHandler>()
.TranscodedBy<JsonDataContractCodec>();
ResourceSpace.Has.ResourcesOfType<Person>()
.AtUri("/Person/{id}")
.HandledBy<PersonHandler>()
.TranscodedBy<JsonDataContractCodec>();
}
}
}
및 핸들러
public class PersonHandler
{
private static readonly List<Person> People = new List<Person>
{
new Person {Id = 1, Name = "Blair Davidson", Subjects = new List<Subject>
{
new Subject{ Name = "Maths"}
}},
new Person {Id = 2, Name = "Esther Hew", Subjects = new List<Subject>
{
new Subject{ Name = "Chinese"}
}}
};
public IEnumerable<Person> Get()
{
return People;
}
public IEnumerable<Person> GetByName(string name)
{
return People.Where(x => x.Name.Contains(name)).ToList();
}
public Person GetById(int id)
{
return People.SingleOrDefault(x => x.Id == id);
}
public OperationResult Post(Person person)
{
People.Add(person);
return new OperationResult.Created
{
ResponseResource = person
};
}
}
의 asp.net MVC와 같은 제약을 사용하는 방법이 있나요?
도움을 주시면 감사하겠습니다.