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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:45:33+00:00 2026-05-13T13:45:33+00:00

I have this wcf method Profile GetProfileInfo(string profileType, string profileName) and a business rule:

  • 0

I have this wcf method

Profile GetProfileInfo(string profileType, string profileName)

and a business rule:

if profileType is “A” read from database.

if profileType is “B” read from xml file.

The question is: how to implement it using a dependency injection container?

  • 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-13T13:45:34+00:00Added an answer on May 13, 2026 at 1:45 pm

    Let’s first assume that you have an IProfileRepository something like this:

    public interface IProfileRepository
    {
         Profile GetProfile(string profileName);
    }
    

    as well as two implementations: DatabaseProfileRepository and XmlProfileRepository. The issue is that you would like to pick the correct one based on the value of profileType.

    You can do this by introducing this Abstract Factory:

    public interface IProfileRepositoryFactory
    {
        IProfileRepository Create(string profileType);
    }
    

    Assuming that the IProfileRepositoryFactory has been injected into the service implementation, you can now implement the GetProfileInfo method like this:

    public Profile GetProfileInfo(string profileType, string profileName)
    {
        return this.factory.Create(profileType).GetProfile(profileName);
    }
    

    A concrete implementation of IProfileRepositoryFactory might look like this:

    public class ProfileRepositoryFactory : IProfileRepositoryFactory
    {
        private readonly IProfileRepository aRepository;
        private readonly IProfileRepository bRepository;
    
        public ProfileRepositoryFactory(IProfileRepository aRepository,
            IProfileRepository bRepository)
        {
            if(aRepository == null)
            {
                throw new ArgumentNullException("aRepository");
            }
            if(bRepository == null)
            {
                throw new ArgumentNullException("bRepository");
            }
    
            this.aRepository = aRepository;
            this.bRepository = bRepository;
        }
    
        public IProfileRepository Create(string profileType)
        {
            if(profileType == "A")
            {
                return this.aRepository;
            }
            if(profileType == "B")
            {
                return this.bRepository;
            }
    
            // and so on...
        }
    }
    

    Now you just need to get your DI Container of choice to wire it all up for you…

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

Sidebar

Related Questions

I have created a basic WCF service in IIS. I am aware that this
Background This question is in two parts. I have a one-way WCF operation hosted
I have this gigantic ugly string: J0000000: Transaction A0001401 started on 8/22/2008 9:49:29 AM
I have this string 'john smith~123 Street~Apt 4~New York~NY~12345' Using JavaScript, what is the
I have this method on a webpart: private IFilterData _filterData = null; [ConnectionConsumer(Filter Data
I have a WCF service method that returns a big byte[] array around 2
I have a WCF service, a MS SQL database, and the Visual Studio 2008
I have a simple WCF service method: [OperationContract] public SetupGameResult SetupGame(long player1Id, long player2Id,
I have a WCF service, in it i have a method that takes a
Can anybody tell me why is this not working. I have created a WCF

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.