dependency-injection

Why Dagger inject is not working but component.getObject yes

泪湿孤枕 提交于 2020-02-08 02:32:51
问题 I am trying to use Dagger 2 for instantiating a Retrofit interface. The CloudContactDataStore class injects the RestClient and calls its methods. When I instantiate a CloudContactDataStore object, its RestClient attribute has null value. public class CloudContactDataStore implements ContactDataStore { @Inject RestClient restClient; public CloudContactDataStore() { this.initializeInjector(); } private void initializeInjector() { ApiComponent component = DaggerApiComponent.builder() .apiModule

DependencyResolver: Pass parameters

允我心安 提交于 2020-02-07 07:50:11
问题 I use autofac and can pass parameters to my resolve method. How can I do this using microsofts DependencyResolver interface? 回答1: The IDependencyResolver does not support passing parameters directly, as I'm sure you have noticed. However, since you have Autofac under the hood, you're able to resolve a factory delegate that enables you to pass on parameters to the underlying service: var factory = dependencyResolver.GetService<Func<int, string, IService>>(); var service = factory(5, "42");

DependencyResolver: Pass parameters

允我心安 提交于 2020-02-07 07:50:03
问题 I use autofac and can pass parameters to my resolve method. How can I do this using microsofts DependencyResolver interface? 回答1: The IDependencyResolver does not support passing parameters directly, as I'm sure you have noticed. However, since you have Autofac under the hood, you're able to resolve a factory delegate that enables you to pass on parameters to the underlying service: var factory = dependencyResolver.GetService<Func<int, string, IService>>(); var service = factory(5, "42");

Several instances of a common @Configuration with different @PropertySource in Spring

雨燕双飞 提交于 2020-02-06 08:47:46
问题 Hi I have the following configuration file : @Configuration @PropertySources({ @PropertySource("classpath:english.properties"), @PropertySource("classpath:spanish.properties") }) public class LanguageConfig { @Value(${hello}) private String hello; // getter setter } I want to know if there is a way to Autowire two instances of LanguageConfig , one for each language. Something like : public Myservice() { @Autowire @Qualifier("englishLanguage") private LanguageConfig englishConfig; @Autowire

@subcomponent.factory method is missing parameters for required modules or subcomponents

百般思念 提交于 2020-02-06 07:23:20
问题 I am injecting Presenter to BookDashboard (Activity) and BookDashboardPresenter class require an MvpView interface in it's constructor . When i run AppComponent @Component( modules = [ AndroidInjectionModule::class, ActivityBuilder::class ] ) @Singleton interface AppComponent : AndroidInjector<App> { @Component.Builder interface Builder { fun addContext(@BindsInstance context: Context): Builder fun addBookEngine(@BindsInstance bookEngineModule: BookEngineModule) :Builder fun build():

How to inject null for unregistered services

泪湿孤枕 提交于 2020-02-06 06:06:12
问题 I have a decorator and an associated service that looks like this: public interface IAdditionalDataService<TResult, TModel> { TResult PopulateAdditionalData(TResult model, params Expression<Func<TModel, object>>[] properties); } public class AdditionalDataDecorator<TQuery, TResult, TModel> : IQueryHandler<TQuery, TResult> where TQuery : QueryBase<TResult, TModel>, IQuery<TResult> where TModel : ModelBase { private readonly IQueryHandler<TQuery, TResult> _decorated; private readonly

How to inject null for unregistered services

家住魔仙堡 提交于 2020-02-06 06:06:05
问题 I have a decorator and an associated service that looks like this: public interface IAdditionalDataService<TResult, TModel> { TResult PopulateAdditionalData(TResult model, params Expression<Func<TModel, object>>[] properties); } public class AdditionalDataDecorator<TQuery, TResult, TModel> : IQueryHandler<TQuery, TResult> where TQuery : QueryBase<TResult, TModel>, IQuery<TResult> where TModel : ModelBase { private readonly IQueryHandler<TQuery, TResult> _decorated; private readonly

How to ConfigureServices in Asp.Net core WebAPI from another assembly

浪子不回头ぞ 提交于 2020-02-05 09:53:29
问题 In a microservice environment I need to construct a framework for Contract based testing. I'm currently investigatingh how to isolate a single service from it's external dependencies inorder to execute the Provider tests. What I need to do is: Keep the WebApi project intact Start an instance of the WepApi with some config-differences Mock out selected dependencies My Solution structure is this: Case-Solution/ ├── src/ | ├──Case.Api | └──Case.Application ├── test/ | ├──Case.Api.Unittest | ├──

Is this a sane implementation of constructor injection?

北城以北 提交于 2020-02-05 08:18:59
问题 Following on from my question on service locators I have decided to use constructor injection instead. Please consider the following code: <?php interface IAppServiceRegistry { public function getDb(); public function getLogger(); } interface IFooServiceRegistry extends IAppServiceRegistry { public function getFooBarBazModel(); } class AppServiceRegistry implements IAppServiceRegistry, IFooServiceRegistry { private $logger; private $db; private $fooBarBazModel; public function getDb() { //

AngularJS DI annotations - why use them?

十年热恋 提交于 2020-02-05 07:20:05
问题 I am learning AngularJS, and am currently trying master Dependency Injection. When I define a controller, the documentation tells me that specifying dependencies through annotations, and just listing them in the parameter list for the constructor are equivalent. Hence, I should get the same outcome if I write either: angular .module('myapp.controllers', []) .controller('MainNavigationController', ['$scope', '$location', function ($scope, $location) { // ... some code }]); or: angular .module(