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

  • Home
  • SEARCH
  • 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 6674565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:45:39+00:00 2026-05-26T03:45:39+00:00

This model is simplified, only used for demonstration. In my application got: Data public

  • 0

This model is simplified, only used for demonstration.

In my application got:

Data

public class Product
{
    public Guid Id { get; set; }
    public string Name { get; set; }
    public Category Category { get; set; }
}

public class Category
{
    public Guid Id { get; set; }
    public string Name { get; set; }
}

Repository

public interface IRepository<T>
    where T : class
{
    T Add(T entity);
    T Remove(T entity);
    IQueryable<T> GetAll();
    int Save();
}

public class ProductRepository : IRepository<Product>
{
    public Product Add(Product entity) { ... }
    public Product Remove(Product entity) { ... }
    public IQueryable<Product> GetAll() { ... }
    public int Save() { ... }
}

public class CategoryRepository : IRepository<Category>
{
    public Category Add(Category entity) { ... }
    public Category Remove(Category entity) { ... }
    public IQueryable<Category> GetAll() { ... }
    public int Save() { ... }
}

Services

public interface ICategoryService
{
    Category Add(Guid gidProduct, Category category);
}

public class CategoryService : ICategoryService
{
    public Category Add(Guid gidProduct, Category category){ ... } //Problem here

    readonly IRepository<Category> _repository;

    public CategoryService(IRepository<Category> repository)  //Problem here
    {
        _repository = repository;
    }
}

As I have a repository for each class when I need information from another repository in my service, what should I do?

In the example above, in my service layer I have a method to Add a product (where I found the code for it) and a category.

The problem is that I do a search in the repository of products to recover it, but in my service class category, there is no repository of products., how to solve this problem?

  • 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-26T03:45:40+00:00Added an answer on May 26, 2026 at 3:45 am

    First you need to create a repository for each aggregate root not for each class.

    and if you need to access more than one repository in your service, simply you depend on all of them then you can add them as parameters to the constructor for dependency injection.

    public CategoryService(CategoryRepository  categoryRepository, ProductRepository productRepository) 
    {
        _categoryRepository = categoryRepository;
        _productRepository = productRepository;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

class Followup < ActiveRecord::Base belongs_to :post belongs_to :comment end This model needs to only
Consider the following Django models: class Host(models.Model): # This is the hostname only name
I have this model in django: class JournalsGeneral(models.Model): jid = models.AutoField(primary_key=True) code = models.CharField(Code,
Let's say I have this model named Product with a field named brand .
I'm using FluentNHibernate but NHibernate XML will do. Say I have this model public
I have this Task model: class Task < ActiveRecord::Base acts_as_tree :order => 'sort_order' end
I have an order entry page and a corresponding ViewModel (simplified example): public class
I'm currently doing a firewall management application for Django, here's the (simplified) model :
I need to write model data ( CharField s only) to an XML file
i have this simplified Model: https://i.stack.imgur.com/d2WsV.png I have these Elements ordered in an NSOutlineView

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.