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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:34:56+00:00 2026-05-25T23:34:56+00:00

I have a WPF MVVM application that has a model and services assembly. I’m

  • 0

I have a WPF MVVM application that has a model and services assembly. I’m trying to figure out how to use the Windsor container to resolve local (services in the service layer) dependencies, but the only thing I can figure out feels kludgy and incorrect.

Services installer:

public class ServicesInstaller : IWindsorInstaller
{
    public void Install(IWindsorContainer container, IConfigurationStore store)
    {
        //Services
        container.Register(
            Component.For<IServiceA>().ImplementedBy<ServiceA>().LifeStyle.Singleton,
            Component.For<IServiceB>().ImplementedBy<ServiceB>().LifeStyle.Singleton
    }
}

Service consumer (located in services):

public class ServiceConsumer
{
     public SomeMethodThatUsesServiceAOnlyOcassionally()
     {
         //buncha logic.
         if (allThatFailed)
         {
                 ??? ResolveServiceA ???
         }
     }
} 

Because I’m not dependent on ServiceA that often, I don’t want to pass it in via constructor injection or property injection. I’d add a static container instance to the Installer, but I have to believe that there’s a more idiomatic solution than that.

  • 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-25T23:34:57+00:00Added an answer on May 25, 2026 at 11:34 pm

    For what you want are common DI patterns.

    If your service has an optional dependency (in other words, it can do its thing with the absence of the dependency), you should use property injection. If your service needs that dependency to properly work, you should use constructor injection (because it is a required dependency). If however, the creation of that service is time consuming, you should hide that dependency behind a proxy, that can create that dependency lazily when the proxy is called for the first time.

    In your case however, ServiceA is registered as a singleton, so it is only created once during the lifetime of the application. In other words, there is no reason to use a proxy and since your service can’t live without it, you should just use constructor injection, because that clearly communicates that IServiceA is a required dependency.

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

Sidebar

Related Questions

I have a WPF application that mostly follows MVVM, which I am trying to
I'm using MVVM in my WPF application. I have a Window that has a
I have a WPF application using MVVM. I have some user controls that show
In a MVVM WPF application, I have a master-detail View that is used to
I have a wpf-mvvm application. In that I have follwoing... <Combo box> item 1
I'm building a WPF application and working with the MVVM pattern. I have 4
I have a WPF app that is using the MVVM pattern. Hooking up buttons
I have an application which I am developing using WPF\Prism\MVVM. All is going well
in my MVVM application (in wpf) i have two view and I want to
I have a wpf application in mvvm pattern. In main view, I have few

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.