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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T14:34:07+00:00 2026-06-02T14:34:07+00:00

I am trying to resolve dependency that is depending on a parameter value in

  • 0

I am trying to resolve dependency that is depending on a parameter value in my operation that I am calling.

I have this WCF service

public class InformationService : IInformationService
{
    private readonly IValueProvider _valueProvider;

    public InformationService(IValueProvider valueProvider)
    {
        _valueProvider= valueProvider;
    }


    public CompanyReportResponse CompanyReport(string option)
    {
        _valueProvider.Execute(option);
    }
}

I have also registered two concrete types for my ValueProvider in my container.

Registry.For<IValueProvider>().Add<ValueProvider1>().Named("No1");
Registry.For<IValueProvider>().Add<ValueProvider2>().Named("No2");

Is it somehow possible to use different Value Provider depending of the value of option?

Ie, when option is "value1" then _valueProvider will use the concrete type ValueProvider1 and when option is "value2” then _valueProvider will use the concrete type ValueProvider2.

  • 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-02T14:34:12+00:00Added an answer on June 2, 2026 at 2:34 pm

    I see at least 2 different options.

    If the ValueProvider is only used in that method, you could consider Method Injection. Since at the moment of passing the option argument you already know which one is going to be used, you could provide the implementation for IValueProvider to use as an additional argument.

    public CompanyReportResponse CompanyReport(string option, IValueProvider provider)
    {
        _provider.Execute(option);
    }
    

    The second option is to define a factory to build your ValueProvider, and inject this factory via constructor injection. The factory will have a method for instantiating the correct ValueProvider depending on the option argument.

    public interface IValueProviderFactory
    {
        IValueProvider CreateProvider(string option);
    }
    
    public class ValueProviderFactory : IValueProviderFactory
    {
        public IValueProvider CreateProvider(string option)
        {
             // Insert custom instantiation logic here:
             // if option == "value1" return ValueProvider1 and so on
        }
    }
    
    public class InformationService : IInformationService
    {
        private readonly IValueProviderFactory _valueProviderFactory;
    
        public InformationService(IValueProviderFactory valueProviderFactory)
        {
            _valueProviderFactory = valueProviderFactory;
        }
    
        public CompanyReportResponse CompanyReport(string option)
        {
            var valueProvider = _valueProviderFactory.CreateProvider(option);
            valueProvider.Execute(option);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a basic class that is trying to resolve an interface using Unity.
I have a question that I have spent too many hours trying to resolve.
We're trying to use Dependency Injection for a WCF Service. The Service has a
I'm trying to have the unit tests not rely on calling container.Resolve<T>() for their
If I have a class that has a dependency that is resolved via property
I have a concrete class of logger that Microsoft.Unity will resolve ILogger to. The
I am trying to resolve a design issue implementation in typo3. Essentially I have
I'm trying to resolve a hostname from an ip address. I have tried using
I'm trying to resolve the AccountController in my application, but it seems that I
I'm trying to resolve the following in C++/CLI which creates a circular dependency. Meaning

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.