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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:13:41+00:00 2026-05-14T04:13:41+00:00

All of our reports are created from object graphs that are translated from our

  • 0

All of our reports are created from object graphs that are translated from our domain objects. To enable this, we have a Translator class for each report, and have been using Dependency Injection for passing in dependencies.

This worked great, and would yield nice classes structured like this:

public class CheckTranslator : ICheckTranslator
{
   public CheckTranslator (IEmployeeService empSvc
                         , IPaycheckService paySvc)
   {
      _empSvc = empSvc;
      _paySvc = paySvc;
   }

   public Check CreateCheck()
   {
      //do the translation...
   }
}

However, in some cases the mapping has many different grouping options. As a result, the c-tor would turn into a mix of class dependencies and parameters.

public class CheckTranslator : ICheckTranslator
{
   public CheckTranslator (IEmployeeService empSvc
                         , IPaycheckService paySvc
                         , bool doTranslateStubData
                         , bool doAttachLogo)
   {
      _empSvc = empSvc;
      _paySvc = paySvc;
      _doTranslateStubData = doTranslateStubData;
      _doAttachLogo = doAttachLogo;
   }

   public Check CreateCheck()
   {
      //do the translation...
   }
}  

Now, we can still test it, but it no longer really works with an IoC container, at least in a clean fashion. Plus, we can no longer call the CreateCheck twice if the settings are different for each check.

While I recognize it’s a problem, I don’t necessarily see the right solution. It seems kind of strange to create a Factory for each class … or is this the best way?

  • 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-14T04:13:42+00:00Added an answer on May 14, 2026 at 4:13 am

    Shot in the dark here, but could you move those parameters to the method instead?

    In other words:

    public Check CreateCheck(bool doTranslateStubData, bool doAttachLogo)
    {
       //do the translation...
    }
    

    Do those parameters have to be passed in via the constructor?

    (Note – if your response to this is “there are too many methods for that to be practical”, then part of the problem may be that the abstraction is too coarse).


    Another option (it’s really hard to say without understanding the domain model and injection patterns) would be to introduce a parameter object that is itself managed by the injector:

    public interface ICheckConfiguration
    {
        bool AttachLogo { get; }
        bool TranslateStubData { get; }
    }
    

    Then inject this with the constructor:

    public CheckTranslator (IEmployeeService empSvc, IPaycheckService paySvc,
        ICheckConfiguration config)
    {
        // etc.
    }   
    

    This should be enough. You can then create a concrete CheckConfiguration class that takes those two bool properties in its constructor, and configure your container to create different instances of the parameter object (interface) based on a higher-level DI parameter.


    The last thing I think I should mention is that just because you’re using DI doesn’t mean that everything has to be managed by the container. It’s not such a bad thing to create CheckTranslator objects in an ad-hoc fashion if there’s only one kind of “translator”. As long as the translator still depends on abstractions, which it does here, then maybe you shouldn’t be injecting it at all, just let higher-level DI-enabled classes create them ad-hoc.

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

Sidebar

Related Questions

I have a profile weblog that contains all our users details (fields seperate from
We have a Library Project that we use for all our central reused code
I'm trying to improve upon a utility that basically scan through all our reports
At this moment, all of our reports are currently written in stored procedures. We
We want to encrypt all our web app configuration files that we deploy to
We have for all our tests a method which starts a Jetty Server to
Currently we got a web service up and running that handles all our C.R.U.D
I have a single server that hosts our production and development databases. It's running
We are building a Java app that creates reports from various data sources. For
we are using NCover from http://www.ncover.com/ For our application we have 6 different solution

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.