FAQ Database Discussion Community


Get class type during dependency resoluton

c#,dependency-injection,unity,constructor-injection
When registering a type for my unity container, I need to pass in the calling class's type into the constructor of the resolved object. This is the class where I am injecting some interfaces into the constructor. namespace MyNamespace { internal class ProcessingService: IProcessingService { private readonly ISomeClass1 someClass1; private...

Java Constructor Injection

java,constructor,dependency-injection,instantiation,constructor-injection
Let's say I have a class resources which instantiates all of my OpenGL / Java game objects and I then pass these via constructor to my Scene class (which requires them), like so (simplified example)..... public class Resources { Hero hero; Enemy enemy; MenuButtons mainMenuButtons; Background background; Scene mainMenu; public...

Injecting an instance using Unity whose constructor parameter is not known

design-patterns,dependency-injection,unity,constructor-injection
I have an interface as follows public interface IDataProvider { List<string> GetData(); } Implementation of it public class TextDataProvider: IDataProvider { public TexDataProvider(string source){...} public List<string> GetData() {...} } One of my services uses IDataProvider to get data. Different implementations could be injected by changing the Unity Register method with...

How does constructor-based dependency injection affects immutability?

java,spring,dependency-injection,immutability,constructor-injection
I am reading Spring documentation and I am wondering what they meant by writing: The Spring team generally advocates constructor injection as it enables one to implement application components as immutable objects and to ensure that required dependencies are not null. I don't see in what way does it enable...

symfony container: injected class's constructor not called

php,symfony2,dependency-injection,constructor-injection
When I inject a service into another via constructor injection, the constructor of the injected class is not being called. Has anyone an explanation for this. What am I overlooking? I created this little sample for demonstration purposes: services.yml services: foo.A: class: Acme\FooBundle\A foo.B: class: Acme\FooBundle\B arguments: a: "@foo.A" Class...