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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T10:36:59+00:00 2026-06-06T10:36:59+00:00

I have an situation here that looks very like a SELECT N+1 from the

  • 0

I have an situation here that looks very like a “SELECT N+1” from the NHibernate world.

I’m creating an application ASP.NET MVC app and the HomeController needs an IUserSignUpService. The IUserSignUpService “lives” in the Application Service Layer where it is binded to the concrete class UserSignUpService.

The UserSignUpService has 2 dependencies:

public IUserRepository UserRepository { get; set; }
public Domain.Services.IUserSignUpService SignUpService { get; set; }

public UserSignUpService(IUserRepository userRepository, Domain.Services.IUserSignUpService signUpService)
{
    this.UserRepository = userRepository;
    this.SignUpService = signUpService;
}

When Autofac is resolving the IUserSignUpService that lives in the Application Service Layer, it needs to resolve the IUserRepository dependency that lives in the Persistence Layer and a Domain.Services.IUserSignUpService (I know, same name, but they are different) that lives inside the Domain and performs several actions before execute the INSERT SQL to the database.

The IUserRepository interface is implemented by the UserRepository class that needs an ISession instance to be injected via constructor.

My point here is:

If I keep using this approach, every time I receive a HttpRequest to the HomeController I’m going to start a new ISession (because it is a constructor dependency of UserRepository, which is a constructor dependency to IUserSignUpController which is a constructor dependency of HomeController).

I don’t need everything every time. Maybe I could instruct Autofac to only resolve the ISession when there’s an instance of the IUnitOfWork interface in the current LifeTimeScope.

Is it possible?

  • 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-06T10:37:01+00:00Added an answer on June 6, 2026 at 10:37 am

    Test whether doing extra work to not construct an ISession is premature optimization. Is there a significant perf hit?

    If so, you could wrap whatever constructor dependency that you “don’t need every time” in a Lazy<> and Autofac will delay instantiation.

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

Sidebar

Related Questions

Here is the situation. I have some javascript that looks like this: function onSubmit()
here is my situation. I have a select box that is populated from a
Here's my situation (SQL Server): I have a web application that utilizes nHibernate for
a noob question here. I have a very strange situation that's very puzzling to
Here's the basic situation: I have an OpenGL VBO that draws a 2D symbol
Here is my situation: I have one table that contains a list of drugs
Here's the situation: I have a two images that are over 1024 in width
Here's my situation. I have a graph that has different sets of data being
Here is my situation. I have an app that is composed almost entirely using
Here is a situation I have encountered: I have two similair java application running

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.