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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:57:09+00:00 2026-06-16T09:57:09+00:00

Occasionally I find myself in a situation where I need to resolve a service

  • 0

Occasionally I find myself in a situation where I need to resolve a service only if a certain condition is met. For example, a user might select to send an email or an sms notification. I would like to lazy load the email or sms service depending on what the user chooses so that I don’t have to load both of them and waste resources (what if there were, for example, 10 options for the user…?).

The problem I have is with using the container outside of my bootstrap code (I dont want my code dependent on th container). I can’t seem to find a way around using the container for lazy loading services (unless I create the needed services by hand and do all the DI manually). Is this a situation where the rules can be bent or is there a better way of doing it?

  • 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-16T09:57:10+00:00Added an answer on June 16, 2026 at 9:57 am

    If you are using Castle Windsor 3.0 or newer, you can use lazy resolving.

    See What’s new in Windsor 3 for more details.

    Registration process changes a bit (new component loader must be registered).

    After that, you are just registering components as always, but resolve dependencies as Lazy<T> instead of T. Until you won’t access .Value property of your Lazy<T>, dependency will not be resolved, so you can pass few lazily evaluated objects and access only the one you will need and when you need.

    If you have more options to the user, maybe you should consider creating some sort of abstract factory interface. You would then register and resolve only this factory and the factory itself would create appropriate service for sending notifications (be it a mail or a sms or any other option). Implementation of the factory can be coded by hand or Castle Windsor can you with that (I think from version 3.0).

    Often when I do use such factory, I implement it by hand and pass container as it’s dependency, so only factory implementation depends on my container.

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

Sidebar

Related Questions

I occasionally find myself in a situation where I have a variable that will
I occasionally find myself needing certain filesystem APIs which could be implemented very efficiently
I occasionally find myself starting and stopping multiple windows services. The only tool I'm
Occasionally when writing Ruby I find myself wanting a pipe method, similar to tap
Possible Duplicate: Can you define “literal” tables in SQL? Occasionally I find myself in
I occasionally find myself passing this or Me to a child object. Such as
I find myself occasionally in C# 3.0 looking for ways to simulate the notion
Occasionally I find I need to process a list by inserting a new item
Being a programmer I occasionally find the need to analyze large amounts of data
I find myself in this position occasionally, and I'm sure there is a better

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.