27,053 questions
2
votes
0
answers
110
views
How to make Angular app wait for the config (provider) to be loaded via AJAX?
The code in app.module.ts is like so:
export function ConfigFactoryInitialize(configService: AppSettingsService): () => Promise<AppSettings> {
return () => configService.loadAsync();
}
...
Best practices
1
vote
3
replies
127
views
Why is field injection discouraged in Spring, while it is encouraged in Angular?
In both Spring and Angular, there are two common ways to inject dependencies:
Constructor injection
Field-style injection (@Autowired in Spring, inject() in Angular)
In Spring, constructor injection ...
Best practices
1
vote
3
replies
114
views
Decorator Pattern with DI
I'm learning about design patterns and I stumbled upon the Decorator pattern. I did my research, and implemented a working version.
public interface IWriter{
void Write(string text);
}
public ...
1
vote
1
answer
89
views
Root provider injected into service resolved from provider of new scope
I have a Blazor server application. I have an IHostedService that is meant to do startup tasks in the StartAsync() method:
builder.Services.AddHostedService<StartupTask>();
It has a constructor ...
1
vote
1
answer
52
views
ASP.NET Core DI error: Unable to resolve service for type StackExchange.Redis.IDatabase
I am working on an ASP.NET Core Web API and using Redis (StackExchange.Redis) for rate limiting.
Redis is running using Docker Desktop, and the container is up and accessible on localhost:6379.
...
Best practices
2
votes
2
replies
127
views
How to make a bean initialize before DataSource without excluding auto‑configuration
I have a Spring Boot application that relies on the default DataSourceAutoConfiguration to create my DataSource bean. I also have a custom bean that must be fully initialized before the DataSource ...
Best practices
1
vote
5
replies
114
views
Is Link-Time Dependency Injection possible in any common linkers?
I've been using Java and Google's Dagger2 dependency injection, and contemplating how to implement similar Dependency Injection in C++ with little-to-no overhead. One stumbling block I've found is ...
1
vote
2
answers
196
views
C# dependency injection error: "Some services are not able to be constructed"
I am getting the following error when starting my app:
System.AggregateException: 'Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: ...
1
vote
1
answer
93
views
Use Controllers/Services/Models pattern and dependency injection
I'm building an API with Slim 4 and want to use the pattern Controllers/Services/Models, but I'm having some difficulties with dependency injection.
For the sake of example, I have these endpoints :
$...
0
votes
0
answers
37
views
Dependency resolve fails while autowire declared bean in another module of project
I have a multi-module project, jsonHelper is defined in the common module, added as dependency to the orchestrator module, but ObjectMapper is not autowired in the orchestrator module.
I got this ...
0
votes
0
answers
41
views
NestJS E2E Tests: ConfigService is undefined when injected into providers
I'm having issues with dependency injection in my NestJS E2E tests using Vitest. The ConfigService works perfectly when running the application locally, but it's undefined when providers try to use it ...
2
votes
1
answer
80
views
Provide Angular Keycloak (v19+) config based on ENVIRONMENT_CONFIG not possible
Introduction
I'm currently migrating some projects from Keycloak Angular v18 to v19, with its big rework. One of the changes is that you now have to use the provideKeycloak() method in the providers ...
Best practices
0
votes
1
replies
42
views
fast api : where to add dependencies
Which is a better approach to follow in fast api to add dependency to the router or function ? check_person_exists will accept the person_id as an input parameter
@router.put(
"/update-name/{...
3
votes
2
answers
83
views
Conditionally register collections of non-generic abstractions in Simple Injector
Consider having two types
public class TypeA
{
public TypeA(IEnumerable<IChild> children) { ... }
}
and
public class TypeB
{
public TypeB(IEnumerable<IChild> children) { ... }
}
...
1
vote
0
answers
71
views
ng-bootstrap Datepicker throws NG0203 takeUntilDestroyed() error on Angular 20
Problem
When clicking on an ngbDatepicker input to open the datepicker popup, I get the following runtime error:
ERROR RuntimeError: NG0203: takeUntilDestroyed() can only be used within an injection ...
1
vote
0
answers
125
views
Resolve key with dependency injection in AddJwtAuthentication in ASP.NET Core app
I want to authenticate my users with JWT tokens. For this purpose, I write an ISigningKeyRepository that handles rotating and creating signing keys in the database. Now when I want to register JWT ...
-2
votes
1
answer
93
views
ASP.NET Core migrating database issue
I am new to ASP.NET Core and C# development, I was following a tutorial that create a web applications and get this error:
Unable to create a 'DbContext' of type 'AppDbContext'. The exception 'Unable ...
1
vote
1
answer
174
views
Boost-DI with concept-based static polymorphism
I'm using Boost.DI, and I've been having a lot of success learning it. However, I ran into a wrinkle that I can't see exactly how to fix.
The following compiles, links and runs as expected:
class CC
{
...
0
votes
2
answers
174
views
Can I use lazy loading with factories?
I have a project which automatically sets up dependency bindings (using PHP-DI) for various database connections based on datasources defined in a configuration file:
// In reality this is loaded from ...
1
vote
1
answer
128
views
PHP dependency injection and PSR LoggerInterface [closed]
I am missing some kind of best practice for implementation of PHP dependency injection and the PSR LoggerInterface.
Currently (without dependency injection) I have created my own LoggerFactory with ...
Best practices
0
votes
0
replies
66
views
Providing System Services through DI
I’m using Koin for dependency injection in an Android app, and I want to provide BluetoothManager through DI.
Right now, I have a module like this:
val bluetoothModule = module {
single<...
1
vote
1
answer
147
views
Constructor-based dependency injection fails when requesting bean via beanFactory.getBean(Command.class, dto) in Spring Boot
I'm migrating from field injection (@Autowired) to constructor-based injection in a Spring Boot application (Java 21), but I'm running into a BeanCreationException when Spring tries to instantiate my ...
Best practices
0
votes
1
replies
51
views
Custom annotation for performing customized injection logic
Spring 5.3
Use case:
I’ve got an annotation
public @interface MyInject {
String region();
String type();
}
I want to use this annotation in a similar fashion to
@Resource(“beanName”)
but ...
Best practices
0
votes
3
replies
78
views
Most efficient way to manage the lifecycle of HttpClient in many wrapper classes?
Our application is somewhat of a middleman that transforms data from numerous APIs. Initially to simplify things, we wrote a bunch of specific clients which wrap an instance of HttpClient created in ...
Best practices
0
votes
0
replies
39
views
How to get Autofac Instance Per Request semantics in Asp.Net Core while keeping it idiomatic, i.e. not using tagged matching scopes?
In Asp.Net (not Core) we have InstancePerRequest which uses tagged matching child scopes.
In Asp.Net Core they deprecated InstancePerRequest in favour of InstancePerLifetimeScope which as I understand ...
-3
votes
1
answer
280
views
Should one service call another service or use the repository directly? [closed]
I'm learning Clean Architecture and I can't figure this out.
Imagine this scenario: I have a ServiceA that calls its repository:
public class ServiceA : IServiceA
{
private readonly IRepositoryA ...
3
votes
1
answer
124
views
What options exist for ownership/references in Rust dependency injection?
I'm interested in the options for providing ownership or references to dependencies when doing dependency injection in Rust. I don't mean like a DI framework or anything like that, just the general ...
Advice
1
vote
9
replies
114
views
Is it a good practice to maintain separate properties for factories, singletons, and instances in the Service Container?
I'm implementing a simple PHP service container for my personal website blog and want to make sure I'm setting it up correctly. My container has three types of service registration methods:
singleton(...
0
votes
0
answers
68
views
Nest JS dependency injection
I'm trying to fully understand how modules DI works and I'm struggling with one thing.
I have sample app:
-- API MODULE
all controllers here
-- USER MODULE
APPLICATION MODULE
DOMAIN MODULE
...
3
votes
2
answers
158
views
How can I tell if a Spring ApplicationContext has been refreshed without using an event listener?
I have an instance of a Spring ApplicationContext in a method and I need to "probe" it and decide if:
it has been fully refresh()ed at least once so I can be sure that the beanFactory is ...
0
votes
1
answer
153
views
Using MassTransit IScopedClientFactory or IClientFactory inside singleton service
All my request clients are added, as this works (not only the generation of the client, but the client itself - the request is sent using rabbitmq and I get the response as expected):
using var scope =...
2
votes
1
answer
131
views
AutoFac DependencyResolutionException when using hybrid cache with redis
I run into a runtime error when using autofac in combination with hybrid cache and redis. I hope someone can explain why this error occurs.
When using autofac to resolve an instance of HybridCache in ...
3
votes
1
answer
63
views
Call CreateUserComand handler in Filter
I'm trying to call the handle to return values from the application layer. I'm using the mediator pattern. I've tried calling it, but haven't been able to due to lack of experience.
The endpoint:
...
-3
votes
1
answer
88
views
.Net Core 9 DI for dynamic instance creation and its required services [closed]
I have the following 2 classes. MyClass composes MyOtherClasses. Each of them requires different ILogger<foo>:
public class MyClass
{
private readonly ILogger<MyClass> _logger;
...
1
vote
1
answer
148
views
How to test .NET Core Console application which uses Dependency Injection using xUnit?
I have a console app constructed using the following code:
public partial class Program
{
private static async Task<int> Main(string[] args)
{
Host.CreateDefaultBuilder(args)
...
1
vote
1
answer
59
views
AutoFac: How to select a service required by consumer with an intermediate handler class (consumer>handler>IService
I have a class Handler with interface IHandler that depends on IService, which in turn has two implementations ServiceA and ServiceB. Then I have a class Consumer which depends on Handler and knows at ...
1
vote
2
answers
112
views
Share a child component service with parent component in Angular
I am building a component library with Angular 19.
I created a component MyComponent that uses a service MyInternalService to store some data and interact with them. MyComponent needs an instance of ...
0
votes
3
answers
208
views
Resolving a circular/recursive dependency with dependency injection
Say I have this interface:
public interface IExample
{
string GetSupportedExtension();
void DoWork(Stream input);
}
a concrete implementation like:
public class PdfExample : IExample
{
...
2
votes
1
answer
148
views
How can I load a map of objects from YAML using Micronaut's ConfigurationProperties?
I'm using the Micronaut framework, and using ConfigurationProperties to load application config into an injectable bean. This has worked well so far, but I'm now stuck on loading nested objects into a ...
2
votes
1
answer
205
views
Set up Koin in modularized Android project for Compose previews
I'm setting up an Android project, where I've separated the code into different modules to have a bit of a cleaner structure. The modules are presentation, domain, data, di and app. I am including a ...
0
votes
1
answer
94
views
Microsoft Feature Management custom provider DI error in VS Code
I have the following code in my Program.cs to implement my custom feature provider:
builder.Services.AddScoped<IFeatureDefinitionProvider, DatabaseFeatureProvider().AddFeatureManagement()....
1
vote
0
answers
86
views
Resolving ServiceProvider DI Container and Prism Dialog registration
I currently have a ServiceProvider that registers certain types from the current assembly within one container. I am trying to implement a separate prism dialogservice that would register only ...
-1
votes
4
answers
182
views
How can I automatically inject common services into all command/query handlers without manually modifying each constructor?
I'm working on a .NET application where every command/query handler needs access to three shared services: IValidator, ISecurity and ILogger. Rather than manually injecting these into each handler ...
1
vote
2
answers
126
views
ASP.NET Core dependency inject (Generic) error
I want to create a repository base class, every service should inherit from this BaseService.
This is my code:
public class BaseService<TEntity, TAddDto, TUpdateDto, TEntityDto> : IBaseService&...
1
vote
0
answers
110
views
ASP.NET Core background/singleton service — how should I access DbContext safely? [duplicate]
I have an ASP.NET Core 8 app with a long-lived service that refreshes an in-memory cache on a timer. I registered the service as a singleton (it’s a hosted background worker), and it needs to query ...
1
vote
1
answer
135
views
Polymorphic deserialize JSON using DI container to create instances
Consider these model classes:
[JsonPolymorphic(TypeDiscriminatorPropertyName = "$type")]
[JsonDerivedType(typeof(A), typeDiscriminator: nameof(A))]
[JsonDerivedType(typeof(B), ...
0
votes
2
answers
118
views
How to inject a reference to a specific IHostedService into another (dependant) IHostedService?
I have a .NET 4.7.2 console application that uses .NET Generic Host and has 2 background services. One of them (dependent) should start its work only after another one (base) has completed its ...
0
votes
0
answers
98
views
Cannot use Connection.transaction() in a manually started transaction
The code is used in many projects and works but in one service sometimes an error occurs:
"InterfaceError: (sqlalchemy.dialects.postgresql.asyncpg.InterfaceError) <class 'asyncpg.exceptions....
1
vote
1
answer
278
views
In C#, how to inject dependent service with named options based on consumer service and param?
C# and .NET 8, using .NET DI framework and IOptions.
I have an option class:
public class MyOptions
{
public string Name { get; set; }
}
Then I have a service class that needs an instance of ...
0
votes
0
answers
64
views
Autofac: ObjectDisposedException when resolving dependencies from factory delegate in ASP.NET Web API
I have an ASP.NET Web API project using Autofac for dependency injection.
I register a factory for creating ICommandExecutor based on an enum:
builder.Register<Func<CommandType, ICommandExecutor&...