c# - ServiceStack auto query global filter -
i'm looking @ using servicestack's autoquery feature , have basic queries working. i'd implement global filter since have multi-tenanted database, e.g.,
all queries should appended criteria customerid = session.customerid
what best way this?
you potentially use custom autoquery base class append custom filter each query, e.g:
public abstract class myautoqueryservicebase : autoqueryservicebase { public override object exec<from>(iquery<from> dto) { var q = autoquery.createquery(dto, request); var session = base.sessionas<customusersession>(); q.and("customerid = {0}", session.customerid); return autoquery.execute(dto, q); } public override object exec<from, into>(iquery<from, into> dto) { var q = autoquery.createquery(dto, request); var session = base.sessionas<customusersession>(); q.and("customerid = {0}", session.customerid); return autoquery.execute(dto, q); } }
then tell autoquery use base class instead, e.g:
plugins.add(new autoqueryfeature { autoqueryservicebasetype = typeof(myautoqueryservicebase) });
Comments
Post a Comment