27,066 questions
-1
votes
0
answers
27
views
Angular 20 w Story 10 mocking a navigation click
I have an Angular 20 app, running Storybook 10. My component works perfectly, however, I'm trying to set up Storybook to mock a navigation link. I just can't seem to get it to work.
This is my ...
Best practices
0
votes
0
replies
60
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<...
0
votes
0
answers
62
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
37
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 ...
-3
votes
0
answers
29
views
MediatR Nuget package versions creating problems
I am getting a version mismatch error when using MediatR in my .NET project.
What happened:
Yesterday my project worked correctly with no errors.
Today I updated some NuGet packages by mistake.
After ...
Best practices
0
votes
3
replies
59
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
23
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
86
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
106
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
100
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
59
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
114
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
129
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
79
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
57
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
80
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
100
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
54
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
83
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
148
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
0
answers
69
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
128
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
63
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
75
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 ...
-2
votes
4
answers
146
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
119
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
61
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
111
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
98
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
1
answer
75
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
130
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
57
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&...
1
vote
1
answer
120
views
Python injector doesn't work for NewType based on tuple[str, str]
I'm trying to use injector to inject a tuple[str, str], but it doesn't work.
import injector
from typing import NewType
Foo = NewType("Foo", tuple[str, str])
class MyModule(injector.Module):...
0
votes
1
answer
96
views
Registration of Views and ViewModels with a parametered constructor in MAUI
I have the following code in a basic .NET MAUI app.
My main page:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/...
2
votes
2
answers
118
views
How to call var scope = ScopeFactory.CreateScope(); and still have one depency resolved from rootProvider
I have situation like this: I have two Blazor components, both using dbContext and I get popular error
A second operation was started on this context instance before a previous operation completed. ...
4
votes
2
answers
138
views
How to override inject() dependency from abstract base class in Angular?
I have an abstract base class that used to accept a service via constructor injection:
export abstract class BaseEditEventClass<T> extends BaseFormClass {
constructor(protected _service: ...
0
votes
1
answer
68
views
Instances cannot be resolved LifetimeScope has already been disposed" when resolving controller
I’m using Autofac with ASP.NET Web API, and I have multiple filters registered with Autofac’s .AsWebApiAuthorizationFilterFor<>() API.
What’s happening:
These filters are InstancePerRequest.
...
1
vote
0
answers
67
views
InjectionException on application shutdown
I have a label provider for my model tree view:
public class ModelTreeLabelProvider implements ILabelProvider {
@Inject
IWorkbench workbench;
@Override
public Image getImage(Object ...
0
votes
0
answers
65
views
How to initialize Android OkHttp cache interceptor config at app start without blocking the main thread (Hilt + Coroutines)?
I have a CacheCreation class that prepares config for an OkHttp interceptor. It’s created during DI on app launch, and we currently use runBlocking so the object graph is ready before the first ...
1
vote
0
answers
74
views
MongoRepository bean not found when repository is in external JAR dependency
My microservice uses an external dependency which is a JAR build by my company.
I can't figure why the bean is not found.
***************************
APPLICATION FAILED TO START
***********************...
1
vote
1
answer
55
views
No actual value was found for the argument "Application" when using dependency injection in Eclipse plugin
My Application class currently works as both the main application class and osgi bundle activator:
@Singleton
public class Application implements IApplication, BundleActivator {
public static ...
0
votes
1
answer
100
views
Generic mongoose dynamic module cannot inject options
I wanna have a dynamic module which should take care of registering mongoose for me. Right now I have a problem with injecting the options asynchronously when I am invoking MongooseModule.forRootAsync(...
4
votes
0
answers
61
views
Unsatisfied dependency for synthetic bean at runtime
I’m a contributor of the OpenSource project VanillaBP which is providing hexagonal architecture to business processing applications using process engines.
In the past VanillaBP was only available to ...
0
votes
0
answers
50
views
How to delay initialization of SQL-based configuration in ASP.NET Core startup without using BuildServiceProvider?
I am using an ASP.NET Core 9.0 Web API with C#. My application setup uses L1 Cache using FusionAPI and L2 is Garnet Server for distributed layer of cache. The following code snippet is from my Startup....
-1
votes
1
answer
139
views
How can I refactor a widely-used C# class to support constructor dependency injection without breaking existing usages? [closed]
In my C# ASP.NET Core project, I have a class that is currently instantiated using a parameterless constructor. This class is used in hundreds of places throughout the solution.
I now need to refactor ...
-1
votes
3
answers
106
views
What is the difference between these two methods of returning new instance value?
The first method is the normal code execution.
The second method is the one that is commented out.
Isn't returning an instance of a class from a newly created standalone service provider the same as ...
0
votes
0
answers
131
views
Why does IKeyedServiceProvider require manual registration in .NET 9 DI container?
I'm working with keyed services in .NET 9 and trying to inject IKeyedServiceProvider directly into my constructors, but
I'm getting a DI container error unless I manually register it. According to the ...
1
vote
1
answer
149
views
.Net 8 dependency injection using reflection: service with generic method returning Task<>
I want to load all types from an assembly and register them for dependency injection, using the following reflection-heavy method:
using System.Reflection;
namespace Server
{
public static class ...
1
vote
2
answers
245
views
WinUI 3 Class Library Dependency Injection
I'm using .NET 9, WinUI 3, CommTk.mvvm, Microsoft DI.
I have 3 projects in the solution:
WinUI 3 (the interface)
WinUI 3 class library (user controls to be used in multiple WinUI 3 projects)
C# class ...
1
vote
1
answer
59
views
GetRequiredKeyService Failing for Unbound Generic
I'm looking at a way to resolve dependencies using keyed services.
I have a very simple interface (for now):
public interface ITest<T>
{
T Get(string key);
}
With two very simple ...