Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3341866
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:46:19+00:00 2026-05-18T00:46:19+00:00

Is there anyway to implement an repository that uses active directory (or any other

  • 0

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 Users and Groups.

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")?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T00:46:19+00:00Added an answer on May 18, 2026 at 12:46 am

    After some thought, I found this solution might be good.

    Along with ActiveDirectoryUserRepository, I can create a internal class ProxyUser that inherits from User, which takes a reference to the ActiveDirectoryUserRepository. The ProxyUser should return the Groups property the first time it is invoked.


    // User.cs
    public class User
    {
        public virtual string Name { get; set; }
        public virtual string DisplayName {get; set;}
        public virtual string Email { get; set; }
    
        public virtual IList<Group> Groups { get; set; }
    }
    

    // Group.cs
    public class Group
    {
        public virtual string Name { get; set; }
        public virtual string Email { get; set; }
    
        public virtual IList<User> Members { get; set; }
    }
    

    //  ProxyUser.cs. It should be in the same assembly as ActiveDirectoryUserRepository 
    
    internal class ProxyUser : User
    {
    
       private ActiveDirectoryUserRepository _repository ;
       internal ProxyUser(ActiveDirectoryUserRepository repository)
       {
           _repository = repository;
       }
    
       internal string IList<string> GroupNames { get; set; }
    
       private IList<Group> _groups;
       public override IList<Group> Groups 
       { 
          get
          {
             if (_groups == null)
             {
                if (GroupNames != null && GroupNames.Count > 0)
                {
                    _groups = new List<Group>();
                    foreach(string groupName in GroupNames)
                       _groups.Add(_repository.FindGroupByName(groupName);
                }
             }
             return _groups;
           }
    
           set
           {
               _groups = value;
           }
        }
    }
    

    // ProxyGroup.cs
    
    internal class ProxyGroup : Group
    {
        // This class should be similar to ProxyUser
    }
    

    // ActiveDirectoryUserRepository.cs
    
    public class ActiveDirectoryUserRepository
    {
        public User FindUserByName(string name)
        {
             DirectorySearcher searcher = new DirectorySearcher();
    
             // ...
             // set up the filter and properties of the searcher
             // ...
    
             Result result = searcher.FindOne();
             User user = new ProxyUser(this)
             {
                 Name = result.Properties["displayName"][0],
                 Email = result.Properties["email"][0],
                 GroupNames = new List<string>()
             };
    
             foreach(string groupName in result.Properties["memberOf"])
             {
                 user.GroupNames.Add(groupName);
             }
    
             return user;
        }
    
        public Group FindGroupByName(string name)
        {
            // Find the Group, which should be similar to FindUserByName
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there anyway to use a bounded wildcard require a class implement more than
Is there anyway that I can have tabs on an iPhone hide if there
I have the following section of code. Is there anyway that I can use
Is there anyway to implement Resource Acquisation is Initialization in Scheme? I know that
Is there any way to implement a URL mechanisim in asp.net like it has
Is there any way to implement pop-ups similar to the system ones on iPhone?
Is there any way to implement something similar to Chatroulette without using Flash or
Is there any way to implement publish subscribe push notification in Android ? At
Is there anyway i can calculate the sum of the square of objects in
I am creating an application where there is main DB and where other data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.