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 this method, that will be called against from a WCF Client, but
In my WCF service I have method with 'int' parameter: [OperationContract] PublishResult PublishEnrollmentProfile( string
I'm trying to implement a fire-and-forget pattern in a WCF method. I have this
I have an ajax enabled WCF service method : [OperationContract] public string Test(string name)
I have a WCF service that is deployed on a machine. This WCF service
I have a Data Service created using WCF that internally uses nHibernate. This WCF
I have an ASP.NET page that calls to a WCF service. This WCF service
I have used this guid: http://www.c-sharpcorner.com/uploadfile/shivprasadk/wcf-faq-part-5-transactions/ Why doesnt it rollback?? I dont understand! I
I have a WCF service application and in this app I am doing calls
I have a WCF service with a function GetData() When my client calls this

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.