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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:02:58+00:00 2026-05-13T12:02:58+00:00

I have the following code, and when I try to run it, I can

  • 0

I have the following code, and when I try to run it, I can see that the BrokerProvider is not being resolved. Here is my code:

static void Main(string[] args)
        {
            IUnityContainer container = new UnityContainer();
            UnityConfigurationSection section = (UnityConfigurationSection) ConfigurationManager.GetSection("unity");
            section.Containers.Default.Configure(container);

            new TestBroker().RunTestBroker();              
        }


class TestBroker
    {
        private IBrokerProvider brokerProvider;

        public void RunTestBroker()
        {
            List<IPortfolio> portfolios = BrokerProvider.GetPortfolios();
        }

        [Dependency]
        public IBrokerProvider BrokerProvider
        {
            get { return brokerProvider; }
            set { brokerProvider = value; }
        }
    }

The related config

 <unity>
    <typeAliases>
      <typeAlias alias="string" type="System.String, mscorlib" />
      <typeAlias alias="singleton" type="Microsoft.Practices.Unity.ContainerControlledLifetimeManager, Microsoft.Practices.Unity" />
      <typeAlias alias="IBrokerProvider" type="PA.Common.Interfaces.IBrokerProvider, PA.Common" />

      <typeAlias alias="PManager" type="PA.BrokerProviders.PManager, PA.BrokerProviders" />
    </typeAliases>
    <containers>
      <container>
        <types>
          <type type="IBrokerProvider" mapTo="PManager">
            <lifetime type="singleton" />
          </type>
        </types>
      </container>
    </containers>
  </unity>

Another question: Do I need to repeat the same 3 lines of code that I have under main in every other class that I would like to use unity or setting it up once is enough?

  • 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-13T12:02:58+00:00Added an answer on May 13, 2026 at 12:02 pm

    That’s because are creating TestBroker directly by calling operator new on it:

    new TestBroker().RunTestBroker();
    

    In order for unity to resolve your dependencies you need to call the framework like so:

    var broker = container.Resolve<TestBroker>();
    

    IUnityContainer is the interface that is going to be doing all the work for you – i.e. resolving types to instances. You only need to create it once and then just pass it around the application where ever you need it.

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

Sidebar

Related Questions

I have this following code fragment which is accessed by different threads. try {
In my python code I have this line: try: result = eval(command, self.globals, self.locals)
I have joined a team developing an ASP.NET MVC version 1 application. I run
For context see post Following the awsome sugestion provided by yock, I changed my
I have a Role domain class, which I have simplified to illustrate the case
I have a user control I'm building (ASP.NET 3.5, using C#). This control is
I'm writing a networking program in Java. I use ServerSocket and Socket objects to
I am developing a GUI to launch an external long-term running background program. This
Thank you so much for reading this! I think the fix is relatively easy,
I'm trying to parse a moderately large XML file (6mb) in php using simpleXML.

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.