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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:25:42+00:00 2026-06-11T08:25:42+00:00

I have a big class hierarchy. When my app starts, I initialize UnityContainer object

  • 0

I have a big class hierarchy.
When my app starts, I initialize UnityContainer object and configure it.
After that I always passing it through constructors to another classes in hierarchy.
Something like this :

Unity container has these classes as Registrations: IClassA, IClassB, IClassC, IClassD

All concrete implementations of interfaces have constructor with IUnityContainer parameter.
For example,

    public class ClassA : IClassA
    {

        public ClassA(IUnityContainer unityContainer)
        {
        }
    }

So, every time when I’m creating a new instance of some class I must pass an object of IUnityContainer.

May I reduce amount of passing IUnityContainer object as constructor’s parameter?
Maybe by using Dependency attribute ?

  • 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-11T08:25:44+00:00Added an answer on June 11, 2026 at 8:25 am

    Yes, you should reduce it.

    You should reduce it to 0.

    Using DI container like this is a bad practice. Don’t treat DI container as a magical super factory.

    You should only use the container to make it easier to compose your application at the composition root: read this

    Your code shouldn’t be aware that it is composed with a DI container, container is just a technology while DI is a technic. You should be able to compose your application without a container too.

    So, how you can reduce it? Like this:

    public class ClassA : IClassA
    {
        public ClassA()
        {
        }
    }
    

    Then if your ClassA needs something (a dependency, an interface), then you should inject that via constructor for example.

    public class ClassA : IClassA
    {
        private readonly IComponent _component;        
    
        public ClassA(IComponent component)
        {
            _component = component;
        }
    }
    

    You can use another injection patterns too: property injection, method injection, ambient context.

    If you use a container like in your question then you hide all the dependencies of the actual class. You can’t figure out what that actual class needs to work because it will use the container to resolve something ad-hoc. It’s completely againts dependency injection because you not inject dependencies, you just inject a generic factory (you can ask for anything) which is very dangerous and highly increases complexity for nothing.

    I highly recommend this book: Dependency Injection in .NET – Mark Seemann

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

Sidebar

Related Questions

Here's the deal. I have a big class hierarchy and I have this one
I have a big class. To sum up, it has only one method that
I have a big winform class that calls from a little one like this:
I have big system that make my system crash hard. When I boot up,
I have big problem when I am trying to deploy my app over clickonce.
I have big element at the top of the webpage that sides down with
I have a big C++ class, which includes 5 other classes inside, and some
I have a very big PHP class called Player. There is a lot of
I got a rather big class library that contains a lot of code. I
Working on a database class that got quite big, and is likely to get

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.