Spring resolver problem...

Spring resolver problem...
I try resolve factory method (previously registered in container) and I get compile error:

{$M+}
TCompaniesManagerFactory = reference to function(const aAuthKey : RAuthKey) : ICompaniesManager;
{$M-}

var
lCompaniesManagerFactory : TCompaniesManagerFactory;
begin
lCompaniesManagerFactory := Container.Resolve; <- line with error

Error:

[dcc32 Error] E2010 Incompatible types: 'TCompaniesManagerFactory' and 'Procedure of object'

ps. I know about composition root and others IoC rules... please tell me why I get compile error, types are compatible

Comments

  1. Sorry, I use Spring4D of course.
    How to fix this problem?

    ReplyDelete
  2. Put parentheses on your call. When assigning a function call result to an anonymous method variable it does not consider calling the method to get an assignment compatible result. Most simple case:

    uses
    System.SysUtils;

    function GiveProc: TProc;
    begin
    end;

    var
    p: TProc;
    begin
    p := GiveProc; // <- E2010 - write GiveProc() and it works
    end.

    ReplyDelete
  3. Stefan Glienke Thx! Mea culpa, stupid (and hidden) error :-)

    ReplyDelete

Post a Comment