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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:42:18+00:00 2026-06-04T21:42:18+00:00

I have an interface for holding the connection configuration info for web service access:

  • 0

I have an interface for holding the connection configuration info for web service access:

public interface IServiceConnectionConfiguration
{
    string Username { get; }
    string Password { get; }
    string ChannelEndpointUrl { get; }
    string MediaEndpointUrl { get; }
    string PlayerlEndpointUrl { get; }
    string PlaylistEndpointUrl { get; }
}

I have a factory class that returns the service instance specific to the type of the service requested.

public static class ServiceClientFactory
{
    public static void Configure(IServiceConnectionConfiguration config)
    {
        _config = config;
    }
    public static T GetService<T>() where T : class, IServiceClient
    {
    }
}

The factory is called as

Channel channelService   = factory.GetService<Channel>();

What I am trying to figure out is an elegant way for the Factory code to resolve the endpoint urls for the passed in types itself based on the config object passed during initialization. eg. If the type parameter passed is channel, it should take the ChannelEndpointUrl while constructing the ChannelService.

I thought about using attributes on the config class to decorate the endpoint urls with the service type that they correspond to but it seems like a bad design.

Any ideas.

  • 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-04T21:42:20+00:00Added an answer on June 4, 2026 at 9:42 pm

    Well, one way to approach it would be to have the Factory have a private static Dictionary containing your initialization logic, indexed by “Type”. Similar to a strategy pattern.

    for example:

    public static class ServiceClientFactory
    {
        private static IServiceConnectionConfiguration _config;
        private static readonly Dictionary<Type, Func<IServiceClient>> Initializers = new Dictionary<Type, Func<IServiceClient>>();
    
        static ServiceClientFactory()
        {
            Initializers.Add(typeof(Channel), () =>
                                                   {
                                                       return //create the service client based on the endpoint
                                                   });
        }
    
        public static void Configure(IServiceConnectionConfiguration config)
        {
            _config = config;
        }
    
        public static T GetService<T>() where T : class, IServiceClient
        {
            return (T)Initializers[typeof (T)]();
        }
    }
    

    EDIT: Now, as you mentioned, you cannot instantiate explicitly in your factory since you’d cause a circular reference, maybe you can force a new() constraint, and construct the instance in the GetService method, and only use the dictionary for endpoint configuration, such as:

    public static class ServiceClientFactory
    {
        private static IServiceConnectionConfiguration _config;
        private static readonly Dictionary<Type, Action<IServiceClient>> Initializers = new Dictionary<Type, Action<IServiceClient>>();
    
        static ServiceClientFactory()
        {
            Initializers.Add(typeof(Channel), t =>
                                                  {
                                                      t.Url = _config.ChannelEndpointUrl;
                                                      //configure t using the appropriate endpoint
                                                  });
        }
    
        public static void Configure(IServiceConnectionConfiguration config)
        {
            _config = config;
        }
    
        public static T GetService<T>() where T : class, IServiceClient, new()
        {
            var service = new T();
            Initializers[typeof(T)](service);
            return service;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have interface IConfigurationSource { .... } and class FileConfigurationSource : IConfigurationSource { FileConfigurationSource(string
I have interface Foo public interface Foo { public void test(); } Class FooChild
I have an interface of edge: public interface IEdge<TPoint, TFactory> where TPoint : IPoint
I have tried to make a webservice interface to a state-holding COM component. The
I have interface interface IAdaptor<T, K> { // ... } And I have realisation
Suppose I have @interface A : NSObject @property (nonatomic, strong) NSMutableArray *array; @end Later
I have two questions 1) my interface i have interface called IRegister and within
Let's say we have interface window_creator that responsible for creation of windows. For simplicity
Just for learn: Say we have: interface Musician { /* content skipped */ }
I have an interface with a base class in C# -- I'd like to

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.