Search code examples
listparameterscastle-windsorcastle

castle windsor: how to register a list programmatically (instead with a configuration file)


I would like to register an object with a list parameter, but without using a configuration file. this is the configuration file that I currently use:

<?xml version="1.0" encoding="utf-8" ?>
<castle>
  <components>
    <component id="EmailParser"
     service="ESImportCommon.Email.IEmailParser, ESImportCommon"
     type="ESImportCommon.Email.EmailParser, ESImportCommon">
    </component>
  </components>
</castle>

Solution

  • You can do it like this:

            using ESImportCommon.Email;
    
            ....
    
            var container = new WindsorContainer(new XmlInterpreter()); 
            container.AddFacility<FactorySupportFacility>();
            container.Register(Component.For<IEmailParser>().ImplementedBy<EmailParser>());
    

    Note that you don't need to pass an instance of XmlInterpreter to the constructor if you do not want any configuration in your web/app.config.