Questions tagged [dependency-injection]
Dependency Injection is a set of software design principles and patterns that enables you to reduce coupling between components
24,822
questions
0
votes
0
answers
7
views
this.service.method is not a function - inversify
Im new to inversify, I was previously working on Nest JS. I tried creating a MailService and when I tried accessing the method from a controller, it returns the following error
[![error][1]][1]
I have ...
0
votes
0
answers
18
views
Using Application User Microsoft Identity, getting error: not able to use repository in Account Controller
Not able to insert the user object in UserRegister method of Account repository as I am using dependency injection. Please refers the attached images for your better understanding.
Error Image: Please ...
0
votes
1
answer
21
views
How to get value from Configuration object via HostBuilder?
Started a new Console app in .NET 6 and am adding Dependency Injection. In the code below, how can I get access to the IConfiguration object to read a value from appsettings (after calling Build?
The ...
1
vote
3
answers
64
views
Strategy Pattern with Dependency Injection?
Is there an elegant way to deal with dependency injection for the strategy pattern?
For instance, I have my dependency injector that I register a few different strategies with, like so:
container....
0
votes
0
answers
15
views
Android Hilt - Question about binding per activity
I've a question about implementing bindings per activity. Let me give you background. In application I've for ex. two activities, both of them inject same simple provider with two different values. ...
1
vote
0
answers
37
views
ASP.NET MVC - Scoped dependency injection with Web Application page
In my ASP.NET MVC project, I am currently setting up a page with huge a search component that let's you search/filter a list of products.
Whenever you click on a filter, an HTTP request is made to the ...
1
vote
1
answer
19
views
No ServiceType registered
Getting up to speed with .NET 6 and trying to get a working example using DI and a console app. When starting up I get an error trying to get a reference to my service class.
What am I missing?
...
0
votes
0
answers
16
views
Cannot inject EF Core DBContext in an AZ Function MassTransit Consumer
I have a few consumers running inside an Azure Function and messages are being received and consumed by the consumers. DI works fine except when injecting a DbContext it crashes the consumer and ...
0
votes
1
answer
13
views
Inject a backend and a frontend instance into the Game class from the Main class with Dependency Injection
I will simplify the code to make my question easier to understand. The code is something like that:
import sample.backend.*;
import sample.frontend.*;
public class Game {
public void run(){
...
0
votes
1
answer
17
views
Explicit type assignment in Koin singleton
I have a list of objects which are created using reflection in runtime and the types are not known in compile time. How can I define a singleton object in Koin using its class during runtime? ...
1
vote
1
answer
8
views
How to register generic types with multiple type arguments in dotnet core for dependency injection?
Using Dotnet Core 3.1, I use the built in DI solution.
I'm implementing a datapump, that uses a data source and a data target, all of them generics:
public interface IDataSource<TData> where ...
-1
votes
1
answer
20
views
What does @Value annotation mean in Constructor depedency injection in Spring?
I have a snippet that looks like this
@Component
public class Inspiration {
private String lyric =
"I can keep the door cracked open, to let light through";
...
0
votes
0
answers
44
views
How to configure Injector for third-party dependency - NullInjectorError from ngrx effects
I'm getting a NullInjectorError from ngrx effects when it's trying to get an ErrorHandler from the DI container in effect sources.
NullInjectorError: R3InjectorError(t)[EffectsRootModule -> ...
0
votes
0
answers
15
views
How to inject submodule reference into Module in Dagger2
I'm working with Dagger 2 and I want to have in my injections a module (AppApiModule class) from where I can get the injections from others submodules, in this case (MySubmodule class). I'm trying to ...
0
votes
1
answer
60
views
What is the effect of AddScoped in UWP and WPF dependency injection?
I kown the difference between AddScoped, AddSingleton and AddTransient in a ASP.NET app, same service instance will be provided in one HTTP request when a service registered by AddScoped.
But in WPF ...
0
votes
0
answers
38
views
Add Services to Asp.Net Controller Scope
Short: How/is it possible to add services to the scope of all (Odata)Controllers of a assembly without adding them to every controller in the application (i.e. give the assembly a permanent scope with ...
1
vote
1
answer
43
views
Using a DI container to inject an object representing the app user (Winforms)
I was hoping I could get some guidance from the community regarding the use of a DI container for a specific scenario. I am new to DI containers and have been learning Autofac, which I plan to ...
1
vote
0
answers
52
views
Arquillian : Dependency Injection not working
I am trying to use Arquillian to run tests on a remote Wildfly server. I am not sure why the Dependency Injection does not work. Here is the relevant section from POM:
<dependency>
...
0
votes
0
answers
53
views
How do I call an async dependency service from my xaml.cs code behind?
I am overriding the OnBackButtonPressed() event in my code-behind because I add some custom navigation behaviour.
My target is to call a function from my bluetooth classic dependency service (...
0
votes
1
answer
27
views
optionbuilder.IsConfigured always false on abstract dbContext
I have a dbContext for readonly operations and a dbContext for write operations, targeting the same database tables.
I tried to make an abstract dbContext that the two other contexts inherit from, in ...
-1
votes
1
answer
47
views
How to use built in IoC container for constructing converters?
I created converter, into which through constructor injects some registered in app service. How should I configure Automapper to use this services on converter creation? I know that I should use ...
0
votes
0
answers
21
views
Dagger annotationProcessor giving error when using dagegr-compiler-2.41.jar instead of "com.google.dagger:dagger-android-processor:2.41"
I am able to compile and run when using annotationProcessor "com.google.dagger:dagger-compiler:2.41" in build.gradle dependencies but when i use annotationProcessor files('libs/dagger-...
0
votes
1
answer
24
views
How to provide injectable service inside module annotation depending on ConfigService value in Nest.js?
Inside a Nest.js module I want to construct a provider depending on a configuration service variable (typically an environment variable).
I can easily do this:
@Module({
imports: [],
controllers: [...
0
votes
1
answer
35
views
How to use lazy services with dependency injection in typo3?
Can I use lazy services in typo3 (version 11)?
I have installed the package symfony/proxy-manager-bridge with composer require symfony/proxy-manager-bridge. The documentation says that is enough.
When ...
0
votes
0
answers
15
views
Why do we use @Inject in angular
In some blog I got to learn that, Inject is used to manually tell that this class needs DI, let me show this with an example
suppose i have a class like this
import { Inject, Injectable } from '@...
0
votes
0
answers
30
views
Static class or Singleton for utility class in .NET Core with DI
I'm migrating a utility class to a .NET Core class library.
At first I thought I can simply make a static class for this but I have a dependency on IConfiguration so I'm not sure how to proceed with ...
0
votes
1
answer
20
views
Ho to propagate autofac scope/container through classes?
What's the correct way to propagate the autofac container to and access it from different classes?
The way I understand the documentation, I add the scope to each class as constructor argument and if ...
-1
votes
1
answer
31
views
Symfony 4.4: Cannot autowire service "Symfony\Component\Validator\Context\ExecutionContextFactory"
I am upgrading from framework version 3 to 4.4 of symfony. I've got the base running. But my automated tests are failing as the framework itself is missing type hinting on an certain file requiring an ...
0
votes
1
answer
21
views
C# HostedService through IHost - get Instance from running ServicePool
The question is quite simple, yet challenging.
Normal service creation:
IHost host = Host.CreateDefaultBuilder(args)
.ConfigureServices(services =>
...
0
votes
2
answers
63
views
Multiple dependency injections for same class C# and .NET Core
I have an interface
public interface ITest
{
void SayHello();
}
And it's implemented as
public class Test : ITest
{
Test(string type)
{
// Do Something with type
}
public ...
1
vote
2
answers
35
views
Repeated checking of ID path parameter in FastAPI
I have the following route specs:
GET /councils/{id}
PUT /councils/{id}
DELETE /councils/{id}
In all three routes, I have to check in the database whether the council with the id exists, like ...
0
votes
1
answer
31
views
Initializing a class object that uses dependency injection
I am working on creating a JAVA library that does no use any dependency injection framework. I need to use a class from an external library. The external library uses DI framework to inject dependency....
0
votes
0
answers
17
views
Spring DI of Constructor parameter with Collection in auto-configure
I m wondering about some Constructor injection in spring boot when creating beans .
For example , in spring boot auto-configure , The JacksonAutoConfiguration file
@Bean
@Scope("prototype&...
-1
votes
1
answer
42
views
Why is Autofac injecting null into my constructor?
I am having issues with my DI in a C# project. When I run my test I am getting an error that says Object reference is not set to an instant of an Object. It is failing on the var retryPolicy = ...
-1
votes
1
answer
28
views
How To Log Effectively Without Flooding Log Files
In an application with long running task and dependency injection log files can easily become flooded with useless data. This makes it harder to follow log files and drains storage space.
Examples:
A ...
0
votes
1
answer
50
views
'NoSuchBeanDefinitionException: No qualifying bean of type' Error after adding new dependency injection to already implemented & unit tested class
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.companyname.enterpriseteam.demo.anonymizer.DAnonymizer' available: expected at least 1 bean ...
0
votes
1
answer
44
views
C# How to decide which class to run in Dependency Injection based on multiple classes implement using same interface
I am working on .NET 6.0 application.
I have an Interface IDestinationFileNaming that is implemented by multiple classes. How I Can choose which class to call based on they implementing same interface....
0
votes
0
answers
41
views
how to use HttpClient in DI
This is a demo
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddHttpClient<MyClient>();
var app = builder.Build();
using (var scope1 = ...
-2
votes
0
answers
33
views
Unable to resolve service DI .net core
I am trying to figure what I did wrong
I am facing a dependency injection issue I am getting exception while running my web application
Inner Exception 1:
InvalidOperationException: Error while ...
0
votes
1
answer
47
views
How can I utilize dependency injection in Swift with minimal reliance on external libraries?
I am trying to understand how dependency injection works in Swift so I can inject into my ViewController. I have some experience with it in Kotlin but am unsure of how to approach it in Swift. I would ...
0
votes
0
answers
24
views
Symfony, API Platform custom operation Action, get Notice: Undefined property RequestStack
I'm using symfony 5 with API Platform to create Rest API.
I have an IIG entity and i'm trying to add a custom operation :
/**
* @ApiResource(
* shortName="iig",
* ...
0
votes
1
answer
45
views
Using interfaces in dependency injection in .Net MAUI
I am trying to implement dependency injection for the first time in my new project in .Net MAUI. For testing purposes, I want to fetch data from a local source in my ViewModel. The production scenario ...
0
votes
2
answers
79
views
Can ASP.NET core dependency injection inject null references?
In my job we are developing ASP.NET core applications. I keep seeing the follwing pattern used with dependency injection. In this example Logic depends on OtherLogic:
public class Logic {
private ...
0
votes
0
answers
46
views
Resharp DI and DNS resolution
I'm upgrading to version 107 restsharp and i'm wondering if both these options below are ok ways of doing dependency injection in dotnet with restsharp.
The documents say don't create a new restsharp ...
0
votes
0
answers
29
views
Can't inject the guice dependency in the jersey filter
In the process of setup a bridge between guice and jersey, I ran into one problem.
When trying to create a jersey filter, I was unable to inject guice dependencies into it.
I found a duplicate, ...
1
vote
1
answer
32
views
Asp.net core service per request scope in child scopes
Is there any way to register service in asp.net core as Scoped to request not to current request scope?
public void ConfigureServices(IServiceCollection services)
{
services.AddScoped<IMyService, ...
1
vote
1
answer
38
views
How to get Service instance using generic asp.net core
I am working on a console application where I want to get the instance of a generic service type. Here is my implementation it gives me null.
public class HelperService
{
private ...
0
votes
1
answer
30
views
Delay Returns with NSubstitute
I have an interface IDiscosClient, for testing/demo purposes while I'm developing the app, I want a mock to return a new model when the .GetSingle<T>() method is called with a random delay of ...
0
votes
1
answer
14
views
Resolve all already created service instances from .NET service provider
I would like to request all created instances from a transient service via the IServiceProvdier. My problem is that requesting them seems to create additional instances instead of retrieving only the ...
0
votes
0
answers
11
views
Dagger Dependency injection circular dependency
So i have Something like
class A {
@Inject // there are providers for things elsewhere
A(Thing1 o, Thing2t){
}
}
class B {
@Provides
A provideA(A a){
return A
}
interface component {
A getA();
}...