I'm using the Spring.Container in some refactoring and am looking for some clarification on the best way (and where - I'll post that separately don't want to confuse things) to set up the factories. I have done this elsewhere, but always where there was a distinct constructor for a type.

I'm using the Spring.Container in some refactoring and am looking for some clarification on the best way (and where - I'll post that separately don't want to confuse things) to set up the factories. I have done this elsewhere, but always where there was a distinct constructor for a type.

There is a single interface, let's call it IFileInfoDisplay (because that is what it is called). There are 3 type registrations along the lines of

container.RegisterType('basic');
container.RegisterType('history');
container.RegisterType('extended');

Each type takes the same constructor Create(aFileInfo: TFileInfo). TFileInfo is returned from a RemObjects server, hence not an interface.

So can I register the factory and call it with the discriminator

Container.resolve('history');

or do I need to register it for each type?

Thanks.

(originally posted in the "Coding In Delphi" community)

Comments

  1. Here is the very same question: (https://stackoverflow.com/questions/9952353/delphi-how-to-pass-a-parameter-from-the-instantiator-to-a-constructor-in-the-s), but I'm afraid things were changed in new versions of spring4d, since I've done GREP searches into the spring4d source, I couldn't find TParameterOverride nor TOrderedParametersOverride.
    stackoverflow.com - delphi - how to pass a parameter from the instantiator to a constructor in the spring4d dependency injection framework?

    ReplyDelete
  2. Thanks Edwin - I missed that one. But, as you say, it has changed quite a bit lately.

    ReplyDelete
  3. So let's wait for Stefan Glienke's comment?

    ReplyDelete
  4. Russell, I think I found the answer. Use TContainer.Resolve(const arguments: array of TValue): T;

    Please check the TTestResolverOverride.TestResolve
    test method in Spring.Tests.Container.pas.

    ReplyDelete

Post a Comment