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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:26:10+00:00 2026-06-11T15:26:10+00:00

I am working on enterprise application using MVC, Nhibernate and IOC container. I three

  • 0

I am working on enterprise application using MVC, Nhibernate and IOC container.

I three tiers:

DAL – Nhibernate Data Repositories

public class CustomerRepository : Repository<int>,ICustomerRepository
{
    public CustomerRepository(IUnitOfWork unitOfWork)
        : base(unitOfWork)
    {

    }
}

BLL – Business Layer

public class CustomerManager
{
    private readonly ICustomerRepository _repository;
    public CustomerManager(ICustomerRepository repository)
    {
        _repository = repository;
    }
    public IList<Customer> GetAll()
    {
        return _repository.GetAll<Customer>();
    }
}

Presentation – MVC controller

private readonly IUnitOfWork _unitOfWork;
private readonly ICustomerRepository _repository;
private readonly CustomerManager _manager;

public HomeController(IUnitOfWork unitOfWork, ICustomerRepository repository)
    {
        _unitOfWork = unitOfWork;
        _repository = repository;
        _manager = new CustomerManager(_repository);
    }

I am using IOC container to register unit of work and CustomerRepository objects. The IOC container is working fine.

What is bugging me about this solution is that I have CustomerRepository reference in the controller. Is this architecture fine or there is a better way to implement this?

  • 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-06-11T15:26:11+00:00Added an answer on June 11, 2026 at 3:26 pm

    You shouldn’t need/have a IUnitOfWork or ICustomerRepository in the controller, with the IoC container you should be able to register the CustomerManager and then do this:

    private readonly CustomerManager _manager;
    
    public HomeController(CustomerManager customerManager)
    {
        _manager = customerManager;
    }
    

    The IoC container should understand the dependency chain and inject all the various dependencies as needed.

    I.e. MVC will try and get a HomeController from the IoC container, which in turn needs a CustomerManager… so the IoC container will try and get a CustomerManager, which in turn needs a ICustomerRepository… so the IoC container will try… you get the point.

    I would also go the the extent of extracting an interface from CustomerManager (ICustomerManager probably) to remove the coupling and make testing the Controller even easier.

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

Sidebar

Related Questions

I'm working on a pretty big enterprise application using Perl, has tens of modules,
I'm working on an enterprise application that leverages the repository pattern on top of
I am working on a enterprise application where forms a generated dynamically and we
I am working with v4 of the Enterprise Application block and I am trying
I've got a project that I'm working Enterprise Library logging into, and that application
I'working on a enterprise application that uses JSF 2.0, with Netbeans 7.0 and Glassfish
I'm using the Enterprise Library Logging application block to allow my application to log
I'm working locally across two domains. I have enterprise.local and application.local virtual hosts on
I'm using the Enterprise Library Exception handling block in an ASP.NET web application. I
I'm working on a web application using spring, Glassfish, hibernate and MySQL. I have

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.