Questions tagged [dependency-inversion]

For questions about the Dependency Inversion Principle in object-oriented programming, one of the SOLID principles originated by Robert C. Martin. It states that modules should, "depend on abstractions, not concretions."

Filter by
Sorted by
Tagged with
1 vote
2 answers
79 views

Dependency inversion in python - why is it used? Can't see the benefit

I've been trying to understand dependency inversion in python. I understand the theory that everybody quotes but I've not yet seen the code example with and without inversion that would clearly ...
  • 11
0 votes
0 answers
33 views

Is OWIN a Dependency injection container or DI framework?

We have an ASP.NET 4.8 project and we thought to introduce Dependency injection principle. A colleague suggested to use OWIN as DI container. I tried to search for more information regarding ownin, ...
0 votes
1 answer
50 views

If condition not working as expected in java class [duplicate]

So i was making a dependecy inversion principle example and i'm getting the wrong output from the class powerSwitch which is supposed to turn the lamp or the televesion (which extend the switchable ...
  • 15
0 votes
1 answer
59 views

Data Layer call and implementing DI

I'm learning how to implement DI in a 3 layers architecture, but I'm not quite sure if what I have implemented is actually a DI or some sort of mud abomination. The code works in the sense that ...
0 votes
0 answers
37 views

How does interface change the flow of control (control flow), as in Dependency Inversion?

I am reading Clean Architecture by Robert Martin, chapter 5. It says (the quote is not 100% accurate, I changed it for brevity): In Figure above, module HL1 calls the F() function in module ML1 . The ...
  • 10.8k
0 votes
0 answers
33 views

How can I remove my if else conditions from my code and apply dynamic behavior when I add new logic?

I have the following code class Store { constructor(paymentProcessor) { this.paymentProcessor = paymentProcessor; } purchaseBike(price, quantity) { if(this....
  • 29
2 votes
1 answer
41 views

Is passing object property against Dependency Inversion Principle? Please advise

Assuming there are classes as follow. interface Book { Guid Id { get; } Guid AuthorId { get; } } interface Author { Guid Id { get; } void Autograph(); } Then there are service and data store ...
  • 604
0 votes
0 answers
240 views

Decorating Generic Command Handlers with Decorator Pattern using Scrutor

I want to decorate command handlers with decorator Pattern in an ASP.NET Core app. So I registered command handers first and then register decorators. But it doesn't work. I am using built-in IoC in ...
1 vote
0 answers
322 views

Jetpack Compose and Dependency Inversion

In Jetpack Compose, most examples look something like this: ScreenLevelContainer { TopBar { ... } ContentA { ... } ContentB { ... } // etc. } Contents of any given composable may be comprised ...
  • 17.2k
0 votes
1 answer
132 views

Dependency Inversion Principle

I'm trying to learn SOLID Principles and I am very confuse with this dependency Inversion principle. Can someone explain and see if my code below violates the mentioned principle? Sorry for the messy ...
0 votes
1 answer
206 views

Nest.js Dependency Inversion function not found

I followed the controller-service-repository architecture and I want to use dependency inversion on StoneRepository. Having the code from bellow I get: [Nest] 22656 - 03/21/2022, 5:01:44 PM ERROR [...
0 votes
1 answer
49 views

SOLID Principles, Can JDBC interface be said as an example of Dependency Inversion Principle?

Of the five SOLID Principles, Dependency Inversion is one of them and the last one. Can I quote JDBC interface as an example of Dependency Inversion Principle?
  • 399
0 votes
0 answers
80 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 ...
  • 637
0 votes
2 answers
107 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 ...
1 vote
1 answer
37 views

How to delay the adoption of a particular dependency injection framework during the early development phase?

Robert C. Martin in his book "Clean Architecture: A Craftsman's Guide to Software Structure and Design" mentions that a good architecture allows to delay decisions about details. One of ...
  • 1,964
1 vote
1 answer
167 views

Dependency Inversion with assosiatedType in protocol

I am having a hard time trying to implement Dependency Inversion. Looking around, find a fantastic article Swift Type Erasure. I am not sure how to can I get advantage in my situation. Here is what I ...
1 vote
1 answer
58 views

How to properly add dependecy of entity class to other classes and reduce coupling

I was reading the dependency inversion principle. It states that the module should be dependent on abstraction. I understand most of the parts, and I can apply them. There is one place where there is ...
  • 816
3 votes
1 answer
58 views

Dependency Inversion Principle. Why can I access classes of a non-directly referenced project in ASP.NET Core 5?

Imagine I have four projects in my solution: UI <- startup project Domain Repository Boot The UI projects has dependencies to the Domain and Boot projects. The Boot project has dependencies to ...
0 votes
1 answer
113 views

Using factory for everything?

My software shall control a device or multiple of them. The program flow is like that it will search for devices on all available interfaces and instantiate an object of the type IDevice for each ...
0 votes
1 answer
1k views

May a Repository call an UseCase in Clean Architecture?

This is a very tricky question, because when we check the rules it's not explicit that a repository couldn't call an UseCase. However, it doesn't seem logical. Is there any definition/good practices ...
1 vote
1 answer
65 views

dependency inversion for data class(classes that define the structure of certain type)

So I have this data class: public class RecentProject { public string ProjectName { get; set; } public string ProjectPath { get; set; } public DateTime CreationDate { get; set; } ...
2 votes
2 answers
176 views

How to autowire this dependency in spring at the time of PostConstruct

I have the below code inside the @PostConstruct block in a spring managed code. class A { private BoogleFeature boogle; @PostConstruct public void createBoggleClient() { ...
  • 6,515
0 votes
1 answer
116 views

Explanation of phrase 'should depend on abstractions' in Dependency Inversion (DI)

I have never quite understood the second part of the phrase... 'High-level modules should not depend on low-level modules. Both should depend on abstractions (e.g., interfaces)' If I changed... class ...
  • 29k
1 vote
1 answer
101 views

Is there a way of centralizing the access to a DataContext in C# using DI pattern?

this is what I got so far, but have to keep passing the DataClassesDataContext around. I wonder if there is a better more centralized way of using the DataClassesDataContext and fill the ...
  • 11
1 vote
2 answers
341 views

Dependency inversion design choice question

I am currently reading an otherwise excellent tutorial regarding the Dependency Inversion Principle https://www.baeldung.com/java-dependency-inversion-principle and there is something I am not able to ...
  • 2,153
1 vote
2 answers
5k views

Instantiate a class object in startup.cs in .Net Core

I am trying to pass an interface and settings into a class while creating an instance of that class in startup.cs in .Net Core Project. I am using the below code to do so. I have some code written in ...
  • 51
0 votes
2 answers
300 views

Do you inject dependencies in the constructor even if the class does not own these dependencies, but uses them in methods? [closed]

If a School class relies on an EmailSender class you might have to inject this EmailSender through it's constructor with a generic interface like IMessagable or IMessageSender or even IEmailSender so ...
3 votes
0 answers
257 views

Trying to deal with circular dependencies using dependency inversion in Python

Here's a simple diagram that illustrates the problem Description: there is a Pipeline entity that contains a Source entity, the Source is validated using the SourceValidator, and it in turn, in order ...
1 vote
1 answer
196 views

Is this still follow Dependency Inversion Principle when implement multiple interface?

sorry for the long question and also my English. I'm reading an article about DIP. I will summarize the code in here. interface CoffeeMachine() { void brewFilterCoffee(); } interface ...
  • 145
1 vote
0 answers
157 views

Best practices to implement an Interface across different project modules

I have a multi module application, consisting of an interface in module A and an implementation in module B. Module A is linked to module B using dependency inversion where module B is injected into ...
0 votes
0 answers
77 views

I am learning on how to implement Dependency Injection [DI] in C#. Is this the valid DI program as an example?

1. Main Method class Program { static void Main(string[] args) { ILogger _log = new Logger(); IDataAccess _da = new DataAccess(); ...
  • 101
4 votes
1 answer
458 views

Use type classes to implement dependency inversion in a Haskell application?

One major architectural goal when designing large applications is to reduce coupling and dependencies. By dependencies, I mean source-code dependencies, when one function or data type uses another ...
0 votes
0 answers
59 views

StackOverFlow in the implementation of the Dependency Inversion Principle for cross-refenced classes

The Situation: I have three classes: Society, Father and Son. The Society has a list of Fathers. Each Father has one son. It is necessary in this application that each Father knows who his Son is ...
2 votes
1 answer
56 views

architecture with Dependency Inversion (prior to a DI Framework)

I'm studying D.I. I've some issues with the architecture, maybe I'm missing some points. Suppose I have this non-DI code (I read a list of "Person" from file) static void Main() { ...
  • 57
4 votes
1 answer
352 views

How can I apply the dependency inversion principle when using third party libraries?

I was reading about the dependency inversion principle and as far as I understand the relation is inverted because package A (high level) defines the interface and package B (low level) implements the ...
user avatar
0 votes
1 answer
529 views

Dependency inversion issue in php. (Repository Pattern)

I am implementing a repository pattern in Laravel, and it seems to be very tedious. For example, let's say I have products then I have to create a ProductRepository interface then a ProductRepository ...
  • 1,003
0 votes
0 answers
136 views

How to create a library that uses DI inside and use in a project that doesn't use DI?

Hy guys, I need to create a library in a project, which uses DI internally, like that: Library namespace Library { public class SomeService : ISomeService { private readonly ...
0 votes
1 answer
164 views

Is the Open-Closed SOLID principle the same as Coding to an Interface?

Does open-for-extension and closed-for-modification mean code-to-an-interface? If I code to an interface so that future concrete implementations can be introduced by implementing the interface, and ...
3 votes
1 answer
57 views

A code-based registration vs a design time registration in the context of the IoC

What is the difference between the code-based registration and a design time registration in the context of the IoC? I met the concepts here while learning the IoC, DIP, DI and IoC containers.
  • 1,661
2 votes
2 answers
373 views

When is it okay to depend on concrete classes?

Today I was asked a question I could not find an answer for so here I am, asking for your help! The Dependency Inversion Principle states that both concrete classes and abstractions should depend on ...
1 vote
1 answer
385 views

Dependency Inversion with a List<T> in a method

How would one implement Dependency Inversion on a given class like the following code? Problem is the function "Add" in class A, which containts the new Keyword. I'm using Autofac for Dependency ...
0 votes
1 answer
53 views

Trying to understand Figure 14.11 of the book "Clean Architecture"

This is from chapter 14 of the book "Clean Architecture" It's trying to break the direct dependency of Stable-->Flexible by introducing UServer. So that we can have Stable-->UServer<--Flexible ...
6 votes
3 answers
4k views

SOLID Design Principles : Liskov Substitution Principle and Dependency Inversion Principle

Just a thought and a question to the Stack Overflow and Microsoft Development Community about the OO software design principles called SOLID. What is the difference between the Liskov Substitution ...
4 votes
3 answers
692 views

Does Inheritance contradict Dependency Inversion Principle

The dependency Inversion principle says that (Head First Java): Depend upon abstractions. Do not depend upon concrete classes. What does it mean with respect to inheritance? As a subclass depends on ...
  • 544
1 vote
1 answer
181 views

Does using a global constants defined by framework within class methods breaks the Dependency Injection principle?

With constants coming from the framework you are using. i.e, ABSPATH in WordPress. How badly will it break the Dependency Injection principle if I do not add the value of that constant as a ...
  • 830
0 votes
2 answers
432 views

Deriving from a concrete class?

In book 'Head First Design Patterns', one of the way mentioned to not violate 'Dependency Inversion' principle is as: No class derive from a concrete class. Is it possible to follow this rule ...
  • 5,739
1 vote
0 answers
83 views

Why are inversion of control and the dependency inversion principle not design patterns, while dependency injection is?

Why is dependency injection a design pattern, while inversion of control and the dependency inversion principle are both not? They seem to me design patterns, despite their differences.
  • 1
0 votes
1 answer
41 views

crash while try store value using dependency inversion

I want to implemented dependency inversion In app delegate in my app as my rootController is my UITabBarController but when I want to try it there is an error Fatal error: Unexpectedly found nil ...
0 votes
1 answer
231 views

Dependency Inversion in swift

Hi I have a question for developer in here, I was reading an iOS programming book from big nerd ranch. I was interested how to structure and technique to create an app. and I was trying to implement ...
58 votes
4 answers
31k views

The non-generic method 'IServiceProvider.GetService(Type)' cannot be used with type arguments

I am using .NET Core dependency injection, but when I am trying to get the service in another class, I am getting the 'IServiceProvider.GetService(Type)' cannot be used with type arguments' error. ...
  • 783