This project is read-only.

Better way to get user repository

Nov 23, 2010 at 12:08 PM
Edited Nov 23, 2010 at 12:09 PM


I'm writing a module that needs to search users repository by name (start with). At the moment I reference the Orchard.Users\bin\Orchard.Users.dll in my project so that I can access IRepository<UserPartRecord> in the service.

What's a better way to get user repository without referencing users module (something with IUser interface maybe)? Is there any method to get repository by table name string "Orchard_Users_UserPartRecord"?



Nov 23, 2010 at 3:51 PM

You should not try to reference a module, as long as there is a common service interface available. In your case it is IMembershipService. So in the constructor of your service, use an argument of this type, like other services, and you will be to use it. You can then manage IUser instances.

If you need a method which is currently not available then you should suggest it to us in order to study the need.

Nov 23, 2010 at 5:45 PM

Or submit a patch with the new method :)

Nov 24, 2010 at 6:08 AM
Edited Nov 24, 2010 at 7:31 AM

I am developing ajax auto complete box control where user can select multiple different users. When user is typing a text, autocomplete box automatically suggests users.

I need method to serach users by username (start with):


	public IEnumerable<IUser> FindUsers(string searchText)
		return _contentManager.Query<UserPart, UserPartRecord>().Where(u => u.NormalizedUserName.StartsWith(searchText)).List<IUser>();

Maybe it would be more usefull to have a common method with custom criteria parameter List<IUser> FindUsers(Criteria) but I dont know how to specify common criteria. First I tried to specify it with Expression<Func<TRecord>>, but you don't have TRecord type of record in interface.

What is your opinion?