As an alternative to creating handlers for each specific resource type it is also
possible to implement an IPomonaDataSource
.
A data source will be used when registered for in the IoC container.
IPomonaDataSource
has the methods Patch<T>
, Post<T>
and Query<T>
, where T
is the
resource type for the current request.
internal class SimpleDataSource : IPomonaDataSource
{
private static readonly IList<SimpleExtraData> repository = new List<SimpleExtraData>()
{
new SimpleExtraData { Id = 0, TheString = "What" },
new SimpleExtraData { Id = 1, TheString = "The" },
new SimpleExtraData { Id = 2, TheString = "BLEEP" }
};
public object Patch<T>(T updatedObject) where T : class
{
var simpleData = updatedObject as SimpleExtraData;
repository[simpleData.Id] = simpleData;
return simpleData;
}
public object Post<T>(T newObject) where T : class
{
var simpleData = newObject as SimpleExtraData;
simpleData.Id = repository.Count;
repository.Add(simpleData);
return simpleData;
}
public IQueryable<T> Query<T>() where T : class
{
return repository.Cast<T>().AsQueryable();
}
}