Join us in building a kind, collaborative learning community via our updated Code of Conduct.

Questions tagged [dependency-injection]

A design pattern to reduce coupling between components, by dynamically injecting into a software component dependencies that it needs to function.

0
votes
1answer
8 views

How to use Dagger2 in Android to inject activity objects easier?

On Android, When using Dagger2, I have to call the following line on every activities that uses apiService: @Inject public ApiService apiService; @Override protected void onCreate(Bundle ...
0
votes
0answers
6 views

Angular DI - useFactory - Provider : Is there a way to invoke Provider Factory function second time when local State gets updated?

The scenario goes as follows: 1. App has root module and it's constructor resolves a Promise and returns a Constant. @NgModule({ ...., providers : [ ... { provide: ...
0
votes
1answer
26 views

How to register all validators generically [duplicate]

I have a problem with dependency injection using open generic types. To register a validator now, I must write: container.RegisterType<IValidator<User>, UserValidator>(); I need ...
0
votes
0answers
13 views

How inject a Singleton class annotated with @Startup? @Inject, @Resource, @EJB ou BeanManager?

I have a class like this: @Singleton @Startup @Default public class A { private Manager manager; // Manager is an interface @PostConstruct public void init() { if (some rule is ...
0
votes
1answer
48 views

How to make a generic class implement interface

I have this generic class: public static class ListBuilder<T> where T : class { public static void Build(XmlElement element, string elementeName, ref List<T> lista) { ...
0
votes
0answers
9 views

Angular 5 + UI Router: Eagerly Loading Services for UI Router Resolve when your application is imported by a different root module

I am creating an Angular 5 application with a single module that will be imported by the larger "root" module in an Angular 5 application beyond my reach. I do not have direct access to this "root" ...
1
vote
1answer
25 views

ASP.NET Core 2.x - Proxy Service Provider

I'm trying to build a DI proxy for ASP.NET Core 2.x apps. My understanding is that you do that by returning IServiceProvider instance in the ConfigureServices method e.g. public IServiceProvider ...
0
votes
1answer
33 views

Using multiple connection strings for the same DBContext

I am working on a asp.net core project which uses MongoDB and I am using dependency injection as well. How current system works There is only one database and the connection string is saved in the ...
1
vote
1answer
19 views

UWP Invoce ContentDialog as Service using Dependency Injection

I'm trying to adapt the example from the post UWP ContentDialog Invocation. I use the same code, but when I press the button only an empty box appears: In addition my MainPage.xaml.cs: public sealed ...
-1
votes
1answer
27 views

Dynamically creating Objects at runtime with parameters DI vs Factory

I currently have a case where I have multiple customers who have variability of on what forms of notifications they want (ie email, fax, etc.). They could also want one or more than one. So I have ...
0
votes
0answers
19 views

How do I integrate Nancy with Autofac and ASP.NET Core windows service

Let me try to keep it simple. My end goal is to create windows service using asp.net core 2.1 and Nancy framework. After lot of research i found below steps Set up a Windows service - https://...
2
votes
1answer
19 views

Using Storyboard and custom View Controller init

When pushing view controller programatically, one can easily do some dependency injection through the init method : let dummyVC = DummyVC(dummyManager: DummyManager()) self.pushViewController(dummyVC,...
0
votes
2answers
55 views

Is it good practice to have ALL dependencies in a base class?

I have a WPF application using the MVVM pattern. I'm using Autofac as the DI container. Like other applications similar to mine, I have a ViewModelBase class which implements the ...
0
votes
1answer
18 views

Two different types leading to the same instance in Unity

Say, that I have a class: class A : IInt {} I'm registering the class in Unity: container.RegisterType<A>(new ContainerControlledLifetimeManager()); I'd like to register IInt to the same ...
-1
votes
1answer
21 views

Unity DI - C# Dependency Injection how to use with a repository class constructor ? It's only intended for controllers?

i wanna know if it's possible to inject dependency for a class constructor as it is injected for controllers, i have the following cenario as an example: An AccountController which depends on an ...
0
votes
1answer
22 views

Spring dependency injection doesn't work in ConstraintValidator

I'm trying to use my service into custom ContextValidator annotation using @Autowired. I looking for some help in old questions on SOF but I was unfortunately so I've created is one new. My goal is ...
0
votes
0answers
15 views

IOptionsSnapshot in .net core Console application not working

Below is the example of .NET Core console application, uses constructor dependency injection with IOptionsSnapshot<T>. class Program { static void Main(string[] args) { ...
0
votes
1answer
30 views

Does it make sense to use generic parameters to select which service implementation will be injected?

I have a class called ReportWorkflow<TReport> that calls some objects to generate a report of a specific type, the object are always called in the same sequence and the only true difference is ...
0
votes
1answer
30 views

Asp.Net Core No service for type has been registered

I have the following two classes public class RepositoryConnection : IRepositoryConnection{ public RepositoryConnection(IConfiguration configuration, ILogger<RepositoryConnection> logger){ ...
0
votes
0answers
14 views

Injecting values in the DelegatingHandler through IHttpClientFactory

When building custom middelware for IHttpClientBuilder, using the DelegatingHandler and IHttpClientFactory. The constructor of my class looks like this. public HttpApiFactory(...
0
votes
1answer
11 views

PHP-DI: Interface being injected into constructor won't resolve correctly

I can't seem to get PHP-DI to properly resolve an interface to it's configured class when injected in the constructor. In the following code, using the container to get \Foo\IDog returns a Poodle ...
1
vote
4answers
27 views

Run unit tests against two different injected dependencies

I have two service beans in my application which both implement an interface. For that interface, all methods must perform the same (tho the internals differ). So I'd like to write one set of tests ...
1
vote
0answers
23 views

Spring Managed Custom Validator not being used from endpoint

I've been at this for a while, but I have a Spring managed custom validator that looks like the below, I have some print statements in there which I'll get to later @Component public class ...
1
vote
1answer
45 views

An error occurred when trying to create a controller of type. Make sure that the controller has a parameterless public constructor

I have integrated dependency injection with code first entity framework. But when I call method of api that time I am getting error. System.InvalidOperationException: An error occurred when trying ...
3
votes
3answers
87 views

Unity injection with too many constructor parameters

I have the following Unity related question. The code stub below sets up the basic scenario and the question is at the bottom. NOTE, that [Dependency] attribute does not work for the example below ...
0
votes
1answer
33 views

How to Overcome Entity Framework Caching/Tracking Using MassTransit?

Forgive my ignorance, but it appears that MassTransit treats singleton and scoped dependencies effectively the same. At least in the case of an Entity Framework DbContext and, therefore, the ...
0
votes
2answers
41 views

How to set a dynamic “id” attribute of an angular component?

My problem is related to placing the same component with different parameters on the same page. In this case it is a component containing a chart from a third party Javascript library (D3JS) which ...
0
votes
1answer
46 views

How to use dependency injection to inject IO.gets input in Elixir?

Suppose I have a function that validates user's input and then output something: def set_name(user_input) do case !InputValidators.empty_input?(user_input) do true -> user_input ...
-1
votes
1answer
33 views

Can any one give example of dependency injection with MVC swift IOS?

i bit of stuck with dependency injection with mvc swift. i have an idea of whats mvc. i just need to know how to use dependency injection? And why are we using it? what is dependency injection? And ...
0
votes
1answer
45 views

Dependency Injection into Roslyn analyzers

I have a custom Roslyn analyzer which inherits from DiagnosticAnalyzer. It is packed in VSIX extension which contains custom Package class. I'd like to pass an instance of a class with the settings (...
0
votes
0answers
29 views

Dagger custom scope, how to?

i need following scope structure in dagger 2.16 --> Custom Scope how can i do that? i dont want use dagger android support because its Beta i try this: //ApplicationComponent.java @Singleton @...
0
votes
2answers
23 views

Register ASP.NET Core ILogger<> from built-in logging mechanism to Autofac

I have a ASP.NET Core app using Autofac as DI container. I'm also using built-in logging mechanism that provides ILogger<> dependency. Now I'd like to register it in Autofac. How?
0
votes
1answer
30 views

Accessing Unity-specific functionality in .NET Core dependency injection

I have a .net core 2.1 console app. I'm building the container as below: public IServiceProvider ConfigureServices() { var services = new ServiceCollection(); // Register services here. ...
1
vote
1answer
37 views

ASP.NET Core 2.1 unable to cast IServiceProvider

My application ASP.net web API project on core 2.1 I have the following IOC container class // Ioc.cs using Microsoft.Extensions.DependencyInjection; using Rendigo.Core.Data; public static class ...
2
votes
1answer
51 views

How to mock external dependencies in tests? [duplicate]

I've modeled and implemented a car using an extern crate inside the implementation: extern crate speed_control; struct Car; trait SpeedControl { fn increase(&self) -> Result<(), ()>...
1
vote
1answer
29 views

Using CoreData and Dependency Injection - Thread 1: Fatal error: init(coder:) has not been implemented

I'm trying to learn how to use CoreData and the correct way to implement it, currently I have watched this video on youtube (link below). At the moment it all makes sense, however when I go from one ...
0
votes
0answers
5 views

DI Factory Method Symfony 3.4

I have abstract factory with "get" method: Factory class: public function get(string $action): Action { // what will write ??? } How i can create object with dependencies? Action class have ...
2
votes
1answer
46 views

Dispose being called multiple times by Microsoft DependencyInjection

I'm registering a class twice but with different contracts. services .AddSingleton<MyClass>() .AddSingleton<IHostedService>(sp => sp.GetService<MyClass>()); The class ...
0
votes
0answers
7 views

MStestV2 and Unity framework

We are using unity framework for intializing objects, everything work fine. But when I create MStestV2 test cases and call the methods, objects are not getting initialized and all testcases are ...
0
votes
0answers
36 views

Optional dependency class in Spring Boot Library

I'm creating a library for in house use and i want to add spring-cloud-starter-sleuth as an optional dependency so in the library's pom file the following is defined <dependency> <...
1
vote
0answers
18 views

Specifying class type in nested config sections in .NET

I've been going through all the documentation I can find for ConfigurationSection and ConfigurationElement trying to figure out how to nest without contaminating my classes with a ton of XML parsing - ...
0
votes
2answers
34 views

Laravel 5.5 Unresolvable dependency resolving

I'm having an issue with some dependency injection and could use a hand. I'm new to all this and Laravel so let me know if you need more clarity/context/code examples. The error is get is thise: ...
0
votes
1answer
16 views

Override the style sheet of a dependency in a maven project

I have a dependency in a maven project which renders html pages. I want to change the style of a table since the view is getting cut off. How can I access the stylesheet of the table and inject rules ...
0
votes
1answer
27 views

Getting lifestyle mismatch registered as transient but implements idisposable error

I am trying to inject the API dependency and MVC dependency. But when I try to inject the MVC Dependency I get the error: The configuration is invalid. The following diagnostic warnings were ...
-4
votes
1answer
57 views

IoC container that doesn't require registration

Is there such a thing? If all I need to do is resolve IThing to Thing, why do I need to even create a registration? I should just map dynamically during run-time. I can easily create one with ...
0
votes
2answers
38 views

Google Guice Inject Member not working

I'm creating a new project using GoogleGuice as DI. So i create an interface of my DAO: public interface UserDAO extends DAO<User> { // Some CRUD methods } and an implementation of that:...
-6
votes
0answers
29 views

Why is my Angular app NOT resulting in a circular dependency warning?

In my Angular project, I have a SharedModule, which declares some components. In one of those components, aptly named SomeSharedComponent, the SharedModule's file (../shared.module) is imported so ...
1
vote
2answers
40 views

Preventing the User Interface Layer from Depending on the Data Access Layer

I have 3 projects in .NET DAL (data access layer) UI (user interface) BI ( logic) DAL call the BI (services) And The BI Call the DAL (repository) my problem in my UI project in (global.asax) - I ...
3
votes
2answers
59 views

Dependency Injection ASP.NET Core: Register multiple implementations

I have the following classes structure: interface IContractService{} class Service1 : IContractService{} class Service2 : IContractService{} class ContractServiceFactory { private readonly ...
-1
votes
0answers
40 views

SimpleInjector and multiProject

I have SimpleInjector (DI) I want to use in my different project I have 4 project UI project , BI project , Dal project , and shared Project I want all of project use SimpleInjector. now only the ...