constructor-injection Questions

8

Solved

I am using Microsoft's Unity for dependency injection and I want to do something like this: IDataContext context = _unityContainer.Resolve<IDataContext>(); var repositoryA = _unityContainer...

2

I have a Windows Form. It contains many controllers: Grids, buttons, and even a TreeView. Events are defined on most of them. For example, there are multiple independent events that query or comman...

2

Inversion of control is a value-proof technique which is used to modularize a system and decouple the components from each other. Low coupling is always an advantage: it simplifies automatic testi...

4

Solved

I'm using .NET Core constructor injection. In a code review from a colleague, he raised the question if I should check for null values on injected dependencies in controllers. Since the framework ...

2

I'm developing a Java Spring application. I have some fields in my application which are configured using a .yml config file. I would like to import those values using an @Value annotation on the f...
Uhl asked 13/9, 2018 at 21:23

2

I have a class with lombok @RequiredArgsConstructor: @RequiredArgsConstructor @Service public class Test{ private final String str; private String str5; // more code } In non-spring boot we pro...
Ish asked 12/8, 2020 at 16:5

3

I have read about dependency injection. Then there comes Constructor Injection, Getter Injection Setter Injection Interface Injection How do they differ from Dependency Injection or all of the...
Chloric asked 16/2, 2018 at 16:40

2

Solved

I am convinced to convert my Spring Java field injection [@Autowired] to constructor injection (among other reasons, to facilitate mock unit testing)... Is there a utility I can use to automatical...

4

I have a looked at similar questions on this board, but none of them answer my question. This sound strange, but is it possible to mock out a constructor call on the object you're mocking. Example...
Durance asked 4/10, 2011 at 19:50

2

Solved

I'm trying to figure out how to use Simple Injector, I've used it around the project with no problems registering simple services and their components. However, I wanted to use dependency injector...

8

Solved

I'm trying to use Spring to inject a SLF4J logger into a class like so: @Component public class Example { private final Logger logger; @Autowired public Example(final Logger logger) { this.l...
Shaving asked 14/6, 2010 at 14:46

2

If I have a Spring configuration class (i.e. a class annotated with @Configuration) can I use constructor injection ? As it stands if I add one I get a no default constructor message, and if I add...
Forman asked 7/3, 2016 at 13:31

3

Solved

I have a base Class Base having dependecy Dep and default and Injection Constructor- Class Base : IBase { public IDep Dep { get; set; } public Base() { Console.WriteLine("Default Constructo...

3

Solved

According to this article, a Controller should have a constructor that gets the interface to be implemented passed in, a la: public class DuckbillsController : ApiController { IDuckbillRepository...

1

I have a component that dynamically loads another component using DynamicComponentLoader. However, the dynamic component needs to have a service injected. However, I'm unsure how to go about this. ...
Alumina asked 8/4, 2016 at 2:29

2

Solved

I'm new to spring beans, so I don't get the use of ref in constructor-arg. Why not use value again like in this example here, Here is the content of TextEditor.java file: package com.tutorialspo...
Azotobacter asked 26/11, 2015 at 11:37

3

I have the following class, which uses constructor injection: public class Service : IService { public Service(IRepository repository, IProvider provider) { ... } } For most methods in this cla...
Calley asked 18/4, 2014 at 14:47

3

Solved

I'm trying to figure out MEF's Constructor Injection attribute. I have no idea how I tell it to load the constructor's parameters. This is the property I'm trying to load [ImportMany(typeof(BUser...
Opportune asked 5/1, 2010 at 18:19

1

Solved

When to use constructor injection in Spring? I heard that constructor injection is particularly useful when you absolutely must have an instance of the dependency class before your component...
Sharlenesharline asked 25/11, 2014 at 16:52

1

When a view model is created you can populate the options (e.g. used in a dropdown list) into a setter property of the view model. The problem is that when that view model is later passed as a para...

2

Solved

Having trouble getting the value of a ConstructorArgument parameter passed to kernel.Get(). I want to use the parameter's value to determine which of two string values will be passed into the con...

3

Solved

I would like to be able to use ninject to inject all instances of a particular generic type into a class. For example I have a bunch of custom extractors of a format similar to: public interface ...
Asthenia asked 7/6, 2012 at 20:25

1

Problem I regularly find myself manually typing out code that looks like this: public class SomeClass { readonly ServiceA serviceA; readonly ServiceB serviceB; public SomeClass(ServiceA servi...

1

Solved

I'm having a problem with Spring and constructor injection. I want to create dynamically objects with a name (String) and special id (long). But when the spring.xml file is loaded an exception occu...
Benzoin asked 23/6, 2013 at 11:23

2

Solved

Suppose that my Foo class has the following: readonly IService service; public Foo(IService service) { if (service == null) throw new ArgumentNullException("service"); this.service = service...

© 2022 - 2024 — McMap. All rights reserved.