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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:48:35+00:00 2026-05-22T20:48:35+00:00

I’m writing an ASP.Net webforms app using nHibernate. Currently I’m not using any IoC

  • 0

I’m writing an ASP.Net webforms app using nHibernate. Currently I’m not using any IoC framework.

Firstly- my scenarios:

  1. I don’t want to allow two Employees with the same name. I would like to enable the Employee class to search for other Employee with the same name and issue an error.

  2. A Department may have 1000s of Employees. I need to know exactly how many Employees each Department has. I don’t want to load them all into memory, so I use a calculated property- EmployeesCount. However, this property is initialized the first time the Department object is loaded. If I add / remove employees the changes are not reflected in that property. (especially since I’m using 2nd level cache, so my object persists over multiple Session scopes)

My idea of solving these problems is to have my domain objects hold reference to the appropriate Repository objects.
I think the best solution is to have my repositories implement interfaces and use some sort of IoC container / DI mechanism.

So, in Employee I’ll have:

if (_empRepository.GetEmployeeByName(newEmployeeName) != null) //...

and in Department:

public int EmployeesCount
  {
    get
      {
         return _departmentRepository.GetCurrentEmployeesCount(this);
      }
  }

my questions:

  1. Which is prefferable- c’tor DI

    public Employee(IEmployeeRepository repository)

or using an IoC container?

public Employee()
  {
     _empRepository = container.Resolve<IEmployeeRepository>();
  }
  1. How to implement the desired solution? I understand that Interceptors / tuplizers is the way to go, but I couldn’t really get my head around the whole thing. Is this a good example? Also- in which namespace should I define the Interfaces, the IoC container etc.?
  • 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-22T20:48:36+00:00Added an answer on May 22, 2026 at 8:48 pm

    The POC0-to-persistence relationship is usually uni-directional: The persistence tier knows about POCOs, but not the other way around.

    The moment you make the POCO responsible for things like searching for other Employees with the same name, you make it bi-directional. I’d be concerned about growing cycles between modules in your design.

    Putting that activity in the POCO might sound like a good idea, because it helps to avoid the “anemic domain model” label, but I wouldn’t do it. I’d put those methods on persistence interfaces and let them handle it. It’s also more likely that the service in charge of fulfilling the use case would want to know about duplicate Employee names; let it do the asking and leave POCO out of the conversation.

    This approach will make your testing life easier. You’ll know how painful module cycles can be when you go to test. You’ll have to drag too much machinery into the test to get it to work.

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

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I am writing an app with both english and french support. The app requests
I am using Paperclip to handle profile photo uploads in my app. They upload
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am currently running into a problem where an element is coming back from

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.