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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:15:36+00:00 2026-05-23T10:15:36+00:00

Imagine there is a Customer class with an instance Load() method. When the Load()

  • 0

Imagine there is a Customer class with an instance Load() method.

When the Load() method is called, it retrieves order details by e.g.

var orders = Order.GetAll(customerId, ...);

GetAll() is a static method of the Order class and the input parameters are fields defined in the Customer class.

As you can see, Order is a dependency of the Customer class, however, I can’t just create an IOrder and inject it there as interfaces can’t have static methods.

Therefore, the question is how could I introduce dependency injection in this example?

I don’t want to make GetAll() an instance method since it’s a static method and need to keep it that way.

For example, I have used utility classes in my design, most of which just contain static methods.

  • 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-23T10:15:37+00:00Added an answer on May 23, 2026 at 10:15 am

    If you must keep the static method, I would wrap the static calls in a Repository object.

    Like this:

    interface IOrderRepository {
       IEnumerable<IOrder> GetAll(customerId, ..);
    }
    
    class OrderRepository : IOrderRepository {
       IEnumerable<IOrder> GetAll(customerId, ...)
       {
         Order.GetAll(customerId,...); // The original static call.
       }
    }
    

    Now you inject this repository into your Customer class.

    (I’m assuming you’re doing this so you can inject fake IOrders at runtime for testing purposes. I should say that in general, static methods are a serious obstacle to testing.)

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

Sidebar

Related Questions

Imagine, there is a class object, like a Customer Class object, and it has
I imagine there are many of you out there who have developed an application
On C# 3.0 and .NET 3.5, imagine there's an interface: public interface INameable {
Is there any way to check if a particular plugin is available? Imagine that
There is one thing that I do not understand... Imagine you have a text
I have what I imagine to be a pretty standard web-interface. There are 4
I have several classes such as Order, Customer, etc. These classes serve for holding
Imagine I have these python lists: keys = ['name', 'age'] values = ['Monty', 42,
Imagine you homebrew a custom gui framework that doesn't use windows handles (compact framework,
Imagine we have a program trying to write to a particular file, but failing.

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.