Questions tagged [inversion-of-control]
Inversion of control (IoC) is an abstract principle describing an aspect of some software architecture designs in which the flow of control of a system is inverted in comparison to procedural programming.
4,379
questions
0
votes
1
answer
41
views
SpringApplication.run() without boot
I'm a total beginner with Spring. I'm currently trying to just run a very simple project just to start learning about Spring and understanding IoC and dependency injection. At first I created a simple ...
0
votes
0
answers
8
views
What exactly is the difference between dependency pull and contextualised dependency lookup?
I don't understand the exact difference between the dependency pull and contextualised dependency lookup.
From what I understand, dependency pull involves gathering dependencies from a registry ( ...
1
vote
2
answers
42
views
when should i use a custom configuration class in spring boot?
I am learning spring at the moment and cant figure out why and when we need to the use the custom @Configuration class and @Bean inside it as spring does everything automatically
@Configuration and @...
0
votes
1
answer
41
views
Unable to inject List property, it throws a ConversionNotSupportedException
I have two beans like this:
<alias name="defaultProblematicBean" alias="problematicBean" />
<bean id="defaultProblematicBean"
class="com.application....
0
votes
0
answers
63
views
Zenject Unity3D - Injecting Dependencies from GameObject Hierarchy
I'm working on a Unity3D project using Zenject for dependency injection. In my project, i have a UpgradeCardButton component which is injected with a ButtonUpgradeCommand object.
ButtonUpgradeCommand ...
0
votes
1
answer
113
views
.NET Core 5 - Registering a class as singleton with strings in its constructor
I have a .NET 5 web application, in which I am attempting to register a particular class as a singleton instance.
I know that .NET 5 is out of support now, and there are plans to upgrade this app in ...
0
votes
0
answers
18
views
Can Spring Application have multiple IOC containers and multiple DispatcherServlets?
I was going through some core Spring Concepts and came across DispatcherServlet and IOC Container/ApplicationContext.
Is it possible to have multiple IOC containers in the same Spring Boot application?...
0
votes
1
answer
42
views
Is there a way to have a single instance of a service per an instance of another service without Owned<T>?
I'm writing a desktop application in C# and using Autofac for DI.
In my app I want to have a big service that depends on several smaller services that depend on each other. There should be only one ...
0
votes
1
answer
33
views
What's the difference between Autowire and Resouce annotations in Spring? Why I cannot substitute Resouce with Autowire?
I am trying to use Redis in Spring project. And I copied some code like this and it works well:
@Autowired
private RedisTemplate redisTemplate;
@Resource(name = "redisTemplate")
...
0
votes
0
answers
5
views
Explanation of the principle of inverted dependency for spring ioc containers
I am a newcomer and have just started using experience Q&A recently. I have some doubts about some questions and hope everyone can help and support me. I hope it is rich and meaningful, dear gods. ...
1
vote
0
answers
88
views
Dynamic injection based on request parameter/ header in controller using InversifyJS
I am exploring InversifyJS in TypeScript and I want to understand if InversifyJS will work for my use case.
I have a TypeScript project with serverless lambda, Koa. I want to integrate InversifyJS and ...
0
votes
1
answer
16
views
Prevent NonUniqueBeanException in Micronaut, even with using @Named annotation
Why does this code yield a io.micronaut.context.exceptions.NonUniqueBeanException?
public abstract class ObjectifyRepository<T> {
}
@Singleton
@Named("repositoryA")
public class ...
0
votes
0
answers
81
views
Binding Mapsui Map to Xaml and with MVVM and service architecture
Goal:
I try to display a map from Mapsui with MVVM and a service.
And CommunityToolkit.Mvvm is installed and can be used for the ViewModel.
My error:
Exception thrown: 'System.InvalidCastException' in ...
0
votes
0
answers
24
views
Resolve a service using Autofac
Im quite lost here guys, there's this plugin for a gameserver (https://github.com/EvolutionPlugins/Dummy/blob/openmod/Dummy/Services/DummyProvider.cs) which i need to access all the tasks from the ...
0
votes
3
answers
281
views
What should application layer return? entity or dto?
In clean architecture, I implement restful api as an infrastructure,
the question is: what should the application layer return
1 - entity: this is what chatgpt answer, it say the application layer ...
1
vote
1
answer
51
views
Autofac RegisterInstance does not work as expected
In my ASP.NET Core application there is a IMemoryCache registration as an instance in startup. When IMemoryCache is injected into a controller, the controller receives a different instance of memory ...
0
votes
1
answer
108
views
Odd dependency injection behavior with Views & ViewModels using Template Studio for WinUI
Using Template Studio for WinUI, I created an app with 2 pages, Main and Foo. If the view model is passed into the page's constructor the application generates an exception, but if the view model is ...
0
votes
1
answer
626
views
How to add IUserDialogs to Maui IOC Add Singleton for Acr.UserDialogs
I'm converting app to Maui. Old IOS through TinyIOC/FreshMvvm was
FreshMvvm.FreshIOC.Container.Register<IUserDialogs>(UserDialogs.Instance);
so how should that look in MauiProgram.cs using ...
0
votes
1
answer
133
views
IConfiguration DI chicken-and-egg question
I have an ASP.NET Core 7 MVC app written in C#. I want to build a custom IConfiguration to add to the providers already registered.
I would like to use some services registered in the DI service ...
0
votes
0
answers
13
views
How to initialize and inject dependency like RpcClient?
I'm initializing an RPCClient in the Inversify container:
container.ts:
....
container.bind<IRPCClient>(TYPES.RPCClient).to(RPCClient);
....
In main.ts I'm initializing this RPCClient:
...
...
1
vote
0
answers
20
views
Difficulty using DryIOC in Web form
I want use DryIoc container in web form,
I use sample code : https://github.com/dadhi/DryIoc/blob/master/docs/DryIoc.Docs/ReuseAndScopes.md#reuse-and-scopes
But every time I ask, I get a new instance ...
2
votes
2
answers
1k
views
Spring Boot error with a repository/entity, "not a managed type"
I know that similar questions have been asked before on this forum, but none of the proposed solutions helped me, so I am writing a separate question. The code is from the spring boot course on ...
1
vote
1
answer
32
views
Can I use a static accessor as my DI approach?
This question is more philosophical.
I'm using DI and there are three ways to do it:
Constructor injection
Method injection
Property injection
Yet all of them incur a huge amount of boilerplate code....
0
votes
1
answer
30
views
Exception 'No service for type 'TestPlugins.Plugin1.Service1' has been registered.' after dynamic assembly loading in .NET7
I have a plugin based solution using C# on .NET 7, using dynamic assembly loading.
Actually, the IoC container says that the service has not been registered, but in fact it has!
Exception 'No ...
0
votes
1
answer
236
views
Testing the Container/ContainerModule in InversifyJs
I'm wondering if anyone has any guidance on how to test that IoC wiring is as intended. For my use case, I'm using InversifyJS with Typescript, and Jest for testing.
I have used Inversify ...
1
vote
1
answer
102
views
How to split code when using inversify js?
@injectable()
class Ninja implements Warrior {
@inject(TYPES.Weapon) private _katana: Weapon;
@inject(TYPES.ThrowableWeapon) private _shuriken: ThrowableWeapon;
public fight() { return ...
0
votes
1
answer
99
views
.NET 6 IoC register services from another assembly
I'd like to register some services from another assembly with built-in IoC of .NET 6. Is it possible as Autofac does?
I found others nuget extensions, still not sure what it is the best practice
...
0
votes
1
answer
73
views
Receiving NullReferenceException on using container.Resolve<IWebDriver>(); Object reference not set to an instance of an object
I am receiving NullReferenceException on CleanUp() method. The below code is from SpecflowHooks.cs
Driver code in SpecflowHooks
public static ChromeDriver driver { get; set; }
[BeforeFeature]
...
0
votes
2
answers
72
views
How to set property in main view to present the actual view in WPF
I have a simple login view with username and password and an other where I would like to access if the two is valid in the database. The problem is the main navigation is going on in the MainWindow....
1
vote
1
answer
112
views
How can I inject named delegate function into a factory to resolve dependency in .NET 7
I am working on a .NET 7 c# solution.
I have a class library that defines my base interface. For example.
public interface IFoo<T1, T2>
where T1 : Contract1 where T2 : Contract2
{
...
0
votes
1
answer
92
views
Quartz.NET scheduling issues in Autofac container
I have an Autofac container that I wish to add a lifetime Quartz.NET scheduler to using Autofac.Extras.Quartz. With the code as is below, a Quartz scheduler is instantiated with the set properties, ...
0
votes
0
answers
67
views
Microsoft.Dependency.Injection similar to Lamar For and Use function
I would like to ask about Microsoft.Extensions.DependencyInjection library for IoC implementation. Is there a way to do a similar function for the Lamar library function like services.For<TService&...
0
votes
1
answer
230
views
How to avoid memory leaks with Autofac?
I'm trying to better understand IoC/DI, in particular the concept of scopes.
I'm using a sample WPF app (repo here) from a Pluralsight course (great service, BTW) and modifying it slightly. Naturally, ...
0
votes
1
answer
278
views
Angular Dependency Injection: Inheritance and Services
Suppose I have the following setup:
export const REPOSITORY_NAME = new InjectionToken<string>('RepositoryName');
export const BASE_ENTITY_NAME = new InjectionToken<string>('BaseEntityName')...
0
votes
2
answers
68
views
Autowiring a Long in my @Service class's constructor
Very new to Spring. I want to create a service class that represents a car dealership. Among others, car dealerships have revenue. For that reason, I have a long field called totalRevenue that I'd ...
0
votes
0
answers
36
views
Lamar Dependencies on RunTime
I am using creating a library that enables developer to add services at runtime. I am not sure if I'm doing this right but below is my code that I made for this:
Test Class
public class Test : ITest
{...
0
votes
0
answers
107
views
Lamar Service Cannot Build Registered Instance
Lamar failed to create instance when trying execute my Service. I'm not sure if I've done it right it should create an instance because I add it in the registry and it fails when trying to execute ...
0
votes
1
answer
118
views
Instantiate class with automatically using dependency types added in Startup.cs
Example code:
public class A
{
public DoWork()
{
//how to Instantiate an object of class B with automatically using dependency service types added in Startup.cs and IServiceCollection?
var b = ...
-1
votes
1
answer
195
views
C# how to assign a type to a generic type in AddScoped using interface? [duplicate]
I'm wanting to do a generic scoped.
I have a class where it needs to receive a "T" type to instantiate it. My problem is receiving this type "T" otherwise without being explicit.
...
0
votes
0
answers
24
views
Memory alias between inherited and super classes in Python
I build an inherited class (Folder) which creates an instance of itself. The problem is: the new instance which it creates copies the super class memory. I don't want this to enable recursive folder ...
0
votes
1
answer
111
views
Can't move a node from one state tree to another - Spring Error
I made a simple Vaadin Web Programm implementing the Spring Framework.
When i refresh the page i keep getting the Error:
java.lang.IllegalStateException: Can't move a node from one state tree to ...
0
votes
0
answers
22
views
Injecting abstract types?
Im trying to wrap my head around TSyringe, having used other IOC's such as Autofac in C# environments, but I must be missing something.
The intend is to register abstract types, to be injected in &...
1
vote
1
answer
932
views
Spring: Could not resolve placeholder 'properties.string' in value '${properties.string}'
I'm getting an error when trying to run a Spring application where I am trying to inject dependencies from an application.properties file. Thus, Spring cannot create the bean.
This is the bean that ...
1
vote
1
answer
122
views
Autofac - How to access IRegistrationBuilder from IResolvePipelineBuilder & ResolveRequestContext?
I would like to extend my service registration [e.g. EnableInterfaceInterceptors] from Autofac Pipeline. However, I couldn't find a way to achieve that. Is there any entrypoint for me to access the ...
0
votes
0
answers
34
views
Log4net get correct class and method name in logfile using Ninject
I'm converting an application to use Ninject as IoC and one of the things I need to convert is the existing Log4net implementation. The problem that I'm facing is that in the logfile (I use the ...
1
vote
1
answer
120
views
How to use Kangaru C++ auto-wiring
Following my previous question, I would like to achieve the following with minimum boilerplate code.
I understand that Kangaru has autowiring feature to reduce code.
Here the original working version ...
1
vote
1
answer
138
views
How to use C++ Kangaru IOC library
I'm trying to do some basic stuff with the kgr library but to be frank it is not so intuitive.
As you will see I have 2 interfaces and 2 concrete classes. The B concrete class should receive by ...
0
votes
2
answers
2k
views
it's possible to do dependency injection in Fastapi using abstract class?
I'm coming from asp.net core and I use DependencyInjection to implement inversion of control in my applications. I would like to know if there is any way to provide fastapi with a list of ...
0
votes
1
answer
410
views
How to use VContainer to inject dependencies across assembly definitions
I've set my project up so that my games presentation and simulation code are in separate assemblies, and would like to use VContainer to inject dependencies across them when needed (the presentation ...
0
votes
0
answers
69
views
Django - Unable to write an interconected service layer
For several days I've been trying to implement a service layer in Django, to separate business logic from models and views. The way I do it is the following (as a example):
from api.services....