title: Castle Windsor Resolve at run time
body: <p>I have been trying to fix this issue for quite a while and I am still none the wiser. I have got the following method:</p>
  
  <pre><code>public IResult Parse(string[] args)
  {
      var argumentOption = new ArgumentOption(_dataModelBinder);
      var boundArgumentOption = argumentOption.Bind(args);
  
      var bindingResults = boundArgumentOption.Validate(_argumentOptionValidator);
  
      // AREA OF INTEREST
      if (bindingResults.Any())
      {
          return new ErrorResult();
      }
  
      return new CreateReportResult(
          _resultActioner
          , boundArgumentOption.OutputFilePath
          , boundArgumentOption.PatientId
          , "database");
  }
  </code></pre>
  
  <p>The code I'm having trouble with involves the return values which I'm newing up, which ideally I'd like to leave to Castle Windsor to deal with. So, what I then did was to create an Abstract factory:</p>
  
  <pre><code>public interface IResultFactory
  {
      IResult Create(int numOfErrors);
  } 
  
  public class ResultFactory : IResultFactory
  {
      private readonly IWindsorContainer _container;
  
      public ResultFactory(IWindsorContainer container)
      {
          _container = container;
      }
  
      public IResult Create(int numOfErrors)
      {
          if (numOfErrors &gt; 0)
          {
              return _container.Resolve&lt;IResult&gt;("ErrorResult");
          }
  
          return _container.Resolve&lt;IResult&gt;("CreateReportResult");
      }
  }
  </code></pre>
  
  <p>and my Parse method now becomes:</p>
  
  <pre><code>public IResult Parse(string[] args)
  {
      var argumentOption = new ArgumentOption(_dataModelBinder);
      var boundArgumentOption = argumentOption.Bind(args);
  
      var bindingResults = boundArgumentOption.Validate(_argumentOptionValidator);
  
      IResult result = _factory.Create(bindingResults.Count());
  
      return result;
  }
  </code></pre>
  
  <p>What I'm having a great deal of problem with is how to do the registration and dynamically pass in the parameters because the constructor for CreateReportResult is:</p>
  
  <pre><code>public CreateReportResult(IResultActioner resultActioner, Uri filePath, string patientId, string dataSource)
  </code></pre>
  
  <p>So the question is how do I set up my registration code in my WindsorContainer installer and how do I then pass in the required parameters? I am using Castle Windsor 3.2.</p>
  
  <p>Here is the code I have in my registration:</p>
  
  <pre><code>container.Register(
    Component
      .For&lt;IResult&gt;()
      .ImplementedBy&lt;ErrorResult&gt;()
      .Named("ErrorResult")
      .LifeStyle.Transient
      , Component.For&lt;IResultFactory&gt;()
      .AsFactory()
  );
  
  container.Register(
    Component
      .For&lt;IResult&gt;()
      .ImplementedBy&lt;CreateReportResult&gt;()
      .Named("CreateReportResult")
      .LifeStyle.Transient
      , Component.For&lt;IResultFactory&gt;()
      .AsFactory()
  );
  </code></pre>