dependency-injection

JUnit @BeforeClass non-static work around for Spring Boot application

落花浮王杯 提交于 2020-01-01 04:01:22
问题 JUnit's @BeforeClass annotation must be declared static if you want it to run once before all the @Test methods. However, this cannot be used with dependency injection. I want to clean up a database that I @Autowire with Spring Boot, once before I run my JUnit tests. I cannot @Autowire static fields so I need to think of a work around. Any ideas? 回答1: Just use @Before (instead of @BeforeClass ) (or BeforeTransaction (depending on how you initialize the database)). This annotation must been

JUnit @BeforeClass non-static work around for Spring Boot application

一曲冷凌霜 提交于 2020-01-01 04:01:11
问题 JUnit's @BeforeClass annotation must be declared static if you want it to run once before all the @Test methods. However, this cannot be used with dependency injection. I want to clean up a database that I @Autowire with Spring Boot, once before I run my JUnit tests. I cannot @Autowire static fields so I need to think of a work around. Any ideas? 回答1: Just use @Before (instead of @BeforeClass ) (or BeforeTransaction (depending on how you initialize the database)). This annotation must been

Injecting the Service Manager to Build a Doctrine Repository in ZF2

∥☆過路亽.° 提交于 2020-01-01 03:49:10
问题 How do I inject the service manager into a Doctrine repository to allow me to retrieve the Doctrine Entity Manager? I using the ZF2-Commons DoctrineORMModule and are trying to implement the repository example listed in the Doctrine Tutorial (bottom of tutorial in link below): http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/tutorials/getting-started.html However, I keep getting a message " Fatal error: Call to a member function get() on a non-object in C:\zendProject\zf2 ... "

How to use the Symfony 2 Container in a legacy app

落爺英雄遲暮 提交于 2020-01-01 02:54:48
问题 Would like to integrate a legacy application with a Symfony 2 application - replacing more and more parts of the old application with Symfony components. The approach I would take is using the Symfony 2 container in the legacy application getting the services that are already configured for the Symfony 2 application. The first services I would like to use are the session and the security context. Questions: Is this feasible? How do I get the configured service container? More info in the

What is “automatic injection of location and resources properties into the controller” in JavaFX?

和自甴很熟 提交于 2020-01-01 02:54:47
问题 In the description of Initializable interface it is said: NOTE This interface has been superseded by automatic injection of location and resources properties into the controller. FXMLLoader will now automatically call any suitably annotated no-arg initialize() method defined by the controller. It is recommended that the injection approach be used whenever possible. The question is: how to "suitable annotate" methods? I find only one annotation -- @FXML . Are there any others? 回答1: The answer

Dependency Injection and development productivity

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-01 02:29:18
问题 Abstract For the past few months I have been programming a light weight, C# based game engine with API abstraction and entity/component/scripting system. The whole idea of it is to ease the game development process in XNA, SlimDX and such, by providing architecture similar to that of the Unity engine. Design challenges As most game developers know, there are a lot of different services you need to access throughout your code. Many developers resort to using global static instances of e.g. a

How to configure simple injector container and lifestylse in a MVC web app with WebAPI, WCF, SignalR and Background Task

心不动则不痛 提交于 2020-01-01 02:25:11
问题 The simple injector documentation provides great examples on how to setup the container for WebRequest, Web API, WCF, ... but the examples are specific to one technology/lifestyle at a time. Our web application uses most of them together! It is not clear to me how to configure the container to work with several lifestyles. Let's say I have a MVC project with Web API. I have the following objects: MyDbContext : My entity code first db context IMyDataProvider implemented by MyDataProvider :

How to configure unity container to provide string constructor value?

眉间皱痕 提交于 2020-01-01 01:31:06
问题 This is my dad class public class Dad { public string Name { get;set; } public Dad(string name) { Name = name; } } This is my test method public void TestDad() { UnityContainer DadContainer= new UnityContainer(); Dad newdad = DadContainer.Resolve<Dad>(); newdad.Name = "chris"; Assert.AreEqual(newdad.Name,"chris"); } This is the error I am getting "InvalidOperationException - the type String cannot be constructed. You must configure the container to supply this value" How do I configure my

Grails: Dynamically inject service in domain class

China☆狼群 提交于 2019-12-31 23:11:16
问题 I need to inject a service based on domain property, so far I came up with the following: ApplicationHolder.application.getServiceClass("package.${property}Service").clazz but loading it this way doesn't inject it's dependent services. Am I doing it wrong? 回答1: New instances will bypass Spring's dependency management; you need to get the configured singleton bean from the application context. Use this instead: def service = ApplicationHolder.application.getMainContext().getBean("${property

How to inject dependencies into any kind of object with Dagger2?

孤者浪人 提交于 2019-12-31 21:33:51
问题 According to http://konmik.github.io/snorkeling-with-dagger-2.html i could just add inject(Anything anything) into AppComponent.java, but this doesn't work for me, in the articles example: @Singleton @Component(modules = AppModule.class) public interface AppComponent { void inject(MainActivity activity); void inject(MainFragment fragment); void inject(MainToolbarView view); } If I try to inject dependencies into my fragment the injected members remain null. What obvious error am I missing