title: delphi - how to pass a parameter from the instantiator to a constructor in the spring4d dependency injection framework?
body: <p>It's possible to register a class with a parameter expected to be passed from the point of creation?</p>
  
  <p>I know it can be done something like this:</p>
  
  <pre><code>GlobalContainer.RegisterType&lt;TUserProcessor&gt;.Implements&lt;IUserUpgrader&gt;.
  AsTransient.DelegateTo(
      function: TUserProcessor
      begin
        Result := TUserProcessor.Create(GetCurrentUser);
      end
    );
  </code></pre>
  
  <p>But there the parameters are binded to the execution context where the container gets registered and not where the object get's intantiated.</p>
  
  <p>Something like this it's possible for example?</p>
  
  <pre><code>GlobalContainer.Resolve&lt;IMathService&gt;([FCurrentUser]);
  </code></pre>
  
  <p>I know some peoble advocate to have very simple constructors, but there are times when a constructor parameter looks clearly the way to go:</p>
  
  <ol>
  <li><p>The object constructed needs the object parameter to work, so the reference must be satisfied. The parameter also makes that constraint much more obvious looking at the class.</p></li>
  <li><p>You can assign the reference in a method or property and raise and exception in every other method if you try to use the object without first making the assignment.. I don't like writing this type of code it's simply a waste of time, just use the constructor parameter and check there. Less code, the better IMO.</p></li>
  <li><p>Also the object being passed it's local to the object that constructs the new object using the container (for example a Transaction object) and has some state (it's not a new object that I can get with the container).</p></li>
  </ol>