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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:28:30+00:00 2026-06-01T00:28:30+00:00

i have a class that uses a proxy class inside to call a service

  • 0

i have a class that uses a proxy class inside to call a service that provide data. of course if the method create the proxy inside there is a problem to test that class. do you think that the proxy should be given in the constructor even if it can be created inside without “knowing” ?

  • 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-01T00:28:31+00:00Added an answer on June 1, 2026 at 12:28 am

    You should provide class dependencies to class via dependency injection (constructor, property, parameter). That makes your class testable and allows to mock all those dependencies.

    UPDATE:
    Inject service proxy:

    class Foo
    {
       private IServiceProxy _serviceProxy;
       public Foo(IServiceProxy _serviceProxy)
       {
            _serviceProxy = serviceProxy;
       }
    
       public void Bar()
       {
           var staff = _serviceProxy.GetStaff();
       }
    } 
    

    Btw consider to hide information about proxy from your class. E.g. implement by proxy same interface that actual service has and provide IService to your class.

    UPDATE2 (gateway):

    All our domain needs – to get some staff. So, we define interface:

    interface IStaffService
    {
      Staff GetStaff();
    }
    

    Our domain class (your tested class uses only this interface and does not depend on web services, proxy creation and other infrastructure concerns).

    Next create Gateway (see definition on Martin Fowler site) for your service:

    public MyServiceProxyGateway : IStaffService
    {
        public Staff GetStaff()
        {
           var proxy = new YourProxyType();
           proxy.X = value;
           proxy.Y = value;
           var response = proxy.CallActualServiceMethod();
           Staff staff = new Staff();
           staff.Value = response.Something;
           return staff;
        }
    } 
    

    Your code now completely unaware about all this infrastructure communications. And you use handy interface GetStaff instead of CallActualServiceMethod.

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

Sidebar

Related Questions

I have a class 'Data' that uses a getter to access some array. If
I have a POJO that uses a service to do something: public class PlainOldJavaObject
I have a Class that uses a dictionary to store some data. But I
I have a class that uses the __set magic method. One of the properties
I have a class that uses __call(): public function __call($method, $args){ $method = _.$method;
I have a class that uses enumerable data types. In it's constructor, it uses
My problem is the following; I have a class that uses non-static native methods
I have a class that has a new method and uses that object to
I have a class that uses XStream and is used as a transfer format
I have a custom class that uses boost mutexes and locks like this (only

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.