views:

23

answers:

1

Given this legacy XML configuration for Castle Windsor:

>  <parameters>
>     <AdditionalMessage>#{message}</AdditionalMessage>
>     <Files>#{files}</Files>
>     <downloaders>
>       <array>
>         <item>${HttpFileDownloader}</item>
>         <item>${HttpsFileDownloader}</item>
>         <item>${FtpFileDownloader}</item>
>         <item>${FileSystemFileDownloader}</item>
>       </array>
>     </downloaders>
>     <?if DEBUG?>
>     <scraper>${BenchmarkingTitleScraperDecorator}</scraper>
>     <?else?>
>     <scraper>${RegexTitleScraper}</scraper>
>     <?end?>   </parameters>

How would one do this using IWindsorInstaller? I have this so far, not sure if I'm on the correct track:

   container.Register(Component
                .For<HtmlTitleRetriever>()
                .Named("HtmlTitleRetriever")
                .DependsOn(Property.ForKey("AdditionalMessage").Eq("#{message}"))
                .DependsOn(Property.ForKey("Files").Eq("#{files}"))
                .DependsOn(Property.ForKey("Files").Eq("#{files}"))
                 .DependsOn(Property.ForKey("downloaders").Is<IFileDownloader>())
                );
A: 
 public class ContainerInstaller : IWindsorInstaller
    {
        public void Install(IWindsorContainer container, Castle.MicroKernel.SubSystems.Configuration.IConfigurationStore store)
        {

            //scrapers
            container.Register(Component.For<ITitleScraper>().ImplementedBy<StringParsingTitleScraper>().Named("StringParsingTitleScraper"));
            container.Register(Component.For<ITitleScraper>().ImplementedBy<RegexTitleScraper>().Named("RegexTitleScraper"));


            //list of downloaders
            container.Kernel.Resolver.AddSubResolver(new ListResolver(container.Kernel));
            container.Register(Component.For<IFileDownloader>().ImplementedBy<HttpFileDownloader>().Named("HttpFileDownloader"));
            container.Register(Component.For<IFileDownloader>().ImplementedBy<FtpFileDownloader>().Named("FtpFileDownloader"));
            container.Register(Component.For<IFileDownloader>().ImplementedBy<FileSystemFileDownloader>().Named("FileSystemFileDownloader"));

            //register concrete management class
            container.Register(Component
                .For<HtmlTitleRetriever>()
                .Named("HtmlTitleRetriever")
                .DependsOn(Property.ForKey("AdditionalMessage").Eq("message"))
#if (DEBUG)
                .DependsOn(Property.ForKey("scraper").Is("BenchmarkingTitleScraperDecorator"))
#else
                .DependsOn(Property.ForKey("scraper").Is("StringParsingTitleScraper"))
#endif
            );

            //now load the stuff that we want to configure from xml
            container.Install(Configuration.FromAppConfig());
Tom DeMille

related questions