Commits

Nick Hodges  committed 369524e

Major changes to accommodate and demonstrate re-org of the Spring4D codebase

  • Participants
  • Parent commits 84e73b5

Comments (0)

Files changed (29)

File Demo.VirtualInterceptor.res

Binary file added.

File DependencyInjection/Intro/6-UseContainer/uServiceLocator.pas

-unit uServiceLocator;
-
-interface
-
-uses
-        Spring.DI
-      ;
-
-  function ServiceLocator: TContainer;
-
-implementation
-
-var
-  FContainer: TContainer;
-
-function ServiceLocator: TContainer;
-begin
-  if FContainer = nil then
-  begin
-    FContainer := TContainer.Create;
-  end;
-  Result := FContainer;
-end;
-
-
-end.

File DependencyInjection/Intro/7-CustomConstructor/uServiceLocator.pas

-unit uServiceLocator;
-
-interface
-
-uses
-        Spring.DI
-      ;
-
-  function ServiceLocator: TContainer;
-
-implementation
-
-var
-  FContainer: TContainer;
-
-function ServiceLocator: TContainer;
-begin
-  if FContainer = nil then
-  begin
-    FContainer := TContainer.Create;
-  end;
-  Result := FContainer;
-end;
-
-
-end.

File DependencyInjection/Intro/8-FieldInjection/uServiceLocator.pas

-unit uServiceLocator;
-
-interface
-
-uses
-        Spring.DI
-      ;
-
-  function ServiceLocator: TContainer;
-
-implementation
-
-var
-  FContainer: TContainer;
-
-function ServiceLocator: TContainer;
-begin
-  if FContainer = nil then
-  begin
-    FContainer := TContainer.Create;
-  end;
-  Result := FContainer;
-end;
-
-
-end.

File SpringDemos/Demo.DependencyInjection/Demo.Spring.ConstructorInjection.dpr

 uses
   SysUtils,
   Classes,
-  uConstructorInjectionDemo in 'uConstructorInjectionDemo.pas',
-  uServiceLocator in 'uServiceLocator.pas';
+  Spring.Services,
+  Spring.Container,
+  uConstructorInjectionDemo in 'uConstructorInjectionDemo.pas';
 
 var
   SCC: ISimpleContainerInterface;
 
 begin
   try
-    ServiceLocator.Build;
-    SCC := ServiceLocator.Resolve<ISimpleContainerInterface>;
+    GlobalContainer.Build;
+    SCC := ServiceLocator.GetService<ISimpleContainerInterface>;
     if SCC.SimpleClass <> nil then
     begin
       WriteLn('SCC.SimpleClass.MyPoint = ', SCC.SimpleClass.MyPoint.X, ', ', SCC.SimpleClass.MyPoint.Y);

File SpringDemos/Demo.DependencyInjection/Demo.Spring.ConstructorInjection.dproj

 				<MainSource>MainSource</MainSource>
 			</DelphiCompile>
 			<DCCReference Include="uConstructorInjectionDemo.pas"/>
-			<DCCReference Include="uServiceLocator.pas"/>
 			<BuildConfiguration Include="Release">
 				<Key>Cfg_2</Key>
 				<CfgParent>Base</CfgParent>

File SpringDemos/Demo.DependencyInjection/Demo.Spring.DependencyInjection.dpr

   SysUtils,
   Classes,
   Spring,
+  Spring.Container,
+  Spring.Services,
   uStringListService,
   uWackyMathService in 'uWackyMathService.pas',
   uNormalMathService in 'uNormalMathService.pas',
-  uServiceLocator in 'uServiceLocator.pas',
   uCalculator in 'uCalculator.pas',
   MathServiceConsts in 'MathServiceConsts.pas',
   uMathInterfaces in 'uMathInterfaces.pas',
 begin
   try
 
-    ServiceLocator.Build;
+    GlobalContainer.Build;
 
-    CalculatorService := ServiceLocator.Resolve<ICalculator>(CalculatorName);
+    CalculatorService := ServiceLocator.GetService<ICalculator>(CalculatorName);
     WriteLn('Using Calculator with injected field...');
     WriteLn(CalculatorService.Addition(2, 3), ', ', CalculatorService.Multiplication(3, 4));
     WriteLn;
 
-    RegisterIniFileService(ServiceLocator, 'Inifile', 'blah.ini', iftFileBased);
-    RegisterIniFileService(ServiceLocator, 'MemInifile', 'blah.ini', iftMemoryBased);
+    RegisterIniFileService('Inifile', 'blah.ini', iftFileBased);
+    RegisterIniFileService('MemInifile', 'blah.ini', iftMemoryBased);
 
-    IniFile := ServiceLocator.Resolve<IIniFileService>('Inifile');
+    IniFile := ServiceLocator.GetService<IIniFileService>('Inifile');
     WriteLn(IniFile.FileName);
     IniFile.WriteString('one', 'two', 'three');
     WriteLn(IniFile.ReadString('one', 'two', 'failed'));
     WriteLn(IniFile.ReadInteger('blah', 'two', -1));
     WriteLn;
 
-    IniFile := ServiceLocator.Resolve<IIniFileService>('MemInifile');
+    IniFile := ServiceLocator.GetService<IIniFileService>('MemInifile');
     WriteLn(IniFile.FileName);
     IniFile.WriteString('one', 'two', 'three');
     WriteLn(IniFile.ReadString('one', 'two', 'failed'));
     WriteLn(IniFile.ReadInteger('blah', 'two', -1));
     WriteLn;
 
-    SLS := ServiceLocator.Resolve<IStringListService>('DSL');
+    SLS := ServiceLocator.GetService<IStringListService>('DSL');
     SLS.Add('one');
     SLS.Add('two');
     SLS.Add('buckle my shoe');
 
     RegisterInjectionTestServices('SpecialType.AString set in the Factory via the property injection attribute at: ' + DateTimeToStr(Now));
 
-    MyIntf := ServiceLocator.Resolve<IMyInterface>;
+    MyIntf := ServiceLocator.GetService<IMyInterface>;
 
     CheckNotEmptyBeforeWriting(MyIntf.SomeString, 'MyIntf.SomeString', 'SomeString set in constructor: ');
     WriteLn('SomeInteger injected value: ', MyIntf.SomeInteger);

File SpringDemos/Demo.DependencyInjection/Demo.Spring.DependencyInjection.dproj

 			</DelphiCompile>
 			<DCCReference Include="uWackyMathService.pas"/>
 			<DCCReference Include="uNormalMathService.pas"/>
-			<DCCReference Include="uServiceLocator.pas"/>
 			<DCCReference Include="uCalculator.pas"/>
 			<DCCReference Include="MathServiceConsts.pas"/>
 			<DCCReference Include="uMathInterfaces.pas"/>

File SpringDemos/Demo.DependencyInjection/Demo.Spring.FieldInjection.dpr

 
 uses
   System.SysUtils,
-  uFieldInjectionDemo in 'uFieldInjectionDemo.pas',
-  uServiceLocator in 'uServiceLocator.pas';
+  Spring.Container,
+  Spring.Services,
+  uFieldInjectionDemo in 'uFieldInjectionDemo.pas';
 
 var
   FID: IFieldInjectionDemo;
 begin
   try
-    ServiceLocator.Build;
-    FID := ServiceLocator.Resolve<IFieldInjectionDemo>;
+    GlobalContainer.Build;
+    FID := ServiceLocator.GetService<IFieldInjectionDemo>;
     FID.UseSomeClass;
   except
     on E: Exception do

File SpringDemos/Demo.DependencyInjection/Demo.Spring.FieldInjection.dproj

 				<MainSource>MainSource</MainSource>
 			</DelphiCompile>
 			<DCCReference Include="uFieldInjectionDemo.pas"/>
-			<DCCReference Include="uServiceLocator.pas"/>
 			<BuildConfiguration Include="Release">
 				<Key>Cfg_2</Key>
 				<CfgParent>Base</CfgParent>

File SpringDemos/Demo.DependencyInjection/Demo.Spring.PropertyInjection.dpr

 
 uses
   System.SysUtils,
-  uPropertyInjection in 'uPropertyInjection.pas',
-  uServiceLocator in 'uServiceLocator.pas';
+  Spring.Container,
+  Spring.Services,
+  uPropertyInjection in 'uPropertyInjection.pas';
 
 var
   Car: ICar;
 
 begin
   try
-    ServiceLocator.Build;
-    Car := ServiceLocator.Resolve<ICar>;
+    GlobalContainer.Build;
+    Car := ServiceLocator.GetService<ICar>;
     Car.SteeringWheel.Direction := 272;
     Writeln('Car is currently heading ', Car.SteeringWheel.Direction, ' degrees');
   except

File SpringDemos/Demo.DependencyInjection/Demo.Spring.PropertyInjection.dproj

 				<MainSource>MainSource</MainSource>
 			</DelphiCompile>
 			<DCCReference Include="uPropertyInjection.pas"/>
-			<DCCReference Include="uServiceLocator.pas"/>
 			<BuildConfiguration Include="Release">
 				<Key>Cfg_2</Key>
 				<CfgParent>Base</CfgParent>

File SpringDemos/Demo.DependencyInjection/Demo.Spring.SimpleInjection.dpr

 
 uses
   SysUtils,
-  Spring,
-  uSimpleInjection in 'uSimpleInjection.pas',
-  uServiceLocator in 'uServiceLocator.pas';
+  Spring.Services,
+  Spring.Container,
+  uSimpleInjection in 'uSimpleInjection.pas';
 
 var
     Pet: IPetNoiseMaker;
 
 begin
   try
-    ServiceLocator.Build;
+    GlobalContainer.Build;
 
 
-    Pet := ServiceLocator.Resolve<IPetNoiseMaker>;
+    Pet := ServiceLocator.GetService<IPetNoiseMaker>;
     Pet.MakePetNoises;
     Pet.MakePetNoises('Cat');
     Pet.MakePetNoises('Cow');

File SpringDemos/Demo.DependencyInjection/Demo.Spring.SimpleInjection.dproj

 				<MainSource>MainSource</MainSource>
 			</DelphiCompile>
 			<DCCReference Include="uSimpleInjection.pas"/>
-			<DCCReference Include="uServiceLocator.pas"/>
 			<BuildConfiguration Include="Release">
 				<Key>Cfg_2</Key>
 				<CfgParent>Base</CfgParent>

File SpringDemos/Demo.DependencyInjection/uCalculator.pas

 uses
            uMathInterfaces
          , uServiceNames
-         , uServiceLocator
-         , Spring
+         , Spring.Container
+         , Spring.Services
          ;
 
 type
 
 procedure RegisterCalculatorService;
 begin
-  ServiceLocator.RegisterComponent<TCalculator>.Implements<ICalculator>(CalculatorName);
+  GlobalContainer.RegisterComponent<TCalculator>.Implements<ICalculator>(CalculatorName);
 end;
 
 initialization

File SpringDemos/Demo.DependencyInjection/uConstructorInjectionDemo.pas

 
 uses
        Types
-     , uServiceLocator
      , Spring
      ;
 
 
 implementation
 
+uses
+     Spring.Container
+   , Spring.Services
+   ;
+
 type
   TSimpleClass = class(TInterfacedObject, ISimpleInterface)
   private
 end;
 
 initialization
-  ServiceLocator.RegisterComponent<TSimpleClassConsumer>.Implements<ISimpleContainerInterface>;
-  ServiceLocator.RegisterComponent<TSimpleClass>.Implements<ISimpleInterface>.InjectConstructor([56, 150]);
+  GlobalContainer.RegisterComponent<TSimpleClassConsumer>.Implements<ISimpleContainerInterface>;
+  GlobalContainer.RegisterComponent<TSimpleClass>.Implements<ISimpleInterface>.InjectConstructor([56, 150]);
 end.

File SpringDemos/Demo.DependencyInjection/uFieldInjectionDemo.pas

 
 uses
       Spring  // needed to get the attributes to work.
-    , uServiceLocator
+    , Spring.Container
+    , Spring.Services
     ;
 
 type
 end;
 
 initialization
-  ServiceLocator.RegisterComponent<TFieldInjectionDemo>.Implements<IFieldInjectionDemo>;
-  ServiceLocator.RegisterComponent<TSomeClass>.Implements<ISomeClass>;
+  GlobalContainer.RegisterComponent<TFieldInjectionDemo>.Implements<IFieldInjectionDemo>;
+  GlobalContainer.RegisterComponent<TSomeClass>.Implements<ISomeClass>;
 
 
 end.

File SpringDemos/Demo.DependencyInjection/uIniFileService.pas

 interface
 
 uses
-       Spring.DI
-     , Classes
+
+       Classes
      ;
 
 type
 type
   TIniFileType = (iftFileBased, iftMemoryBased);
 
-  procedure RegisterIniFileService(aContainer: TContainer; aServiceName: string; aFilename: string; aIniFileType: TIniFileType = iftFileBased);
+  procedure RegisterIniFileService(aServiceName: string; aFilename: string; aIniFileType: TIniFileType = iftFileBased);
 
 
 implementation
 
 uses
          IniFiles
-       , Spring
+       , Spring.Container
        ;
 
 type
   FIniFile.WriteTime(Section, Name, Value);
 end;
 
-procedure RegisterIniFileService(aContainer: TContainer; aServiceName: string; aFilename: string; aIniFileType: TIniFileType = iftFileBased);
+procedure RegisterIniFileService(aServiceName: string; aFilename: string; aIniFileType: TIniFileType = iftFileBased);
 begin
-  aContainer.RegisterComponent<TIniFileImpl>.Implements<IIniFileService>(aServicename).AsSingleton.DelegateTo(
+  GlobalContainer.RegisterComponent<TIniFileImpl>.Implements<IIniFileService>(aServicename).AsSingleton.DelegateTo(
     function: TIniFileImpl
     begin
       Result := TIniFileImpl.Create(aFilename, aIniFileType);
     end
   );
-  aContainer.Build;
+  GlobalContainer.Build;
 end;
 
 initialization

File SpringDemos/Demo.DependencyInjection/uInjectionDemo.pas

 interface
 
 uses
-  Classes, uServiceLocator, Spring;
+       Classes
+     , Spring
+     ;
 
 type
 
 
 implementation
 
-uses Spring.DI.Registration;
+uses
+       Spring.Container
+     , Spring.Services
+     ;
 
 type
   TPropertyInjectionDemo = class(TInterfacedObject, IMyInterface)
 
 procedure RegisterInjectionTestServices(aSpecialTypeString: string);
 begin
-  ServiceLocator.RegisterComponent<TPropertyInjectionDemo>
-                .Implements<IMyInterface>
-                .InjectField('FFieldInjectionString', 'Field Injection is working!')
-                .InjectMethod('SetSetterInjectionString', ['string from InjectMethod call'])
-                .InjectProperty('AnotherString', 'This value set by injection.')
-                .InjectConstructor(['Set from Spring DI', Random(100)])
+  GlobalContainer.RegisterComponent<TPropertyInjectionDemo>
+                 .Implements<IMyInterface>
+                 .InjectField('FFieldInjectionString', 'Field Injection is working!')
+                 .InjectMethod('SetSetterInjectionString', ['string from InjectMethod call'])
+                 .InjectProperty('AnotherString', 'This value set by injection.')
+                 .InjectConstructor(['Set from Spring DI', Random(100)])
 
     ;
-  ServiceLocator.RegisterComponent<TSpecialType>.Implements<TSpecialType>.DelegateTo(
+  GlobalContainer.RegisterComponent<TSpecialType>.Implements<TSpecialType>.DelegateTo(
   function: TSpecialType
   begin
     Result := TSpecialType.Create(aSpecialTypeString);
   end);
-  ServiceLocator.Build;
+  GlobalContainer.Build;
 end;
 
 { TPropertyInjectionDemo }

File SpringDemos/Demo.DependencyInjection/uNormalMathService.pas

 implementation
 
 uses
-       uServiceLocator
-     , uMathInterfaces
+       uMathInterfaces
      , uServiceNames
+     , Spring.Container
      ;
 type
 
 
 procedure RegisterNormalMathService;
 begin
-  ServiceLocator.RegisterComponent<TNormalMathServiceImplemenation>.Implements<IMathService>(NormalAdditionServiceName);
+  GlobalContainer.RegisterComponent<TNormalMathServiceImplemenation>.Implements<IMathService>(NormalAdditionServiceName);
 end;
 
 initialization

File SpringDemos/Demo.DependencyInjection/uPropertyInjection.pas

 implementation
 
 uses
-      uServiceLocator
-    , Spring
+      Spring.Container
+    , Spring.Services
     ;
 
 type
 end;
 
 initialization
-  ServiceLocator.RegisterComponent<TSteeringWheel>.Implements<ISteeringWheel>;
-  ServiceLocator.RegisterComponent<TCar>.Implements<ICar>;
+  GlobalContainer.RegisterComponent<TSteeringWheel>.Implements<ISteeringWheel>;
+  GlobalContainer.RegisterComponent<TCar>.Implements<ICar>;
 
 
 end.

File SpringDemos/Demo.DependencyInjection/uServiceLocator.pas

-unit uServiceLocator;
-
-interface
-
-uses
-        Spring.DI
-      ;
-
-  function ServiceLocator: TContainer;
-
-implementation
-
-var
-  FContainer: TContainer;
-
-function ServiceLocator: TContainer;
-begin
-  if FContainer = nil then
-  begin
-    FContainer := TContainer.Create;
-  end;
-  Result := FContainer;
-end;
-
-
-end.

File SpringDemos/Demo.DependencyInjection/uSimpleInjection.pas

 
 implementation
 
-uses  uServiceLocator;
+uses
+      Spring.Services
+    , Spring.Container
+    ;
+
 
 type
 
 
 procedure TPetNoiseProvider.MakePetNoises(aAnimalName: string);
 begin
-  FPet := ServiceLocator.Resolve<IMakeNoise>(aAnimalName);
+  FPet := ServiceLocator.GetService<IMakeNoise>(aAnimalName);
   FPet.MakeNoise;
 end;
 
 initialization
-  ServiceLocator.RegisterComponent<TCat>.Implements<IMakeNoise>('Cat');
-  ServiceLocator.RegisterComponent<TDog>.Implements<IMakeNoise>('Dog');
-  ServiceLocator.RegisterComponent<TCow>.Implements<IMakeNoise>('Cow');
+  GlobalContainer.RegisterComponent<TCat>.Implements<IMakeNoise>('Cat');
+  GlobalContainer.RegisterComponent<TDog>.Implements<IMakeNoise>('Dog');
+  GlobalContainer.RegisterComponent<TCow>.Implements<IMakeNoise>('Cow');
 
-  ServiceLocator.RegisterComponent<TPetNoiseProvider>.Implements<IPetNoiseMaker>;
+  GlobalContainer.RegisterComponent<TPetNoiseProvider>.Implements<IPetNoiseMaker>;
 
 end.

File SpringDemos/Demo.DependencyInjection/uStringListService.pas

 
 uses
          Classes
-       , Spring.DI
-       , uServiceLocator
        , SysUtils
        ;
 
 
   end;
 
-procedure RegisterStringListService(aContainer: TContainer; aName: string);
+procedure RegisterStringListService(aName: string);
 
 implementation
 
+uses
+        Spring.Container
+      ;
+
 type
   TStringListImpl = class(TInterfacedObject, IStringListService)
   strict private
   Result := FStringList.ToStringArray;
 end;
 
-procedure RegisterStringListService(aContainer: TContainer; aName: string);
+procedure RegisterStringListService(aName: string);
 begin
-  aContainer.RegisterComponent<TStringListImpl>.Implements<IStringListService>(aName);
-  aContainer.Build;
+  GlobalContainer.RegisterComponent<TStringListImpl>.Implements<IStringListService>(aName);
+  GlobalContainer.Build;
 end;
 
 initialization
-  RegisterStringListService(ServiceLocator, 'DSL');
+  RegisterStringListService('DSL');
 
 end.

File SpringDemos/Demo.DependencyInjection/uWackyMathService.pas

 
 uses
          uMathInterfaces
-       , uServiceLocator
+       , Spring.Container
        , uServiceNames;
 
 type
 
 procedure RegisterwWackyMathService;
 begin
-  ServiceLocator.RegisterComponent<TWackyAdditionServiceImplementation>.Implements<IMathService>(WackyAdditionServiceName);
+  GlobalContainer.RegisterComponent<TWackyAdditionServiceImplementation>.Implements<IMathService>(WackyAdditionServiceName);
 end;
 
 initialization

File SpringDemos/Demo.General/Demo.Spring.ObjectContainer.dpr

 
 uses
   System.SysUtils,
-  uYeller in 'uYeller.pas',
-  uServiceLocator in '..\Demo.DependencyInjection\uServiceLocator.pas';
+  Spring.Services,
+  uYeller in 'uYeller.pas';
 
 var
   Yeller: TYeller;
 begin
   try
-    Yeller := ServiceLocator.Resolve<TYeller>;
+    Yeller := ServiceLocator.GetService<TYeller>;
     Yeller.Yell;
   except
     on E: Exception do

File SpringDemos/Demo.General/Demo.Spring.ObjectContainer.dproj

 				<MainSource>MainSource</MainSource>
 			</DelphiCompile>
 			<DCCReference Include="uYeller.pas"/>
-			<DCCReference Include="..\Demo.DependencyInjection\uServiceLocator.pas"/>
 			<BuildConfiguration Include="Release">
 				<Key>Cfg_2</Key>
 				<CfgParent>Base</CfgParent>

File SpringDemos/Demo.General/uEnumDemo.pas

 implementation
 
 uses
-      Spring
+      Spring.Utils
     , System.Types
     ;
 

File SpringDemos/Demo.General/uYeller.pas

 implementation
 
 uses
-       uServiceLocator
-     ;
+      Spring.Container
+    ;
 
 procedure TYeller.Yell;
 begin
-  Writeln('HEY HEY HEY!!');
+  Writeln('See, you can put a plain old object in the Spring Container, and it works.');
 end;
 
 initialization
-  ServiceLocator.RegisterComponent<TYeller>;
+  GlobalContainer.RegisterComponent<TYeller>;
 
 
 end.