dependency-injection

Inject spring dependency in abstract super class

跟風遠走 提交于 2019-12-17 15:54:20
问题 I have requirement to inject dependency in abstract superclass using spring framework. class A extends AbstractClassB{ private Xdao daox ; ... public setXdao() { ... } } class AbstractClassB{ .. private yDao daoy; public seyYdao() { ... } } I need to pass superclass dependency everytime i instantiate Abstract class B (which can be subclassed in 100's of ways in my project) entry in application.xml (spring context file) <bean id="aClass" class="com.mypro.A" <property name="daox" ref=

Inject spring dependency in abstract super class

有些话、适合烂在心里 提交于 2019-12-17 15:53:56
问题 I have requirement to inject dependency in abstract superclass using spring framework. class A extends AbstractClassB{ private Xdao daox ; ... public setXdao() { ... } } class AbstractClassB{ .. private yDao daoy; public seyYdao() { ... } } I need to pass superclass dependency everytime i instantiate Abstract class B (which can be subclassed in 100's of ways in my project) entry in application.xml (spring context file) <bean id="aClass" class="com.mypro.A" <property name="daox" ref=

spring: set property of one bean by reading the property of another bean?

孤者浪人 提交于 2019-12-17 15:53:45
问题 Is it possible to set the property of one bean by reading the property of another bean? For instance, suppose I had: class A { void setList(List list); } class B { List getList(); } I would like Spring to instantiate both classes, and call A's setList method, passing in the result of calling B's getList method. The Spring configuration might look something like: <bean id="b" class="B"/> <bean id"a" class="A"> <property name="list" ref="b" ref-property="list"/> </bean> Alas, this made-up XML

log4net with DI Simple Injector

戏子无情 提交于 2019-12-17 15:51:57
问题 I am trying to use Simple Injector ( + integration MVC) v 2.5.2. for an MVC 4 Application and I need to track/log performance (execution) as well(by log4net module). Current implementation (during runtime) creates log4net file in specified path but did not write any line of text into it (when I debug it everything went with no error to the end of _logger.Info("message") ). Does anyone try to use Simple Injector DI for log4net? The way how I've registered log4net module is: public static class

Why use constructor over setter injection in CDI?

筅森魡賤 提交于 2019-12-17 15:44:33
问题 I couldn't find any reasonable answer here on SO so I hope it's not a duplicate. So why should I prefer setter or constructor injection over simple @Inject MyBean bean; I get the usage of the constructor injection if you need to do something with injected bean during your class initialization like public void MyBean(@Inject OtherBean bean) { doSomeInit(bean); //I don't need to use @PostConstruct now } but still, it's almost the same like @PostConstruct method and I don't get setter injection

Spring injects dependencies in constructor without @Autowired annotation

女生的网名这么多〃 提交于 2019-12-17 15:39:18
问题 I'm experimenting with examples from this official Spring tutorials and there is a dependency on this code: https://github.com/spring-guides/gs-async-method/tree/master/complete If you look at the code on AppRunner.java class, I have 2 questions: When server is starting, if I put a breakpoint in this class's constructor, seems like in the constructor, the GitHubLookupService is provided by spring, using the @Service bean that was configured. BUT, there was no @Autowired annotation on the

Strategy Pattern and Dependency Injection using Unity

对着背影说爱祢 提交于 2019-12-17 15:36:25
问题 I am finally getting my feet wet with Dependency Injection (long overdue); I got started playing with Unity and run into an issue with the strategy pattern. I can use the container to return to me specific implementations of a strategy based on a name, but what I don't see is how I am supposed to get the right strategy in the context. Let's illustrate on a simple example: the context is a car, which has an IEngine (the strategy), with 2 implementations, FastEngine and SlowEngine. The code

What is the intention of Ninject modules?

不羁的心 提交于 2019-12-17 15:35:29
问题 I'm a complete newbie to ninject I've been pulling apart someone else's code and found several instances of nInject modules - classes that derive from Ninject.Modules.Module, and have a load method that contains most of their code. These classes are called by invoking the LoadModule method of an instance of StandardKernel and passing it an instance of the module class. Maybe I'm missing something obvious here, but what is the benefit of this over just creating a plain old class and calling

Configuring dependency injection with ASP.NET Web API 2.1

懵懂的女人 提交于 2019-12-17 15:25:21
问题 I'm creating an ASP.NET Web API 2.1 site and as I want to inject dependencies directly into the controllers, I've created my own implementation of IDependencyResolver so that StructureMap will handle that for me. public class StructureMapDependencyResolver : IDependencyResolver { public IDependencyScope BeginScope() { return this; } public object GetService(Type serviceType) { return ObjectFactory.GetInstance(serviceType); } public IEnumerable<object> GetServices(Type serviceType) { return

How to extend a component with dependency injection?

一个人想着一个人 提交于 2019-12-17 15:23:57
问题 I have the following class ModuleWithHttp : @Injectable() export default class { constructor(private fetchApi: FetchApi) {} } and I want to use it as follows: @Component({ selector: 'main', providers: [FetchApi] }) export default class extends ModuleWithHttp { onInit() { this.fetchApi.call(); } } So by extending a super class that already injects a dependency I want to have an access to it in its children. I tried many different ways, even having super-class as a component: @Component({