inversion-of-control

how to implement IOC without a global static service (non-service locator solution)?

跟風遠走 提交于 2021-02-17 08:44:16
问题 we want to use Unity for IOC. All i've seen is the implementation that there is one global static service (let's call it the the IOCService) which holds a reference to the Unity container, which registers all interface/class combinations and every class asks that object: give me an implementation for Ithis or IThat. Frequently i see a response that this pattern is not good because it leads to a dependency from ALL classes to the IOCService (not to the Unity container because it is only known

Creating a Delphi IoC. How to disable Delphi's linker from removing unused classes

[亡魂溺海] 提交于 2021-02-16 16:23:06
问题 I've created a IoC in delphi with the ability to automatically register any classes that have a IocSingletonAttribute to it. The AutoRegister looks like the following. procedure TIocContainer.AutoRegister; var ctx: TRttiContext; rType: TRttiType; attr: TCustomAttribute; &Type: PTypeInfo; begin ctx := TRttiContext.Create; for rType in ctx.GetTypes do Begin for attr in rType.GetAttributes do Begin if TypeInfo(IocSingletonAttribute) = attr.ClassInfo then Begin &Type := IocSingletonAttribute(attr

How to share instance between decoratee and decorator in the context of ScopedLifestyle.Flowing

主宰稳场 提交于 2021-02-11 12:53:43
问题 I don't understand how to to share instance between decoratee and decorator by using a DI container. The following example illustrates my problem. The context instance is shared between the TransactionCommandDecorator and the Command service. var context = UowFactory.GetUnitOfWork(); var command = new TransactionCommandDecorator( context, new Command(context)); command.Execute(new CommandParams { }); context.dispose(); Basically I need to have a lot of commands that interact with the database

Registering an instance as 'singleton' bean at application startup

為{幸葍}努か 提交于 2021-02-07 17:15:48
问题 I am playing around with Spring Boot and I am trying to construct an instance of ServiceImpl to be resolved when a Service is required. Currently I am annotating the implementation as @Component but this does not give me the chance to construct the instance as I want. The ServiceImpl should be constructed with a String containing a path to a file on disk. I would like to do this in the main method of the @SpringBootApplication class of the application. Maybe it's just me coming from a long

Registering an instance as 'singleton' bean at application startup

落花浮王杯 提交于 2021-02-07 17:14:05
问题 I am playing around with Spring Boot and I am trying to construct an instance of ServiceImpl to be resolved when a Service is required. Currently I am annotating the implementation as @Component but this does not give me the chance to construct the instance as I want. The ServiceImpl should be constructed with a String containing a path to a file on disk. I would like to do this in the main method of the @SpringBootApplication class of the application. Maybe it's just me coming from a long

Registering an instance as 'singleton' bean at application startup

僤鯓⒐⒋嵵緔 提交于 2021-02-07 17:13:28
问题 I am playing around with Spring Boot and I am trying to construct an instance of ServiceImpl to be resolved when a Service is required. Currently I am annotating the implementation as @Component but this does not give me the chance to construct the instance as I want. The ServiceImpl should be constructed with a String containing a path to a file on disk. I would like to do this in the main method of the @SpringBootApplication class of the application. Maybe it's just me coming from a long

How do I inject dependencies into an iOS view controller?

守給你的承諾、 提交于 2021-02-06 19:18:35
问题 My view controllers need to send messages to a couple of model objects. How do I obtain references to these model objects inside the view controller? These model objects are "singletons" (in that there should only be one copy of them in the system at once) and they are used by multiple view controllers. So I can't instantiate them in the init method of each view controller. I can't use constructor injection as the runtime chooses the init method that gets used to create the view controller. I

How do I inject dependencies into an iOS view controller?

孤人 提交于 2021-02-06 19:18:26
问题 My view controllers need to send messages to a couple of model objects. How do I obtain references to these model objects inside the view controller? These model objects are "singletons" (in that there should only be one copy of them in the system at once) and they are used by multiple view controllers. So I can't instantiate them in the init method of each view controller. I can't use constructor injection as the runtime chooses the init method that gets used to create the view controller. I

How do I inject dependencies into an iOS view controller?

﹥>﹥吖頭↗ 提交于 2021-02-06 19:16:38
问题 My view controllers need to send messages to a couple of model objects. How do I obtain references to these model objects inside the view controller? These model objects are "singletons" (in that there should only be one copy of them in the system at once) and they are used by multiple view controllers. So I can't instantiate them in the init method of each view controller. I can't use constructor injection as the runtime chooses the init method that gets used to create the view controller. I

How do I inject dependencies into an iOS view controller?

纵饮孤独 提交于 2021-02-06 19:15:13
问题 My view controllers need to send messages to a couple of model objects. How do I obtain references to these model objects inside the view controller? These model objects are "singletons" (in that there should only be one copy of them in the system at once) and they are used by multiple view controllers. So I can't instantiate them in the init method of each view controller. I can't use constructor injection as the runtime chooses the init method that gets used to create the view controller. I