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,300
questions
0
votes
0
answers
28
views
How to inject dependencies of the same interface in some order? [duplicate]
interface I1{}
class Imp1: I1{}
class Imp2: I1{}
class User{
I1 var1;
I1 var2;
User(I1 v1, I1 v2){
var1 = v1;
var2 = v2;
}
}
So we have something like this, User has ...
0
votes
1
answer
25
views
How to get all beans of specified interface which also implements other interfaces
Here I have 3 Interfaces: InterfaceA and InterfaceB and SharedInterface
public interface InterfaceA {
/**
* print some message
*/
void printMsg();
}
public interface InterfaceB {
...
0
votes
2
answers
26
views
How can I tell if IRegistrationBuilder.EnableInterfaceInterceptors() has already been called?
I'm using Autofac.Extras.DynamicProxy to write a couple of IInterceptors. They can be used individually, or both together. I want consumers of these interceptors to be able to attach them to Autofac ...
0
votes
1
answer
21
views
Object gotten from the NestFactory has all the internal dependencies as undefined - NestJS
I get an object from NestFactory and then I call a function. There is another class injected inside service class. All the dependencies inside the service are not accessible.
const FASTIFY = new ...
0
votes
1
answer
29
views
Swift, iOS: How to get Polymorphic and Decouple Coordinator from concrete type
I have these protocols:
protocol Coordinator {
var rootViewController: UIViewController { get set }
func start()
}
protocol UIViewControllerFactory {
func mainViewController() -> ...
0
votes
0
answers
40
views
Is it best practice to nest IoC registrations and could this be causing issues with my EF woes?
I have been tasked with finding out why we get an intermittent error in a WPF application that uses AutoFac to register an instance of an EF context. That EF context is registered as a Singleton which ...
0
votes
1
answer
62
views
Micronaut - Create a bean without creating ApplicationContext
I have a Micronaut declarative HTTP client written using @client annotation. I want to call this while starting micronaut app before creating the ApplicationContext itslef.
HttpClient : ...
-2
votes
0
answers
44
views
Calling Class methods from a hash in Ruby
I want to implement the Publisher/Subscriber programming style for a simple term frequency counter code.
The problem: I intend to use the publish(event) method to execute all the "subscribed"...
0
votes
1
answer
50
views
Why does spring use ioc and di?
I'm new to spring 5 and my question is why does spring use DI and IOC? I mean why do we have to write the beans in an XML (legacy) and then create it where we need it? Why don't we use one method ...
0
votes
0
answers
19
views
IShouldInitialize interface equivalent in ABP Framework
I search for an equivalent of the IShouldInitialize interface in ABP.IO framework.
In ASP.NET Boilerplate, the interface marked the framework to run an Initialize method: https://aspnetboilerplate.com/...
0
votes
0
answers
60
views
ExpressJS inject async dependency (WWEBJS) once and start listening to http requests
Hello I have an express node backend with WWEBJS (multidevice auth) that upon initialization (via localauth) will start an instance that is readily available to start sending messages, after the ...
0
votes
2
answers
44
views
Register IStartupFilter with TryAddSingleton equivalent in ASP.NET Core
My class library registers an IStartupFilter (using a factory) with the ASP.NET Core container:
services.AddSingleton<IStartupFilter>(serviceProvider =>
ActivatorUtilities.CreateInstance&...
0
votes
0
answers
37
views
Correctly registering services in Xamarin.Forms app with Prism
I am building a Xamarin.Forms application and have decided on using the Prism MVVM framework with Unity as the IoC. It is my first time using Prism, I have been using MVVMLight for my previous app. I ...
1
vote
4
answers
132
views
dependency injection not working in data class "an object reference is required" error
I have a c# DotNet6 project where I need to get my connection string from within my data classes, and usually did this via a global variable. I need to do this via dependency injection instead, and ...
3
votes
2
answers
216
views
Injecting dependencies into dynamically loaded .dll (.net core)
Similar to How to Inject Dependencies to Dynamically Loaded Assemblies, I want to inject dependencies into classes from dynamically loaded assemblies. Is this possible with the .NET 6.0 DI Container? ...
2
votes
2
answers
110
views
How to replace a registered service with a new one in MVVM?
Trying to migrate from good old MVVM Light to Windows Community Toolkit. How are we supposed to override a registered service, i.e. replace it with another implementation at runtime?
Example
I have ...
0
votes
1
answer
40
views
@Autowired ApplicationContext vs passing an ApplicationContext object to the method
I have a MyRunnalbe implements Runnable and will be excuted by ThreadPoolTaskExecutor.
Inside this MyRunnalbe class, the run() method will call multiple applicationContext.getBean(MyBean.class) to get ...
0
votes
1
answer
19
views
Is there any way to retrieve a object in a test from a Provide in Guice?
I'm trying to get a Object in a JUnit test from a @Provides in a module which isn't @Injected therefore I cannot get it by the injector.
Is there any way that I can call the method without injecting ...
0
votes
1
answer
24
views
Register lambda as factory (with dependencies)
I'm trying to migrate from Grace IOC container to Autofac.
In Grace, I could do this kind of registration (original source):
block.ExportFactory<SimpleObjectA, SimpleObjectB, SimpleObjectC, ...
0
votes
0
answers
55
views
How to use constructor dependency injection using unity in the test class
I am using Unity container to achieve the constructor DI in the console application. The dependency registration is done in the Main method of a program class.
All works fine but i am not able to ...
0
votes
0
answers
9
views
Is Javascript's Array.sort an example of Inversion of Control?
In Javascript's sort method of an Array, I can pass a customized sorting function. Example:
const data = [ { name: "Tom", age: 10 },
{ name: "Dick", age: 9 },
{ name: ...
0
votes
0
answers
27
views
Spring boot, @Autowired
i'm new in spring There's something I don't understand
Spring automatically register the class that implement interface,
So we can code like below
@Service
public class MyServiceImpl implements ...
-1
votes
1
answer
58
views
Where exactly are spring beans used? Looking for help understanding spring beans in depth
I'm using spring MVC and was hoping to understand the concept a bit better. I have been through some videos, samples and the spring Beans/IoC documentation but it's still not completely clear. I ...
2
votes
1
answer
21
views
Is it possible to customize DryIOC type matching to workaround embedded Interop COM assemblies type mismatch?
We are currently working on a Prism project using DryIoc as the backing container and we are running into problems with the embedding of Interop assemblies for our COM interop.
In the past, when we ...
0
votes
0
answers
28
views
IoC vs DIP differences
Is it possible to have Inversion of Control without the Dependency Inversion Principle? Some sources insist they're the same, others don't. Would like to get a conversation going around the ...
2
votes
1
answer
40
views
Passing dependencies the "right way"
When injecting dependencies into a constructor, I'm not quite sure if it breaks SOLID if I do the following:
public MyClass(IConfiguration configuration)
{
_port = configuration.GetValue("...
0
votes
0
answers
101
views
How to check if a bean is injected or not in Spring
I'm injecting a bean as below which scope is Request.
@Autowired
private Optional<User> currentUser;
But when, bean is not injected for any reason, I'm trying to check currentUser.isPresent() ...
-1
votes
1
answer
52
views
Nette framework - accessing , getting services , service classes models, components, helpers from inside presenters or latte templates
How to retrieve services in Nette from/inside presenters ( controllers ) to models, templates?
0
votes
2
answers
41
views
DLL design and the Dependency Inversion Principle
I have a somewhat basic design question that I have not been able to find a good answer to (here, on other forums nor the books I've consulted)
I'm creating a dll and is wondering what the best way to ...
2
votes
1
answer
96
views
How to configure dependency injection container with Func<T, Result>?
BusinessAction is used to represent an action that can be performed by a user. Each action is related to the specific entity, so if for example, that entity is Order, business actions could be ...
0
votes
0
answers
120
views
InversifyJS - Binding inside a factory method
I have a question about this piece of code:
This is how my factory looks like. As you can see I'm binding/unbinding some classes inside this factory method:
// application/flow-manager/...
1
vote
1
answer
62
views
Equivalent Simple Injector .Register invocations
I have an object whose constructor requires a primitive. I register it using a delegate (please excuse the contrived example).
container.Register<Account>(() => new Account(1000M), Lifestyle....
1
vote
1
answer
15
views
Force StructureMap to Plug-In a populated Instance During Runtime
During unit tests, I load-up my Unit-of-Work (UOW) instance with mock data. Then, I hand the Unit-of-Work instance to the class-instances that are being tested.
FOR EXAMPLE:
Below I am loading the ...
1
vote
1
answer
59
views
Inject a bean into a manually instantiated class in spring
I've got some domain classes that I'm using. There is a requirement for logging in them, but it doesn't look like spring will allow you to inject a bean into a manually instantiated object. I don't ...
0
votes
0
answers
41
views
how can I stream in grayscale? (Android)
when I stream from my android smartphone it doesnt capture any color manipulations like grayscale. Because the color inversion is applied too late in the rendering pipeline to be included in a ...
0
votes
1
answer
76
views
Get String text which is wrapped in a object
I want to create objects of a class which hold a specific string value. The string value will be passed through the constructor of the class, like this
public class Class_A {
private String id;
...
0
votes
0
answers
57
views
How to rectify circular dependency in IOC (Controllers) using Inversify TypeScript
PostController -> ImageController -> PostController
https://i.stack.imgur.com/Mayuq.png
How can I resolve this issue in TypeScript Inversify IOC. Please explain with suitable example (Only ...
0
votes
1
answer
37
views
Is Spring more suitable for business-logic-focused apps?
After reading the official doc of Spring, I got this impression:
"Spring, specifically its IoC container, suits better for apps that requires only one instance of most classes".
For example ...
1
vote
0
answers
33
views
Java spring resolving dependency in a generic method
I'm looking for suggestions on how to simplify some generics in Java/Spring
Let's say I have the following:
public Interface Event
{
}
public Interface EventHandler<T extends Event>
{
void ...
0
votes
1
answer
30
views
BeanFactory and the ApplicationContext
I have this class:
@Service
public class SecurityManagerService implements ISecurityManagerService {
private final UserRepository userRepository;
private final RoleRepository roleRepository;
...
0
votes
2
answers
130
views
IoC in .NET Core
What type of IoC is used for AddSingleton, AddScoped, or AddTransient in ASO.NET Core? is it Unity, Spring.Net or Ninject? Or something Built-in specially for .NET Core?
2
votes
1
answer
53
views
Scoped Unit of Work Resolution in Prism Xamarin with DryIoc
In a Prism Xamarin app with DryIoc as container, I have a Unit of Work which is referenced by several other components which are then referenced from view models. It looks something like this (...
0
votes
0
answers
611
views
Using decorators with NextJS and TypeScript
I'm trying to add dependency injection to my NextJS solution using TypeDI.
In tsconfig.js I have the following set
"experimentalDecorators": true,
"emitDecoratorMetadata": true
...
0
votes
0
answers
12
views
IOC Container in Games
I have a problem... I'm making a library of roleplaying games, and I have many "entities" (they are objects in the game created dynamically) that have their own data, like status, health, ...
1
vote
1
answer
171
views
Two implementations of one interface in Jersey/HK2, reuse first in other
I have an interface with a naive implementation, say
interface MyService {
void doIt();
}
class MyServicePlain implements MyService{
@Inject
SomeOtherInterface
public void doIt ...
0
votes
0
answers
248
views
How to use Express's RequestHandler AND inversify-express-utils's BaseMiddleware on a single controller
There are two middleware functions I'm trying to use - one is the express request handler interface (third party package - bull monitor) and the other is inversify-express-utils's BaseMiddleware (auth ...
0
votes
1
answer
43
views
Castle Windsor Resolving Mutiple Generic Implementations of 1 Inteface
Suppose I have the following:
public interface IFileHandler<TLocation,TRow> { ... }
//loads file in some location using record format defined in RowTypeA
//e.g. RowTypeA records exist in files ...
1
vote
2
answers
86
views
.NET DI with runtime implementation resolvers
I have a bit of a weird case involving DI, specifically in resolving implementation at runtime from within the same service. I'm aware that I could inject a service provider, but that would seemingly ...
0
votes
1
answer
29
views
Cam I make Identity part of the container when creating MVC controllers?
When my controller uses an object which taked identity as input, I could of course do this:
public class MyController : ControllerBase
{
private readonly MyRepository _repository;
public ...
1
vote
1
answer
353
views
Embedded Jetty upgrade issues from 6.1.7 to 9.4.43
I have used jetty.xml for configuration in older jetty version which looks something like this:
<Configure id="Server" class="org.mortbay.jetty.Server">
<Set name=&...