Is there a platform for developing dependencies for Delphi using attribute-based?

I would like to be able to code in Delphi this way, just annotating the field:

type
  TMyClass = class
  private
    [Inject]
    Factory: ISomeFactory;
    ...
  end;

or by assigning a setter

type
  TMyClass = class
  private
    FFactory: ISomeFactory;

    [Inject]
    procedure SetFactory(const AFactory: ISomeFactory);
    ...
  public
    property Factory: ISomeFactory read FFactory write SetFactory;
  end;

Background: I move the old code to a service-oriented architecture and find that a link to the service level always leads to constructions like

DataModule1.ServiceLayerInstance1.SubSystemN.InvokeSomething(Params, ...);

which can be much shorter than

type
  Form1 = class(TForm1)
  private
    [Inject]
    SubsystemN: ISubsystemN;
    ...
  end;
  ...
  SubsystemN.InvokeSomething(Params, ...);
+5
source share
2 answers

Yes there is. Delphi Spring Structure

http://www.spring4d.com/

does just that. It has the [Inject] attribute.

One caveat - to use it, you need to include the Spring block in your code where the attribute is specified. Otherwise, the compiler will ignore the attribute.

+9
source
+2

All Articles