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

  • Home
  • SEARCH
  • 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 8703935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:58:37+00:00 2026-06-13T02:58:37+00:00

C# on .NET 4.5: public Interface IMyInterface { public string DoSomething( string input1 )

  • 0

C# on .NET 4.5:

 public Interface IMyInterface
    {
    public string DoSomething( string input1 )
    }

    public MyClass1 : IMyInterface
    {
    public string DoSomething( string input1 )
    {
    return "1";
    }
    }

    public MyClass2 : IMyInterface
    {
    public string DoSomething( string input1 )
    {
    return "2";
    }
    }

At runtime, I want to detect the hosting environment, set some kind of “global”, and then based on the global always instance and use MyClass1 or MyClass2. I do not want to have a single “MyClass” and then do lots of case logic inside it to detect the environment.

What is a good pattern or practice to do that? Is this actually a good place for Dynamics?

Thanks.

  • 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-13T02:58:38+00:00Added an answer on June 13, 2026 at 2:58 am

    Seems like you need to use Factory. Create a method in Factory class to return MyClass object. Keep the return type of the method as IMyInterface. Within the method, you can execute your hosting logic and depending upon the output of hosting logic, instantiate proper class and return the reference to the object.

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

Sidebar

Related Questions

Environment: ASP.NET MVC3 C# Say I have some repository (semi-psuedo): public interface IRepository {
This is .NET 4.0/C#. I have a class that inherits from an interface: public
Since I'm a C#-/.NET-guy, I'm used to explicit interface implementations - like so: public
Having the following class (.Net 3.5): public class Something { public string Text {get;
I am calling an ASP.NET MVC action public JsonResult GetPatient(string patientID) { ... from
Is there a .NET framework interface like this? public interface IEvent { event EventHandler
I have a .NET interface <System.Runtime.InteropServices.GuidAttribute(0896D946-8A8B-4E7D-9D0D-BB29A52B5D08), _ InterfaceType(ComInterfaceType.InterfaceIsIDispatch)> _ Public Interface IEventHandler Sub OnEvent(ByRef
I have an interface: [ServiceBehavior] public interface ICartService { string DaoString {get;set;} public GetString();
Consider the following lines of code: public interface IProduct { string Name { get;
I want to invoke a constructor via .Net reflection that takes a interface as

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.