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,289
questions
0votes
1answer
36views
@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 ...
0votes
1answer
16views
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 ...
0votes
1answer
15views
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, ...
0votes
0answers
35views
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 ...
0votes
0answers
8views
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: ...
0votes
0answers
24views
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 ...
-1votes
1answer
36views
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 ...
2votes
1answer
18views
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 ...
0votes
0answers
18views
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 ...
2votes
1answer
23views
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("...
0votes
0answers
67views
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() ...
-1votes
1answer
24views
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?
0votes
2answers
37views
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 ...
2votes
1answer
70views
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 ...
0votes
0answers
112views
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/...
1vote
1answer
50views
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....
1vote
1answer
14views
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 ...
1vote
1answer
40views
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 ...
0votes
0answers
37views
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 ...
0votes
1answer
55views
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;
...
0votes
0answers
39views
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 ...
0votes
1answer
35views
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 ...
1vote
0answers
30views
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 ...
0votes
1answer
27views
BeanFactory and the ApplicationContext
I have this class:
@Service
public class SecurityManagerService implements ISecurityManagerService {
private final UserRepository userRepository;
private final RoleRepository roleRepository;
...
0votes
2answers
90views
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?
2votes
1answer
35views
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 (...
0votes
0answers
410views
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
...
0votes
0answers
12views
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, ...
1vote
1answer
110views
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 ...
0votes
0answers
134views
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 ...
0votes
1answer
43views
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 ...
1vote
2answers
81views
.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 ...
0votes
1answer
29views
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 ...
0votes
1answer
284views
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=&...
0votes
2answers
93views
How to implement Inversion of Control using Pure DI on a Console Application? (Without using IoC containers)
I have an example application where I would like to use the concepts of Inversion of Control to inject dependencies into lower level classes. My example application is a gummy bear factory. The gummy ...
1vote
1answer
383views
Circular component dependency detected while activating Autofac .NET Core Web API
I have a problem with IAfterSaleService interface and AfterSaleService Class and I used autofac IoC for these cs files. However while constructor injection ı made is working for some interface, ...
0votes
0answers
33views
Re-inject values
Is it possible to manually re-inject value to already created instance?
For example I use objects from pool and would like to inject new values when taking object from pool instead of creating new ...
0votes
1answer
93views
Inject different loggers for controllers in ASP.NET MVC
I have defined services in Startup.cs
public void ConfigureServices(IServiceCollection services)
{
string connectionString = Configuration.GetConnectionString("DbConnection");
...
-2votes
1answer
29views
can anyone please tell me what is the difference between Inversion of Control (IOC) and Dependency Injection (DI) in spring?
I'am seriously figuring out this for the last one week and continuously keep on reading articles and blogs so that I can understand the difference in the very leman language and terms so that I can ...
1vote
1answer
51views
Does Inversion of Control lead to Side Effects?
A question I've been struggling a lot with lately is how, in my opinion, Inversion of Control
breaks Encapsulation and can easily lead to side effects in a program. However, at the same time, some of ...
2votes
2answers
320views
NestJS: UseGuards Doesn't Use Dependency Injection - Can't Override Guard
Current behavior
The documentation states here that:
...we passed the RolesGuard type (instead of an instance), leaving responsibility for instantiation to the framework and enabling dependency ...
1vote
0answers
91views
Hangfire Register IoC Dependency in Scope For Job at Run Time
Issue: most jobs are dependent on configuration dependency.
Ideal Solution: (copied here and at end just to save reading if you already know exactly how to do this)
I would like to
during job Q (...
1vote
2answers
117views
How to keep duplicate spring bean in container. [ConflictingBeanDefinitionException]
I am working on an application which uses some third java libraries which are build on top of core spring framework.
Now when my application uses these libraries I am getting ...
0votes
0answers
132views
Caliburn micro and xamarin forms
I am new in xamarin but have used Calibrun Micro on wpf.
I playing with an application that builds by VS 2022
I installed nuget packages for Caliburn.micro.core and caliburn.micro.xamarin.form to all ...
0votes
1answer
83views
Refresh Spring Resource from Google Cloud Storage in Runtime
I have a file in Google Cloud Storage that is used as a resource in my Spring server. I found that there is a GCS SDK for Spring here. However, it only supports fetching resources once when the ...
0votes
0answers
26views
Autofac - WPF tabbed app - Multiple single instances of the same service
I've been searching and thinking about how IoC (using Autofac) should be implemented correctly when it comes to multi document (tabbed) application where each document should have its own single ...
0votes
0answers
67views
How to use a DI Container within a legacy class to create an instance of a new class
There is a legacy class in a huge Winforms solution which I cannot change the constructor (because there are lots of references to it).
However, I need to call a new class method within one of the ...
1vote
3answers
516views
Spring Boot and constructor injection
I'm building a new Springboot application, and I'm a bit confused about constructor injection for properties. I'm reading values from a yaml file. And the yaml looks like this:
app:
name: ...
0votes
1answer
34views
DI Question, is this considered loosely coupled?
I am using a factory class here to inject DataAccess and Logging to my BusinessLogic, is this considered loosely coupled?
I am trying to follow the DIP (Dependency inversion principle), and IoC (...
0votes
1answer
103views
Null Pointer Exception in @Autowired Annotation
I know there are still a lot of sources that have already answered this question. But still, there are some resolved issue and getting NULL Pointer Exception
Application.java File
package com.shubham....