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 5941357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:05:54+00:00 2026-05-22T16:05:54+00:00

I would really appreciate peoples opinions on the below design problem. I have a

  • 0

I would really appreciate peoples opinions on the below design problem.

I have a model in which either a ‘Person’ or a ‘Business’ may be the provider of a certain ‘Service’. An example class definition is shown below:

IProvider
Guid Id

Person: IProvider
Guid Id
string FirstName
string LastName

Business: IProvider
Guid Id
string Name

Service
Guid Id
IProvider provider

Therefore I have created the relevant concepts in my domain, ‘Person’, ‘Business’, ‘IProvider’ and ‘Service’. Where I am struggling is on which entities to create the repositories. In this context ‘Service’ is an aggregate root and therefore has its own repository. ‘Business’ is also an aggregate root in my context as it will have meaning even if it is not a provider. ‘Person’ will only be created in the system if they ‘are a Provider’.

Would I create a repository for the role of IProvider, which would return me instances of ‘Person’ and ‘Business’; my issues with this are that the code could quickly become quite complicated as any implementation would need to look at multiple tables etc to return all different type of IProvider. Such an approach would require repositories for ‘Person’ and ‘Business’ to be created and injected into the ‘IProvider’ repository to provide the required functionality i.e.

public class ProviderRepository : IProviderRepoistory
{
    public IBusinessRepository businessRepository {get; set; }
    public IPersonRepository personRepository {get; set; }

    public IProvider FindById(Guid Id){
        IProvider entity = businessRepository.FindById(Id);

        if(entity == null)
            entity = personRepository.FindById(Id);

        return entity;
    }
}

Another appraoch would be to create repositories for the ‘Person’ and ‘Business’ entities which implement a ‘IProvider’ interface, therefore making them available to participate in that role. i.e

public class PersonRepository : IPersonRepository, IProviderRepository
{
    private ISession session;        

    public Person FindById(Guid Id){
        return session.Query<Person>().FirstOrDefault<Person>(x => x.Id == Id);
    }

    public IProvider FindById(Guid Id){
        return session.Query<Person>().FirstOrDefault<Person>(x => x.Id == Id && x.IsProvider == true);
    }
}

I would then use a mechinism (i.e. IoC container) to pick the correct concrete implementation of the IProviderRepository when required. For example if I am dealing with a provider who I know to be a person I can get the PersonRepository implementation.

Another option would be to not implement any IProvider repositories and just stick with ‘Person’ and ‘Business’ repositories and use them as required in the service layer?

  • 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-22T16:05:55+00:00Added an answer on May 22, 2026 at 4:05 pm

    I think you’re over thinking it, and you’re trying to optimize too early.

    From everything you’ve said here, it sounds to me like Person and Business are both entities, but neither is an aggregate (though obviously, I might be missing something in your discussions w/ domain experts). It seems to me that the Provider is the aggregate.

    When you build the ProviderRepository, you don’t need to inject repositories for Businesses nad Persons, b/c if they’re not aggregates, they shouldn’t have their own repositories. Instead, the ProviderRepository should use the Session directly to fetch what it needs from whatever DB schema you come up with to compose the entities in question for the given query. If you map the inheritance correctly, you can do queries on the base class or interface.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would really appreciate if you could shed light on this problem. I have
I have been dealing with a problem for some time and would really appreciate
I would really appreciate any help with the following problem: I need to be
I would really appreciate any jquery expert help as a method I've used previously,
I would really appreciate it if some of you could help optimize my tables,
I would really appreciate if you would take a look at this piece of
Ok I give up and would really appreciate it if you guys could cast
I'm very new to C++ and would really appreciate any and all help. I
I'm new to postgreSQL, so would really appreciate any pointers from the community. I
I would really appreciate it anybody could briefly explain me, what's the general approach

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.