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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:46:28+00:00 2026-06-18T06:46:28+00:00

Following on from my recent question regarding SimpleInjector and hybrid web request/thread lifestyles it

  • 0

Following on from my recent question regarding SimpleInjector and hybrid web request/thread lifestyles it seems I do not fully understand the technical requirements and have been doing something I don’t actually need to do.

With this code

interface IUnitOfWork { }
interface IWebUnitOfWork : IUnitOfWork { }
interface IThreadUnitOfWork : IUnitOfWork { }
class UnitOfWork : IWebUnitOfWork, IThreadUnitOfWork { }

container.RegisterPerWebRequest<IWebUnitOfWork, UnitOfWork>();
container.RegisterLifetimeScope<IThreadUnitOfWork, UnitOfWork>();
container.Register<IUnitOfWork>(() => container.GetInstance<UnitOfWork>());

// Register as hybrid PerWebRequest / PerLifetimeScope.
container.Register<UnitOfWork>(() =>
{
    if (HttpContext.Current != null)
        return container.GetInstance<IWebUnitOfWork>() as UnitOfWork;
    else
        return container.GetInstance<IThreadUnitOfWork>() as UnitOfWork;
});

My understanding was that for AppDomains running within IIS the IWebUnitOfWork would be returned, and otherwise there would be an error unless I have explicitly declared an instance of a LifetimeScope to wrap the call to the container (which would return IThreadUnitOfWork).

The following statement has made me realise I don’t fully understand what I’ve been doing!

You however, don’t seem to need a hybrid lifestyle add all. A hybrid lifestyle is a lifestyle that can switch dynamically (on each call to GetInstance and per each injection), while you only seem to need to switch during start-up.

My question is this: under what circumstances can a container (or any other class for that matter), be it static or instance, that is loaded within an AppDomain running within IIS, be called without the existence of a HttpContext?

  • 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-18T06:46:29+00:00Added an answer on June 18, 2026 at 6:46 am

    As Steven has outlined in the comments, hybrid registration is generally needed when a web request can start a process on another thread. In this situation the container can be required to service requests for both Web Requests and Thread requests.

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

Sidebar

Related Questions

Following on from my recent question on Large, Complex Objects as a Web Service
Following on from my recent question regarding parsing XML files in Java I have
Following from my last question which @Jon Skeet gave me a lot of help
Following from these question Subset sum problem and Sum-subset with a fixed subset size
I try to understand Firefox's behavior regarding the added prevent this page from creating
From my recent question , I try to centralize the domain model by including
From some recent testing and reading I've done, it seems the X (exclusive) name
The following code is extracted from: https://github.com/facebook/folly/blob/master/folly/Synchronized.h I recent had a look at the
Following my recent Asked Question (which was answered; thanks very much for the help!)
I was asked the following question at a recent job interview: What do you

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.