1

is there a way to manage users with ServiceStack?

I've only found the IUserAuthRepository interface that has some methods to get a user by name, email and id. But how to get a list of users (with filters & co).

Thanks.

1 Answer 1

3

I think some of this depends on where and how you're storing you data.

If you are storing the data in a SQL database there should be 3 tables holding user data User, UserAuth, UserOAuthProvider. Most of the user data you want will probably be within the UserAuth table. At least, this is the table that seems to be mostly referenced with the 'OrmLiteAuthRepository'. To return a list of users (List<UserAuth>) using OrmLite you could do

using (IDbConnection con = DbConnectionFactory.OpenDbConnection())
{
    var users = con.Select<UserAuth>();
}

Or use whatever your preferred way of accessing is.

If you are not using a SQL database it will vary. I think you can do something like below for Redis. I don't think the 'configuration' is a straight forward but it looks like you start by accessing a Hash. There are two options for the 'HashId'. Use 'hash:UserAuth:Email>UserId' when email address is a key and 'hash:UserAuth:UserName>UserId' when username is a key. FYI, these values could change, but I'm not aware of a way to access them via ServiceStack code.

using (IRedisClient client = RedisClientManager.GetClient())
{
    var userskeys = client.GetHashKeys("hash:UserAuth:Email>UserId").ToList();
    var users =  userskeys.Select(k => client.As<UserAuth>().GetById(k)).ToList();
}
1
  • Thanks for your answer. I thought there was a standard way in ServiceStack that works with every repository. I'm using RavenDB so this should be easy.
    – dna
    Apr 24, 2013 at 12:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.