Get started

222 views
Skip to first unread message

Roland Bengtsson

unread,
May 29, 2017, 4:07:38 PM5/29/17
to Spring4D
Hi

I just started read Dependency Injection and try to start using Spring4D with Delphi Berlin.
I normally use Delphi 2007 so Spring4D is new for me.

I try to compile and run NickDemocode\EKON17\DependencyInjection\Code downloaded from https://bitbucket.org/NickHodges/nickdemocode/overview

I just wonder how it is supposed to setup.
First I try to add the Spring4D folders in the projects search path.

The path end up like this

C:\Spring4D\Source\Core\Container;C:\Spring4D\Source\Core\Logging;C:\Spring4D\Source\Base\Logging;C:\Spring4D\Source\Core\Services;C:\Spring4D\Source\Core\Interception

I got the error 
[dcc32 Error] ContainerDemo.dpr(22): E2003 Undeclared identifier: 'GlobalContainer'

Then I added following lines to dpr-file

  Spring.Container in 'C:\Spring4D\Source\Core\Container\Spring.Container.pas',
  Spring.Services in 'C:\Spring4D\Source\Core\Services\Spring.Services.pas';

and it compile at least but with 3 hints and 2 warnings.

[dcc32 Warning] uNoServiceLocatorDemo.pas(23): W1000 Symbol 'InjectAttribute' is deprecated: 'Use Spring.Container.Common.InjectAttribute'
[dcc32 Warning] uContainerStuff.pas(46): W1000 Symbol 'InjectAttribute' is deprecated: 'Use Spring.Container.Common.InjectAttribute'
[dcc32 Hint] uContainerStuff.pas(40): H2219 Private symbol 'FHasScope' declared but never used
[dcc32 Hint] ContainerDemo.dpr(16): H2164 Variable 'TempBattlefield' is declared but never used in 'ContainerDemo'
[dcc32 Hint] ContainerDemo.dpr(17): H2164 Variable 'RifleIntf' is declared but never used in 'ContainerDemo'

When try the demo I got this

Project ContainerDemo.exe raised exception class EResolveException with message 'Cannot resolve type: TRifle'.

Obviously I doing something wrong. Can someone give me a hint ?

Regards
Roland Bengtsson

Stefan Glienke

unread,
May 30, 2017, 4:44:00 AM5/30/17
to Spring4D
First I suggest you compile the spring4d package group for your Delphi version and then add the directory it outputs the dcus into to your library path. That way you don't have to manually add half a dozen spring4d source directories to every project you want to use it in and you dont have to compile it every time (best practice for every 3rd party code imo btw) - or you simply use the Build.exe that does that for you: select the Delphi version and the platform you want, check the "modify registry" (that is adding the dcu directory to your library path) and you are set.

As for the Demo itself - it is probably really outdated EKON 17 was in 2013 - so he most likely was using version 1.0 or 1.1 back then.
Also FWIW its rather terrible given that it looks like some project that he modified during the session to show different things.
In its current form as committed on bitbucket it is not very helpful.

I think there are more recent examples - either in his book or in the Samples/IntroToDependencyInjection directory in Spring4D.
It shows step by step how to go from non DI to using DI (also written by Nick but compatible with the current 1.2 version)

Roland Bengtsson

unread,
May 30, 2017, 3:51:40 PM5/30/17
to Spring4D
Ok thanks for the advices.

Regards
Roland

Reply all
Reply to author
Forward
0 new messages