spring4d

delphi - how to pass a parameter from the instantiator to a constructor in the spring4d dependency injection framework?

和自甴很熟 提交于 2020-01-10 14:19:06
问题 It's possible to register a class with a parameter expected to be passed from the point of creation? I know it can be done something like this: GlobalContainer.RegisterType<TUserProcessor>.Implements<IUserUpgrader>. AsTransient.DelegateTo( function: TUserProcessor begin Result := TUserProcessor.Create(GetCurrentUser); end ); But there the parameters are binded to the execution context where the container gets registered and not where the object get's intantiated. Something like this it's

Mocking interfaces in DUnit with Delphi-Mocks and Spring4D

自古美人都是妖i 提交于 2020-01-05 07:42:12
问题 So, I am getting Access Violation error when try to Mock 2-nd composite interface, below examples of code with using Delphi-Mocks and Spring4D frameworks unit u_DB; type TDBObject = class public property ID: TGUID; end; TDBCRM = class(TDBObject) public property SOME_FIELD: TSomeType; end; unit i_dmServer; type {$M+} IdmServer = interface ['{A4475441-9651-4956-8310-16FB710EAE5E}'] function GetServiceConnection: TServiceConnection; function GetCurrentUser(): TUser; end; unit d_ServerWrapper;

Why is Spring4D's IList<T> OnChanged event not fired when the object changes (while Add and Remove fire the event)?

蓝咒 提交于 2019-12-11 16:47:17
问题 I modified @Stefan Glienkes example from Notify the TObjectList when Object changed to use IList, since I am using interfaced objects in my list. In the event handler, I can handle caAdded and caRemoved events, but caChanged is not signaled. Is this by design or am I making a mistake somewhere? This example shows the behavior: program Project61; {$APPTYPE CONSOLE} uses Spring, Spring.Collections, SysUtils; type TNotifyPropertyChangedBase = class(TInterfaceBase, INotifyPropertyChanged) private

Process to convert TObjectlist to TObjectList<T> to use in TObjectDataset

我的未来我决定 提交于 2019-12-11 06:08:42
问题 I would like to use TObjectDataset which relies on TObjectList<> (System.Generics.Collections / Spring.Collections) but only have a TObjectList (System.Contnrs). Is there any way besides for iterating through objects and building a new TObjectList<> to get this working? Ultimately I would like to couple the TObjectList to an Objectdataset in order to bind to an UI. 回答1: Your question is slightly wrong. The Spring4d TObjectDataSet takes an IObjectList interface which is a specialization of

Can't use default parametr values with comparer in Spring4D

一曲冷凌霜 提交于 2019-12-11 04:06:29
问题 I'm not sure if this is some generic problem or it's because of Spring4D implementation, but I can't use default parameter values for creating comparer. type TMyClass = class class function MyComparer(AParam: Boolean = False): IComparer<TMyClass>; end; implementation class function TMyClass.MyComparer(AParam: Boolean): IComparer<TMyClass>; begin Result := TComparer<TMyClass>.Construct( function (const L, R: TMyClass): Integer begin Result := 0; end); end; When I create a list without the

Delphi Spring DI: Is it possible to delegate interface instantiation without an implementing type?

岁酱吖の 提交于 2019-12-04 11:27:03
问题 I'm just getting started with the Delphi Spring Framework and was wondering whether the current version of the DI container somehow allows delegating the construction to a factory method without specifying an implementing type? E.g. something similar to this: GlobalContainer .RegisterFactory<ISomeObject>( function: ISomeObject begin Result := CreateComObject(CLASS_SomeObject) as ISomeObject; end) .Implements<ISomeObject> // could probably be implied from the above .AsSingletonPerThread; As

Delphi Spring DI: Is it possible to delegate interface instantiation without an implementing type?

隐身守侯 提交于 2019-12-03 07:12:56
I'm just getting started with the Delphi Spring Framework and was wondering whether the current version of the DI container somehow allows delegating the construction to a factory method without specifying an implementing type? E.g. something similar to this: GlobalContainer .RegisterFactory<ISomeObject>( function: ISomeObject begin Result := CreateComObject(CLASS_SomeObject) as ISomeObject; end) .Implements<ISomeObject> // could probably be implied from the above .AsSingletonPerThread; As you can see, my specific use case is the instantiation of COM objects. In that case the class

How to initialize main application form in Spring4D GlobalContainer?

為{幸葍}努か 提交于 2019-11-30 10:35:41
so for instance I have a main form and want to inject a logger instance as private field. I register the logger GlobalContainer.RegisterType<TCNHInMemoryLogger>.Implements<ILogger>; I have a private field in my main form private FLogger: ILogger; All what I want is to make so: private [Inject] FLogger: ILogger; In my DPR file I have typical delphi way to create main form: begin Application.Initialize; Application.MainFormOnTaskbar := True; Application.CreateForm(Tfrm_CNH, frm_CNH); Application.Run; end. What should I change in a way of the form creation to have private fields injected properly

delphi - how to pass a parameter from the instantiator to a constructor in the spring4d dependency injection framework?

廉价感情. 提交于 2019-11-30 09:24:23
It's possible to register a class with a parameter expected to be passed from the point of creation? I know it can be done something like this: GlobalContainer.RegisterType<TUserProcessor>.Implements<IUserUpgrader>. AsTransient.DelegateTo( function: TUserProcessor begin Result := TUserProcessor.Create(GetCurrentUser); end ); But there the parameters are binded to the execution context where the container gets registered and not where the object get's intantiated. Something like this it's possible for example? GlobalContainer.Resolve<IMathService>([FCurrentUser]); I know some peoble advocate to

How to initialize main application form in Spring4D GlobalContainer?

こ雲淡風輕ζ 提交于 2019-11-29 15:25:31
问题 so for instance I have a main form and want to inject a logger instance as private field. I register the logger GlobalContainer.RegisterType<TCNHInMemoryLogger>.Implements<ILogger>; I have a private field in my main form private FLogger: ILogger; All what I want is to make so: private [Inject] FLogger: ILogger; In my DPR file I have typical delphi way to create main form: begin Application.Initialize; Application.MainFormOnTaskbar := True; Application.CreateForm(Tfrm_CNH, frm_CNH);