Is there anyway to implement an repository that uses active directory (or any other data source than relational db) as the data source and can get entity objects that has the ability to lazy load their associations?
An example:
Two classes will be frequently used in various applications we are going to develop
class User
{
public string DisplayName {get; set;}
public string UserID {get; set;}
public string Email {get; set;}
public string WorkPhone {get; set;}
// etc.
public string IList<Group> Groups {get; private set;}
public User Manager {get; set;}
}
class Group
{
public string DisplayName {get; set;}
public string Email {get; set;}
// etc.
public IList<User> Members {get; private set;}
public User Owner {get; private set;}
}
I want to be able to reuse these two classes in all our future applications. For some application, the data source for User
and Group
would now be active directory, but in the future, we may wanna use some database or a mixture of database and active directory. In order for code reuse, I would employ the repository pattern to design two repositories MySqlDBRepository
and ActiveDirectoryRepository
for me to retrieve and store User
s and Group
s.
Suppose we already have a library for active directory, which can be used to get user information represented in texts, i.e. you can get user's name, email, manager id all in string format. I need to implement a repository that can be used in much the same way as Entity framework or NHibernate, i.e.
var user = _activeDirectoryRepository.GetUserByUserID("bryan");
foreach(var group in user.Groups)
Console.WriteLine(group.Manager.DisplayName);
Most importantly, user.groups
and group.Manager
both should be lazy-loading automatically. How am I supposed to implement _activeDirectoryRepository.GetUserByUserID("bryan")
?