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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:08:23+00:00 2026-05-12T08:08:23+00:00

I have a method returning an ISomething . I am trying to use Inversion

  • 0

I have a method returning an ISomething. I am trying to use Inversion of Control throughout my program… but I have no idea how to do it when it comes to the return value – I cannot pass it to the method, or to the object when constructing it, because this method is supposed to create the object.

The only solution I see is to pass an ISomething factory (Func<ISomething>) to the object when constructing it. Is this the usual / correct solution or is something else recommended?

[Edit] Weird – nobody else had this problem? I mean, there’s no up- (or even down-) voting…

[Edit] More details: the method is supposed to import an IExcel into an ITable. The consensus below seems to be that I should think of this method as a converter, transforming an IExcel into an ITable, thus receiving both as arguments instead of returning the ITable value. I’ll leave this up for one more day and then go with one of the responses if nothing new shows up.

  • 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-12T08:08:23+00:00Added an answer on May 12, 2026 at 8:08 am

    Is your method supposed to be constructing the ISomething, or setting it’s state and returning an ISomething with state initialized? (or does this need to be one operation?)

    If your class has a method that is responsible for creating an ISomething, then it is an ISomethingFactory (unless you have mixed concerns). In that case, it has the logic to choose the correct ISomething implementation and create it, so you shouldn’t worry too much about the IoC aspect.

    However, if this class’s concern is not creating the appropriate ISomething, then I would probably pass a factory in. The issue is, that in most cases your DI container should be able to do this for you (call a factory to get the appropriate ISomething), so seeing a method that must create an ISomething that is not a factory makes me nervous.

    Trying to give architectural guidance is always tough in a forum like this though – but with the limited input there I’d say either you have a factory that you didn’t know was a factory, or you have a problem.

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

Sidebar

Related Questions

I have a remote EJB with a method that validates an object (returning true
I have a method that can return either a single object or a collection
I have a persistence framework, and I am trying to use generics so I
I'm trying to use Moq 3.x, it works superbly. However, I have a problem
I'm trying to use the MoqAutoMocker class that comes with StructureMap and I can't
I have a method which takes params object[] such as: void Foo(params object[] items)
I have class method that returns a list of employees that I can iterate
I have a method that where I want to redirect the user back to
I have a method in my Python code that returns a tuple - a
I have this method on a webpart: private IFilterData _filterData = null; [ConnectionConsumer(Filter Data

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.