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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T21:33:05+00:00 2026-05-10T21:33:05+00:00

I am having a problem using the Unity Application Block, I have created a

  • 0

I am having a problem using the Unity Application Block, I have created a base class called Composition.

Each Composition contains a IUnityContainer, when i create the top level object UniversalComposition i want to initialize it with a UnityContainer.

Any object that gets created from the UniversalComposition I want to inject a child IUnityContainer into it, using the IUnityContainer.CreateChildContainer method.

class Program {     static void Main(string[] args)     {         UniversalComposition universe = new UniversalComposition();       } }  public class UniversalComposition : Composition {     // Everything that gets resolved in this container should contain a child container created by the this container      public UniversalComposition()     {         this.Container.RegisterType<IService, Service>();     }      protected override IUnityContainer CreateContainer()     {         return new UnityContainer();     }  }  public abstract class Composition {     protected IUnityContainer Container {get; private set;}      public Composition()     {         this.Container = this.CreateContainer();     }      public TInstance Resolve<TInstance>()     {         return this.Container.Resolve<TInstance>();     }      protected abstract IUnityContainer CreateContainer(); }  public class Service : Composition, IService {     public Service(/* I want to inject a child Unity Container in here container.CreateChildContainer() */)     {     } }  public interface IService { } 
  • 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. 2026-05-10T21:33:06+00:00Added an answer on May 10, 2026 at 9:33 pm

    I don’t think this will work via injection as you have it implemented in the parent since the parent container doesn’t exist until the child object is instantiated. Thus you have no way to generate the child container to inject. A better way would be to inject the parent container via a parameterized constructor on the base class, then inject both in the child class. The default constructor could call the parameterized constructor with null and the parameterized constructor could detect this and create a container if one isn’t specified. The example below is simplified for clarity.

    public abstract class BaseClass {     public IUnityContainer Container { get; protected set; }      public BaseClass() : BaseClass(null) {}      public BaseClass( IUnityContainer container )     {         this.container = container ?? this.CreateContainer();     }      public abstract IUnityContainer CreateContainer(); }  public class DerivedClass : BaseClass {     public IUnityContainer ChildContainer { get; private set; }      public DerivedClass() : DerivedClass(null,null) {}      public DerivedClass( IUnityContainer parent, IUnityContainer child )         : BaseClass( parent )     {         this.ChildContainer = child ?? this.CreateChildContainer();     }      public IUnityContainer CreateContainer()     {          return new UnityContainer();     }      public IUnityContainer CreateChildContainer()     {          return this.Container.CreateChildContainer();     }  } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 70k
  • Answers 70k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer See what EXPLAIN EXTENDED says. If it says DEPENDENT SUBQUERY… May 11, 2026 at 1:05 pm
  • added an answer A few I can think of are namespace pollution and… May 11, 2026 at 1:05 pm
  • added an answer That is the buffer for output, but a file upload… May 11, 2026 at 1:05 pm

Related Questions

I am using the tablesorter plugin ( http://tablesorter.com ) and am having a problem
I'm having the problem described here: http://groups.google.com/group/microsoft.public.xml.soap/browse_thread/thread/029ee5b5d4fa2440/0895d73c5c3720a1 I am consuming a Web Service using
I am having problems converting a string in the format yyyy-MM-ddZ using VB.net. For
I am having a problem with the speed of accessing an association property with
For some school groupwork, I'm making a Generic Pizza Delivery Everything Management System, and
I use an HttpHandler to dynamically serve images in a ASP.Net web application. I
I'm having a bit of trouble doing some unit-testing using moq. If I have
(Title was: How to write a unit test for a DBUS service written in

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.