Questions tagged [dependency-injection]

Dependency Injection is a set of software design principles and patterns that enables you to reduce coupling between components

Filter by
Sorted by
Tagged with
-2 votes
1 answer
39 views

Where does Spring boot application scan the annotations , create beans and inject them

I wanted to understand as to how spring boot application scan the annotations, create the beans and inject them, so I create a simple spring boot CRUD application. @SpringBootApplication public class ...
CuriousMind's user avatar
  • 8,387
-1 votes
0 answers
29 views

How to call a method of scoped service from a class located in it?

I have a scoped service, containing concurrent dict of Game instances. In game class there is a method "updateSession", which has to call an "Update" method of scoped service ...
Erray1's user avatar
  • 1
0 votes
0 answers
46 views

SwiftUI using Enum across module

I am trying to use an enum across multiple modules as follows // ComponentsModule public struct FloatView: View { var str: String public init(str: String) { self.str = str ...
Geob's user avatar
  • 586
0 votes
0 answers
33 views

Getting a dependency injection error when I try to add route parameters to my Angular component

I want to make a component that uses a route parameter. Resources online all suggest that this is pretty easy with the ActivatedRoute syntax. But whenever I try, I keep getting this error: Error: ...
Luke Bretscher's user avatar
0 votes
1 answer
25 views

ASP.NET Core Razor - redirecting from a dependency injected service

I'm building a Razor pages website. Users are required to login to access the website. I have a controller behind the login, e.g: [Authorize(AuthenticationSchemes = CookieAuthenticationDefaults....
gbgr's user avatar
  • 13
0 votes
2 answers
33 views

Returning multiple implementations of same interface from Abstract Factory with ASP.NET Core

I want to make multiple implementations of a specific interface accessible through an Abstract Factory in .NET Core. Based on a supplied enum the correct implementation should be returned. This is my ...
Engin Şengül's user avatar
0 votes
0 answers
10 views

Dependency Injector not wiring containers in Flask application

I'm using Dependency injector on my Flask Project. When trying to add an expense to my FakeExpenseRepository, i receive the following error: AttributeError: 'Provide' object has no attribute '...
Tomas Rojo's user avatar
0 votes
1 answer
22 views

Want to inject some services into a WebHostBuilder for testing. Can I do it after WebHost has been started? Should I change test initialization?

I'm working in a very large existing codebase where it's hard for me to fully refactor MyTestFixture. Tests are setup like this: MyTestFixture.cs public class MyTestFixture: IDisposable { IWebHost ...
pseudodev's user avatar
0 votes
1 answer
14 views

InvalidOperationException: Service Not Registered in ASP.NET Core Worker Service

I'm working on an ASP.NET Core application with a BackgroundService where I'm facing an issue with dependency injection. I've set up a generic repository pattern and have registered my services in ...
Nico Florez's user avatar
2 votes
2 answers
93 views

Get all instances of a keyed service type in .NET 8

Before keyed services were introduced in .NET 8 you could retrieve all of the instances of a class or interface with IEnumerable<MyType> myTypes like so: Program.cs builder.Services.AddSingleton&...
Starfish's user avatar
  • 3,394
0 votes
2 answers
68 views

How to use dependency injection for a ASP.NET Core web application?

I have created an ASP.NET Core web app which has two classes of interest: public class DBConnect { private readonly IConfiguration _configuration; public DBConnect(IConfiguration config) ...
Yan Soo's user avatar
  • 11
-1 votes
0 answers
45 views

Importing files when using PHP configuration files in Symfony

I have a Symfony's services.yaml which defines a "basic" container configuration and import di.php files to configure some specific services. imports: - { resource: '../src/**/di.php' } ...
pepper's user avatar
  • 1,730
0 votes
0 answers
39 views

How would I return all children related to a property in a generic method using Entity Framework

Below is a method in my generic repository which every repository inherits from. public IQueryable<T> GetAllIncluding(params Expression<Func<T, object>>[] includeProperties) { ...
jtslugmaster08's user avatar
0 votes
0 answers
47 views

How to register a database connection, such as npgsql, with .NET Dependency Injection without relying on EF, Dapper, etc

I have a pretty simple service using Postgresql as the database. It is just a few tables, with a few columns for indexing and the rest of the data is stored in a jsonb column. Since it's so simple ...
Stephen Gilboy's user avatar
1 vote
1 answer
27 views

angular - What does ... interface Type<T> extends Function { new (...args: any[]): T; } ... mean?

Interface Type<T> is an interface which is extending global type Function. I found this in typescript documentation Function about global function. What does the above code mean? I got this code ...
Sujeet.G's user avatar
  • 161
0 votes
0 answers
13 views

Injecting a service into a class not instantiated by NestJS (Trying to implement Colyseus + NestJS)

I'm struggling to achieve a dependency injection inside a class not instantiated by NestJS. I want to use the Colyseus Framework (https://colyseus.io/) in my NestJS project, and I need to inject ...
melones's user avatar
0 votes
0 answers
8 views

Dart: How to implement dagger like dependecy injection @MapInto and @StrinKey with get_it

I'm using the get_it package in Dart for dependency injection, and I'm looking for a way to implement similar functionality of Java Dagger annotations @StringKey @MapInto in dart to eliminate the ...
Alwani's user avatar
  • 1
2 votes
2 answers
82 views

How to get a dictionary of keyed services in ASP.NET Core 8

In ASP.NET Core 8, we have the option to register services using a key. Typically, injecting IEnumerable<ICustom> in a constructor will return all services that are registered of the ICustom. ...
Jay's user avatar
  • 1,322
0 votes
0 answers
52 views

How to use dependency injection for helper classes after an API call returns in .NET?

I'm writing a .NET API that accepts a request, saves the request to a database, then runs further validation/processing. Since the validation takes a long period of time, we're saving the request to ...
Zachary Pataky's user avatar
0 votes
0 answers
11 views

Pylint throws E1120 error in dependency injection

I've implemented a custom decorator which injects arguments to a function when necessary. Code works as expected, but pylint throws a E1120 error because it expects the injected instance as an ...
juanjo12x's user avatar
  • 183
0 votes
1 answer
21 views

Resolving Microsoft Logger with Unity throws error

I am using .NET 4.8. and I registered Microsoft.Logger with unity injection: var factory = new LoggerFactory(); factory.AddLog4Net("log4net.config"); container.RegisterInstance<...
pakerinjo's user avatar
0 votes
0 answers
68 views

Primary Constructor Parameter not Working in Unit Test

Problem Statement: Generally, we write asp.net unit tests for Service layer: Service.cs public class AppService : IAppService { private readonly IAppRepository _appRepository; public AppService(...
Ming Sun's user avatar
  • 274
0 votes
2 answers
58 views

Use DI to instantiate a service with a dynamic parameter?

I have a class with below constructor: public MyClass(SomeRequiredService srs, string someRandomInput) { } How can I register MyClass with DI but with an option to pass a different someRandomInput ...
Hamid Z's user avatar
  • 300
0 votes
0 answers
23 views

What is the difference between a "hook", a "plugin", a "mount point", and a "dependency Injection"? [closed]

In all cases we provide a point in our code, where the user of our code can inject his own code, via a function or a class, and we call that code. Which differences are there, if any?
Nils Lindemann's user avatar
0 votes
0 answers
23 views

C# how can take parameters from BD before execute configureServices from Injection Dependecy

In a .net 7.0. I need load some data before execute the configuration Services to Dependency Injection. ` private static IServiceProvider ConfigureServices(IConfiguration configuration) { var services ...
FoundingCoding99's user avatar
0 votes
0 answers
18 views

Configure Specflow to test a dll with Microsoft DI

The scenario is as follows: I have created a .net dll that uses microsoft dependency injection. This dll can be used by either a web api or a windows service. I need to create a specflow test that ...
ScottKirwanThomas's user avatar
2 votes
0 answers
37 views

Best practises for compile time safe factory pattern with dependency Injection

I have a situation where I need to resolve a type, of which the constructor contains a combination of services, as well as custom parameters. Hence I will use a factory to resolve it. Note, I do not ...
Red Riding Hood's user avatar
0 votes
1 answer
39 views

Get ApiController instance at run time with .NET 7.0

I have a Web API application with 2 ApiControllers (that must be kept separated). I use dependency injection and I need to access an instance of an ApiController from the other one. Not being a ...
Sergiob's user avatar
  • 848
0 votes
0 answers
23 views

How to deal with library inline generic functions with reified and allow dependency injection?

I have a some library method, which I can't really change. class Lib { inline fun <reified T> getSomething(): T { // ... } } It uses reified generic parameter to pass ...
MrKew's user avatar
  • 843
2 votes
1 answer
40 views

Unable to register Microsoft Logger with Unity

I have a Worker with logger and the project is throwing an error: Resolution of the dependency failed, type = "Test.IWorker", name = "(none)" public class SimpleWorker : IWorker { ...
pakerinjo's user avatar
0 votes
0 answers
14 views

cannot convert from 'Microsoft.Extensions.DependencyInjection.IServiceCollection' to 'Microsoft.Extensions.DependencyInjection.ServiceCollection'

Getting the following error when launching asp.net core 6.0 c# web application. Application did not through any run time error. it just displays 404: page not found. Unable to launch the home page. I ...
Seeker of Best Solution's user avatar
0 votes
1 answer
15 views

Unsatisfied dependency for type io.acme.helpers.OAuth2Helper and qualifiers [@Default]

I am trying to use dependency injection from my own library using Quarkus as the main framework and it's not working out. When I declare the class inside the project, @Inject works exactly as ...
dimon37's user avatar
0 votes
1 answer
34 views

Unit of Work has null repository property in Unit Test

I cannot run a unit test from the BLL/Service layer. The test mocks the Unit of Work because its a unit test for a service method. Thus, the uow mock has a null repository property which fails the ...
Mihai Socaciu's user avatar
0 votes
0 answers
12 views

Possible to collect data from a injectable service?

Scenario: A blazor web assembly application that will manage, among other things, information about companies. At login, I want the user to be able to select a "working company" and place it ...
Prv's user avatar
  • 161
0 votes
0 answers
77 views

DbContext and migration - clean architecture [closed]

Problem Statement Architecture Overview I am aiming to get a clean architecture for a new app I want to develop. And I struggle to get the DbContext to work properly. The layering is: 1. ...
Stefan's user avatar
  • 133
0 votes
0 answers
47 views

How to register generic services with an interface using reflection

I have multiple services with this pattern, each repository class is using generics for the context and is implementing an interface also with generics: public partial interface IUserRepository<...
Bruno's user avatar
  • 4,716
1 vote
1 answer
29 views

Laravel Service Provider is not injecting values into Service class

I have a service provider called "MyServiceProvider.php": <?php namespace App\Providers; use App\Services\MyService; use Illuminate\Support\ServiceProvider; class MyServiceProvider ...
Rollin's user avatar
  • 316
1 vote
0 answers
27 views

I want to inject Repository in Controller constructor using typedi

I want to inject Repository in Controller. Here is my FiedSettings Repository I have tried to follow typedi docs. Field Setting Repository import { Service, Container } from 'typedi'; import { Entity,...
Nitin Kumar's user avatar
1 vote
1 answer
24 views

function app startup from scratch (not using the FunctionsStartup)

I need to use Startup.cs that doesn't inherit from FunctionsStartup. My program looks like this.. public class Program { public static void Main(string[] args) { CreateHostBuilder(args).Build()....
Rod Johnson's user avatar
  • 2,407
1 vote
1 answer
29 views

Circular initialization dependency with picocli, typesafe config and Guice

In a Java-based CLI application, I'm using the following libraries Guice for dependency injection Lightbend Typesafe Config to handle the configurable options Typesafe Config Guice to tie these two ...
vwegert's user avatar
  • 18.4k
0 votes
1 answer
48 views

inject dependencies injection with parameters

I'm using ASP .net 6 to create web api. My project structure looks like this: in controller puclic AccountController(IAccountService service) { } in service public AccountService(DatabaseContext db) {...
Ming Hieu's user avatar
  • 169
0 votes
0 answers
21 views

Guice bindings on config changes

I am using cfg4j library for reflecting the changes in the beans on changes in the config files (auto-reload/refresh) public ConfigurationProvider getConfigurationProvider() { ...
Paul Schimmer's user avatar
0 votes
2 answers
80 views

How to register GraphServiceClient in ASP.NET Core 6.0?

I am using the GraphServiceClient to get user.Department in the following controller: namespace ExternalApp.Areas.Budget.Controllers { public class Controller : BaseController { ...
csharpdev's user avatar
0 votes
0 answers
33 views

Main and Service Dependencies outside of Angular

How can dynamically inject services into an Angular project from an external npm project and run the Angular from outside? Seeking a clean architectural solution for runtime service injection. I have ...
Market's user avatar
  • 450
0 votes
0 answers
72 views

Entity Framework Cannot access a disposed context instance - but works called from external controller

Handling a transaction in a controller, I have a function in my 'accountsHelpers' lib to mark a payment as paid. It was geting heavy in the controller so I created a 'processReceipt' function in the '...
Brett JB's user avatar
  • 722
0 votes
1 answer
39 views

Replace app config with instance in tests using Options pattern

I use the C# Options pattern, e. g. with a config type like this: public class MySettings { public bool IsEnabled { get; set; } public int NumberOfDays { get; set; } } Within my tests, I ...
mu88's user avatar
  • 4,423
0 votes
1 answer
60 views

Injecting userid in DbContext for multi-tenant application

I am building a multi-tenant application with .net identity. I want each user when they log in to view their own data. I have a user resolver service where i inject httpContextAccessor to try to ...
athagiorgos's user avatar
1 vote
1 answer
43 views

Redux Toolkit typescript error when inyecting extra argument in Thunk Middleware

I'm trying to customize the Redux Toolkit`s included Middleware to add an extra argument. This extra argument is an implementation of a Repository. When I configure the store I add that extra argument:...
Ale's user avatar
  • 2,304
1 vote
2 answers
65 views

How to deal with a Controller containing two constructors in ASP.NET Core?

I have an API upon which I mean to do Unit Testing via xUnit and Moq. It had one constructor actually, but I had to add another one for the specific purpose of Testing as per a suggestion by Visual ...
Aboliii's user avatar
  • 47
2 votes
1 answer
50 views

Why is the use of IConfiguration a bad thing in Azure Functions Dependency Injection

Here it states: Injection of IConfiguration can lead to unexpected behavior. Without much explanation of what that means. Does anyone know: What scenarios this happens in? What is the behavior? Why ...
GoldieLocks's user avatar

1
2 3 4 5
530