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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T19:52:08+00:00 2026-05-18T19:52:08+00:00

I am trying to get started with Castle.Windsor and following a comment I made

  • 0

I am trying to get started with Castle.Windsor and following a comment I made on the samples currently available for newbies (http://stw.castleproject.org/Windsor.Silvertlight_Sample_App_Customer_contact_manager.ashx?Discuss=1), I thought I’d take the bull by the horns and update the example provided here http://dotnetslackers.com/articles/designpatterns/InversionOfControlAndDependencyInjectionWithCastleWindsorContainerPart1.aspx.

This is a simple and fairly straightforward console application making use of Castle Windsor, albeit an outdated version. My Main method in Program.cs is as follows:

public static void Main()
    {
        IWindsorContainer container = new WindsorContainer();

        container.Install(FromAssembly.This());
        var retriever = container.Resolve<IHtmlTitleRetriever>();

        Console.WriteLine(retriever.GetTitle(new Uri(ConfigurationManager.AppSettings["fileUri"])));

        Console.Read();

        container.Dispose();
    }

and the Service and Components, which are all in the same file i.e. Program.cs are thus:

public interface IHtmlTitleRetriever
{
    string GetTitle(Uri file);

}

public interface IFileDownloader
{
    string Download(Uri file);
}

public interface ITitleScraper
{
    string Scrape(string fileContents);
}

public class HtmlTitleRetriever: IHtmlTitleRetriever
{
    private readonly IFileDownloader _downloader;
    private readonly ITitleScraper _scraper;

    public HtmlTitleRetriever(IFileDownloader dowloader, ITitleScraper scraper)
    {
        _downloader = dowloader;
        _scraper = scraper;
    }

    public string GetTitle(Uri file)
    {
        string fileContents = _downloader.Download(file);
        return _scraper.Scrape(fileContents);
    }
}



public class HttpFileDownloader : IFileDownloader
{
    public string Download(Uri file)
    {
        return new WebClient().DownloadString(file);
    }
}

public class StringParsingTitleScraper : ITitleScraper
{
    public string Scrape(string fileContents)
    {
        string title = string.Empty;
        int openingTagIndex = fileContents.IndexOf("<title>");
        int closingTagIndex = fileContents.IndexOf("</title>");

        if(openingTagIndex != -1 && closingTagIndex != -1)
            title = fileContents.Substring(openingTagIndex, closingTagIndex - openingTagIndex).Substring(7);

        return title;
    }
}

It is pretty much a straight copy of what Simone Busoli has from his example. The code compiles fine but I get the following error when I run the application:

No component for supporting the service WindsorSample.IHtmlTitleRetriever was found

I understand what that means but I don’t know what I’m doing wrong that the components are not getting loaded into the container. I’m using Castle.Windsor 2.5.2 and .NET 4.0.

Looking forward to the answers,

David

  • 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-18T19:52:08+00:00Added an answer on May 18, 2026 at 7:52 pm

    Following Krzysztof’s advice, here is how to get my simple example going:

     public static void Main()
        {
            var container = new WindsorContainer();
    
           // container.Install(FromAssembly.This());
            container.Register(
                Component.For( typeof( IHtmlTitleRetriever ) ).ImplementedBy( typeof(HtmlTitleRetriever) ) ,
                Component.For( typeof( IFileDownloader ) ).ImplementedBy( typeof( HttpFileDownloader ) ),
                Component.For( typeof( ITitleScraper ) ).ImplementedBy( typeof( StringParsingTitleScraper ) )
             );
            var retriever = container.Resolve<IHtmlTitleRetriever>();
    
            Console.WriteLine(retriever.GetTitle(new Uri(ConfigurationManager.AppSettings["fileUri"])));
    
            Console.Read();
    
            container.Dispose();
        }
    

    That will work.


    Krzysztof, we also tried this

     container.Register(
                AllTypes.FromThisAssembly().Pick().If(Component.IsCastleComponent)
            );
    

    and adorned all the classes appropriately but I still got the same error as before. Can you shed some light on this please?

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

Sidebar

Related Questions

I'm trying to get started with spine.js following the steps here: http://spinejs.com/docs/started When i
I'm trying to get to the latest of nservicebus and castle windsor: My issue
I have some experience with NHibernate and I'm trying to get started with Castle
Im just trying to get started with learning C http://fromlearncodethehardway.com . However I'm stuck
Im trying to get started with app development. Isnt this the corrent JDK if
Im trying to get started with silverlight for wp7 and I understand its Silverlight
I've been trying to get started with scipy, but the package is giving me
I am trying to get started in testing ActiveAdmin, in particular I need to
I am trying to get started with iOS Airplay (split screen and mirroring) and
I am trying to get started with scons . I have Python 3.0.1 and

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.