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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:22:39+00:00 2026-05-11T21:22:39+00:00

I am writing a API over the top of a COM object and you

  • 0

I am writing a API over the top of a COM object and you have to pass around the COM object into pretty much every type and static method that I write so that I can test each part of my API.

Now my question is do I have an overloaded method for the one that takes the COM object but pass the IoC resolved one instead to the other one instead, so that the users of the API don’t have to worry about passing in the COM object or should I remove the overloaded method and just resolve it with out the option to pass it in.

Bit hard to explain so here is an example;

Constuctor Example;

FooType(IComObject obj,string table) {}
FooType(string table) : this(Ioc.Resolve<IComObject>(), table) {}

or just

FooType(string table) : this(Ioc.Resolve<IComObject>(), table) {}

Static method example;

public static SomeType Create(IComObject obj,string table) 
{ // Do some work with obj}

public static SomeType Create(string table) 
{ 
   return MyClass.Create(Ioc.Resolve<IComObject>(),table);
}

or just

public static SomeType Create(string table) 
{ 
   IComObject obj = Ioc.Resolve<IComObject>();
   return MyClass.Create(Ioc.Resolve<IComObject>(),table);
}

My biggest worry with the overloading is that it’s going to create a lot of methods that just froward calls. What other options do I have here or is this correct way of tackling this?

P.S I really don’t want to burden the user with having to pass a instance of IComObject all around their application.

  • 1 1 Answer
  • 1 View
  • 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-11T21:22:39+00:00Added an answer on May 11, 2026 at 9:22 pm

    One of the principles of Dependency Injection is that dependencies of a class should be made explicit to the outside world. When a class resolves a dependency itself (as in your second example) it goes against that principle, and is headed back down the road of using singleton services – though admittedly you are somewhat better off because you do have the IoC container as an “escape hatch” for mocking the service objects.

    Obviously having a whole load of parameters in the constructors of all your objects is rather burdensome, but that’s where the IoC Container steps in. If it supports auto-wiring, and you’re using it as it was designed, you usually find yourself having to resolve very few instances yourself: you pull the first object out, and it comes ready-configured with all its dependencies – and they’re ready configured with all their dependencies, and so on. For this reason, Joshua Flanagan makes the argument that IoC Containers really ought to be called IoC Composers.

    If you want to avoid burdening the users of your API, how about having a focal object that wraps up your IoC container and pulls configured instances out of it for consumption by calling code?

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

Sidebar

Related Questions

I'm writing an API that converts actions performed by a non-technical user into Salesforce.com
I am writing an API and have come across the following pattern: My API
I'm writing demo code for an API we've created and I keep running into
We are writing an API for iphone developers and we don't know what the
I am currently writing an API and an application which uses the API. I
I'm writing an API on Android that will be used by an existing application,
I'm writing a caching API in PHP. It does everything I need it to
I'm writing a Web API service and trying to return a (400) Bad Request
I'm a C++ amateur. I'm writing some Win32 API code and there are handles
I'm currently writing the documentation for the API of my website. I'm not sure

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.