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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:39:03+00:00 2026-05-15T05:39:03+00:00

I am trying to use Castle Windsor with MS Test. The test class only

  • 0

I am trying to use Castle Windsor with MS Test. The test class only seems to use the default constructor. How do I configure Castle to resolve the service in the constructor?

Here is the Test Class’ constructors:

private readonly IWebBrowser _browser;

        public DepressionSummaryTests()
        {

        }

        public DepressionSummaryTests(IWebBrowser browser)
        {
            _browser = browser;
        }

My component in the app config looks like so:

 <castle>
    <components>
      <component id="browser"
                 service="ConversationSummary.IWebBrowser, ConversationSummary"
                 type="ConversationSummary.Browser" />       

    </components>
  </castle>

Here is my application container:

public class ApplicationContainer : WindsorContainer
    {
        private static IWindsorContainer container;

        static ApplicationContainer()
        {
            container = new WindsorContainer(new XmlInterpreter(new ConfigResource("castle")));
        }
        private static IWindsorContainer Container
        {
            get { return container; }
        }

        public static IWebBrowser Browser
        {
            get { return (IWebBrowser) Container.Resolve("browser"); }
        }
    }

MS test requires the default constructor. What am I missing?

Thanks!

  • 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-15T05:39:03+00:00Added an answer on May 15, 2026 at 5:39 am

    Since MSTest requires the default constructor it also means that it only uses this constructor. Thus, you can never get it to use the overloaded constructor. That’s not an issue with Castle Windsor, but just the way MSTest works.

    It’s not that big of a deal though, because you shouldn’t need to use a container for unit testing anyway.

    When you use Windsor, you may want to consider using the Fluent Registration API instead of XML.

    Another thing is that you shouldn’t use a static Service Locator – it’s an anti-pattern. This means that the ApplicationContainer class is redundant and should be deleted.

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

Sidebar

Related Questions

I'm trying to use Castle Windsor to create my message handlers because just using
I have created an ASP.NET MVC application and am trying to use Castle Windsor
I am trying to use the XMLSerializer with a castle active record class which
Trying to use an excpetion class which could provide location reference for XML parsing,
I am trying out Castle ActiveRecord. I want to use the Validation features AND
I am using a custom ControllerFactory (to use Castle Windsor's IOC to create controllers),
I am trying use filehelpers class builder but I am kinda confused on what
I am trying to register a facility in Castle Windsor using the fluent apis
I have a C# .Net Web Service. I am trying to use nHibernate to
I'm trying to remove some logging dependencies and stumbled across Castle Windsor's logging facility.

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.