inversion-of-control

How do I inject dependencies into an iOS view controller?

Deadly 提交于 2021-02-06 19:14:58
问题 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:13:20
问题 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:13:08
问题 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

IoC Container. Inject container

旧街凉风 提交于 2021-02-04 19:56:57
问题 What I want: Resolve object A, and inside object A, I want use same container to resolve object C: public static void Work() { IUnityContainer con = new UnityContainer(); con.RegisterType<IA, A>(); con.RegisterType<IB, B>(); con.RegisterType<IC, C>(); var a = con.Resolve<IA>(); } interface IA { } interface IB { } interface IC { } class A : IA { public A(IB b, IUnityContainer con) { for (int i = 0; i < 10; i++) { var c = con.Resolve<IC>(); } } } class B : IB { }; class C : IC { }; Problem: On

Decorator for creating Scope with ScopedLifestyle.Flowing in Simple Injector

可紊 提交于 2021-01-29 22:27:11
问题 I need some help to understand what it's wrong in my configuration of the container. I based this implementation by using this example. Basically i need to implement some use case as database command based on that interface public interface IDatabaseCommand<TResult, TParam> { TResult Execute(TParam commandParam); } and i want to use a decorator that add the transaction safe functionality. Every command need to use a dedicated DbContext and the transaction has to be executed on that context To

Spring Dependency Injection - Private fields - Anti Pattern? Why does it even work?

允我心安 提交于 2021-01-29 21:33:07
问题 I am generally a c# developer but working on Java now and then I see a lot of dependency injection using Spring on private properties, with no public way of setting the value. I was surprised this actually works, but I guess it’s possible via reflection? Surely this is terrible practice?! I can't see how anyone unit testing or inspecting the class would possibly know that a private member needs to be set from some external framework. How would you even set the property when you are unit

Many dependencies in service

不打扰是莪最后的温柔 提交于 2021-01-27 15:19:46
问题 I have trouble with dependencies in my application in service layer. I have following class: <?php class UserService{ private $userRepository; private $vocationService; private $roleService; public function __construct(UserRepository $userRepository, VocationService $vocationService, RoleService $roleService) { $this->userRepository = $userRepository; $this->vocationService = $vocationService; $this->roleService = $roleService; } } There are only three dependencies which I'm injecting. Assume

SignalR Hubs Clients are null when firing event

孤者浪人 提交于 2021-01-21 12:30:35
问题 I've written a generic hubs which I'm having some issues with so to debug it I've decided to make a simple connection count like so: public class CRUDServiceHubBase<TDTO> : Hub, ICRUDServiceHubBase<TDTO> { public const string CreateEventName = "EntityCreated"; public const string UpdateEventName = "EntityUpdated"; public const string DeleteEventName = "EntityDeleted"; protected int _connectionCount = 0; public Task Create(TDTO entityDTO) { return Clients.All.InvokeAsync(CreateEventName,

What is a DI Container?

妖精的绣舞 提交于 2021-01-20 15:51:30
问题 I am watching this course video about dependency injection and the instructor talked about di-container but did not explain in detail, now I read some articles and I want to confirm that now I am getting this right. Below is simple program and my question is, Is Program class below is kind of simplest di-container? if not how would simple di-container would be like interface Implementable { void doSmth(); } class A implements Implementable { @Override public void doSmth() { } } class B {

Registering a generic abstract class in Castle Windsor

十年热恋 提交于 2020-12-04 08:14:22
问题 I am trying to register a type by convention, I've simplified my case in this example: public abstract class BaseEntity{} public class EntityA : BaseEntity{} public class EntityB : BaseEntity{} public abstract class BaseClass { //... } public abstract class GenericBaseClass<T> : BaseClass where T : BaseEntity { //.. } public class ConcreteA : GenericBaseClass<EntityA> { //... } public class ConcreteB : GenericBaseClass<EntityB> { //... } I'm trying to find the way to register GenericBaseClass