dependency-injection

How to @Inject a HttpSession object in a service layer (DAO) class in GWT using Guice?

烂漫一生 提交于 2020-01-23 03:50:46
问题 I have such a dirty code in my GWT app, some of the classes of my service layer depend on an HttpSession object. So for example, in one of my DAO (which was a GWT-RPC endpoint) I have something like this : public class MyExampleDAO extends RemoteServiceServlet { public findItems() { // here I need to get the object session to retrieve the currently logged in user in order to query for all its items... } } The problem is that, I am currently migrating the code to use RequestFactory. My DAO

Symfony 3.3 services autoconfiguration

限于喜欢 提交于 2020-01-22 20:08:02
问题 I'm trying migrate to symfony 3.3 and use new feature autowire / autoconfigure services: So in services.yml i have: services: _defaults: autowire: true autoconfigure: true public: false # makes classes in src/AppBundle available to be used as services AppBundle\: resource: '../../src/AppBundle/*' # you can exclude directories or files # but if a service is unused, it's removed anyway exclude: '../../src/AppBundle/{Entity,Controller,DQL,Form/DataTransformer,Repository}' i declare my twig

Dependency Injection Container - Factory Pattern

[亡魂溺海] 提交于 2020-01-22 19:48:11
问题 I have been trying to learn about dependency injection and have been reading about and trying to code a small dependency injection container similar to this: http://fabien.potencier.org/article/12/do-you-need-a-dependency-injection-container The one thing that is confusing me is this: Isnt a dependency injection container just a glorified implementation of the factory pattern? If so, why not just call it that, why the need for a fancy term only to confuse matters. If it isnt, can someone

Prevent Simple Injector to throw an exception when resolving an unregistered service

旧时模样 提交于 2020-01-22 15:43:05
问题 I was wondering if Simple Injector has an option to stop throwing exceptions whenever GetInstance(Of TService) returns Nothing ? It appears to be throwing them now because I have two requests to get an instance, it's not there, and it throws the exception. Is there a way to prevent the default behavior, a setting somewhere, or something else? 回答1: There absolutely is a simple way of doing this. The SimpleInjector.Container implements System.IServiceProvider, which defines an object GetService

Presenter injection with Dagger 2

杀马特。学长 韩版系。学妹 提交于 2020-01-22 12:13:07
问题 I just started using Dagger 2 and I found online thousands guides each one with a different implementation and I'm a bit confused now. So basically this is what I wrote at the moment: AppModule.java: @Module public class AppModule { Application mApplication; public AppModule(Application application) { mApplication = application; } @Provides @Singleton Application providesApplication() { return mApplication; } } DataModule.java: @Module public class DataModule { private static final String

Presenter injection with Dagger 2

那年仲夏 提交于 2020-01-22 12:12:18
问题 I just started using Dagger 2 and I found online thousands guides each one with a different implementation and I'm a bit confused now. So basically this is what I wrote at the moment: AppModule.java: @Module public class AppModule { Application mApplication; public AppModule(Application application) { mApplication = application; } @Provides @Singleton Application providesApplication() { return mApplication; } } DataModule.java: @Module public class DataModule { private static final String

Presenter injection with Dagger 2

扶醉桌前 提交于 2020-01-22 12:12:04
问题 I just started using Dagger 2 and I found online thousands guides each one with a different implementation and I'm a bit confused now. So basically this is what I wrote at the moment: AppModule.java: @Module public class AppModule { Application mApplication; public AppModule(Application application) { mApplication = application; } @Provides @Singleton Application providesApplication() { return mApplication; } } DataModule.java: @Module public class DataModule { private static final String

How to inject a controller into a directive when unit-testing

左心房为你撑大大i 提交于 2020-01-22 10:33:16
问题 I want to test an AngularJS directive declared like this app.directive('myCustomer', function() { return { template: 'cust.html' controller: 'customerController' }; }); In the test I would like to inject (or override) the controller, so that I can test just the other parts of the directive (e.g. the template). The customerController can of course be tested separately. This way I get a clean separation of tests. I have tried overriding the controller by setting the controller property in the

How to inject a controller into a directive when unit-testing

社会主义新天地 提交于 2020-01-22 10:33:08
问题 I want to test an AngularJS directive declared like this app.directive('myCustomer', function() { return { template: 'cust.html' controller: 'customerController' }; }); In the test I would like to inject (or override) the controller, so that I can test just the other parts of the directive (e.g. the template). The customerController can of course be tested separately. This way I get a clean separation of tests. I have tried overriding the controller by setting the controller property in the

ASP.Net Core Call a controller from another controller

▼魔方 西西 提交于 2020-01-22 10:30:57
问题 In my ASP.Net Core MVC 6 solution I have two sets of controllers. One set contains the webpages with their regular views. Another set contains the API controllers. To avoid duplicating db logic the web controllers are using the API controllers. Currently I am creating an instance of the required controller manually by handing it a DbContext as constructor argument. This is the DbContext given to web controller by dependency injection. But whenever I add another constructor parameter to the