Questions tagged [dependency-inversion]

Dependency inversion refers to a specific form of decoupling software modules. The principle is that high level modules and low level modules should depend on abstractions, and abstractions shall not depend on implementation details. Not to be confused with dependency injection which is a special form of dependency inversion.

Filter by
Sorted by
Tagged with
-2 votes
3 answers
108 views

Should I do dependency inversion on the same layer level

I'm working on an accounting service. I have to generate invoice for a user and upload it to the file storage. So my service would have to use a service from file storage team. File storage service ...
user avatar
  • 123
3 votes
0 answers
69 views

How to structure python modules/packages according to dependecy inversion

If I am working on a project, say it has this file structure: car/ body/ __init__.py doors.py bonnet.py engine/ cyclinderhead/ __init__.py pistons.py ...
user avatar
0 votes
2 answers
62 views

Design pattern for persistent data storage - load and save arbitrary file, database, api etc

I have the following problem - I write the code for object data manager, and one of requirements is being able to save/load data into some persistent data storage. I want to make it as the following: ...
user avatar
  • 111
-3 votes
1 answer
54 views

Best way make a complex libraries as a plugin with dependency inversion principle [closed]

For instance, if we have a complex library with many functionalities, how can we make this lib a plugin such that it can be replaced with another lib more easily. The answer obviously is the ...
user avatar
2 votes
3 answers
222 views

Is there any redundancy within the scope of SOLID principles?

I have read in an article DIP in the Wild that "When Robert Martin first discussed the DIP, he equated it a first-class combination of the Open Closed Principle and the Liskov Substitution ...
user avatar
  • 101
0 votes
3 answers
122 views

Is it acceptable to inject dependency container in factories?

When trying to design a factory service in a project where i am using a dependency container i sometime find myself in this situation. I have an interface, in this example ISettingsLoader. ...
user avatar
  • 59
0 votes
2 answers
504 views

Onion architecture: Dependency Inversion Principle within the Service layer

I'm trying to implement a project using the Onion Architecture (aka Hexagonal, aka Ports and Adapters, aka Clean Architecture). I understand that the user interface uses Service interfaces instead of ...
user avatar
  • 271
0 votes
6 answers
392 views

If it is a bad practice to use an interface if only one class will implement it, what is the purpose of IoC container?

Okay, first of all I understand the concept of IoC container! It's used to implement automatic dependency injection so you won't have to manually inject dependencies to class. It can automatically ...
user avatar
  • 17
-3 votes
1 answer
74 views

Should you use your own implementation of inversion of control instead of a dependency injection container? [duplicate]

I have a small project that has 6 service classes and a main class. Since they are service classes and does not store any state in it, I declared one static method in each one: class Main calls A....
user avatar
3 votes
3 answers
456 views

How to decouple chain hierarchy project dependency by dependency injection? (C# .Net Standard)

I'm working on decoupling a Xamarin (.NetStandard) solution. It was using DryIOC container but I didn't see the IOC structure from the dependency, as the projects are still tightly coupled. Three main ...
user avatar
  • 133
0 votes
3 answers
375 views

Orthogonalization vs Dependency Inversion Principle

Is the dependency inversion principle an instance of orthogonalization? Given the class dependency X -> Y a common solution is to introduce interface Z so that the dependencies become X -> Z <...
user avatar
0 votes
2 answers
139 views

Improving dependency inversion principle

Reading a little bit about Functional core & imperative shell pattern, I am wondering if the DI principle can be improved. What happen if instead of having an Infrastructure layer depending on ...
user avatar
3 votes
3 answers
452 views

Dependency Inversion principle and high-level module reuse

If I got it right, the Dependency Inversion principle says that high level modules should use interfaces to the low level modules and low level modules should implement these interfaces. The purpose ...
user avatar
9 votes
4 answers
3k views

Is dependency inversion principle necessary?

I've read a lot about dependency inversion principle but still, I can't apply it to my case. I just don't know when I should apply it and when not. I write a simple application in Java to generate ...
user avatar
  • 327
8 votes
3 answers
4k views

Clean Architecture Gateway layer depends on outer layer

Looking at the clean architecture layers and flow diagrams, and implemented it my self in my applications, I've always wondered which layer is supposed to contain the DB, or any 3rd Party service or ...
user avatar
  • 227
2 votes
2 answers
236 views

Composition vs Aggregation: is this a "hidden my dependencies" case?

I have been thinking about this for a while and could not get to a conclusion. I need to convert a object to another (that will end up serialized as XML). Both objects have many fields, let's have an ...
user avatar
2 votes
2 answers
436 views

Migrating legacy code with singletons to Dependency injection

I'm working on a larger, older project. Our code is littered with classical singletons, i.e. classes like public class ABCService { private static final instance = new ABCService(); public ...
user avatar
1 vote
2 answers
859 views

Default value for constructor dependency injection

I have class A that depends on interfaces B & C. I use constructor injection to inject them into A: class A { let b: B let c: C init(b: B, c: C) { self.b = b self....
user avatar
  • 69
2 votes
1 answer
128 views

Application of Dependency Inversion Principle

Not a new programmer but new to architecture design. I'm about halfway through "Clean Architecture" by Robert C. Martin and I've realized that few components in my program need to have their ...
user avatar
  • 31
3 votes
1 answer
1k views

How do I implement Dependency Inversion in C?

I'm a firmware developer and I'm interested in applying the SOLID practice in low level programming especially in Hardware Abstraction Layers in ARM microcontrollers. Every example I come across on ...
user avatar
  • 203
2 votes
1 answer
104 views

Wrapping a legacy project in a test framework

I am working on wrapping an old project written in C# in a test framework. The largest problem I have is that I have a bunch of classes that are all VERY tightly coupled with other classes. All of ...
user avatar
4 votes
4 answers
1k views

Do we really need interface classes for the dependency inversion principle?

As a practical example, imagine a Gripper class which represents a robotic gripper in a simulation. Gripper has a TryGrip method, which checks if there's a GrippableItem in the correct position (...
user avatar
3 votes
1 answer
206 views

How to maintain Depedency Inversion Principle with enums & custom types?

From what I understand two components A and B should only communicate with one another via an interface. Ideally this interface should be in its own separate assembly so that the client need not be ...
user avatar
  • 909
6 votes
2 answers
486 views

Is it good design to have one constructor that supplies a "default" concrete class to another that takes an abstraction?

I like to invert dependencies whenever possible by depending mostly on abstraction and allowing the concrete implementations to be passed into the object by clients, or a factory. I've found this to ...
user avatar
1 vote
3 answers
323 views

Dependency Inversion Principle and Lower-Level Code Reuse

I am wondering about how to make lower-level code reusable when the Dependency Inversion Principle (DIP) is used. In the book Clean Architecture by Robert C. Martin, the DIP is described such that ...
user avatar
0 votes
2 answers
197 views

Avoid framework lock-in with dependency inversion

I am trying to understand the concept of dependency inversion and I think I finally got the concept. However now I am struggling with another issue, which is the selection of framework, when ...
user avatar
1 vote
2 answers
293 views

Should a BDD feature be implemented by a one (and only one) clean architecture interactor?

TL; DR Given BDD documentation with features composed by several scenarios, should we: Create a single interactor per feature Create minor interactors per scenario, and composing the feature ...
user avatar
3 votes
2 answers
980 views

Clean Architecture and Persistence Annotations

If one wants to comply with the clean architecture principle 100%, they must not annotate the entities in the entities layer with database-specific annotations (like Hibernate, Neo4j, etc.). So, two ...
user avatar
  • 199
2 votes
2 answers
3k views

Depend on DDD Entities or Interfaces?

My understanding is that the dependency inversion principle does not apply to entities, because entities basically are your application - it generally doesn't make sense to swap out a different ...
user avatar
  • 373
2 votes
2 answers
600 views

3 layer architecture In DI based software

I'm building software with 3 layer architecture and asp.net core , as you know the Dependency Injection is Built Into Asp.net core As i know the 3 layer architecture diagram is like this: ...
user avatar
1 vote
3 answers
252 views

Use just one parameter for all dependencies instead of many?

I understand that having 3 or more parameters as dependency is a sign that the class may be doing too many things, however there are cases that the class really needs more than 3. My question is, is ...
user avatar
  • 313
2 votes
2 answers
916 views

Dependency inversion vs repository pattern (app layer dependency on ORM)

Let's say we have an application layer with some command handler and we use an Entity Framework database context/ORM context in that handler. I would invert dependencies from the Entity Framework/...
user avatar
  • 23
1 vote
1 answer
132 views

Should a function implementer or function caller handle immutability

I know there is no right and wrong answer here, I'm just looking for other opinions on who should handle immutability, dependency inversion and decoupling. Example 1: Here each function caller has ...
user avatar
5 votes
2 answers
247 views

Help with dependency inversion

I'm learning about Binary Trees in school and I'm trying to apply the SOLID principles to it. My problem is in my BinaryTree::insert() method I'm creating a new BinaryNode, and from what I've ...
user avatar
0 votes
2 answers
220 views

How best to avoid member implementation of class' Abstract/Interface instance variables

I'm sorry if the phrasing of the question is a bit unclear but let me try to clarify below. (If anyone can word it better, feel free to edit) I have a Map instance variable, groups, which is defined ...
user avatar
  • 173
2 votes
4 answers
211 views

Is Implementation class exposure fine in Dependency Inversion

Basically we should depend on abstractions instead of concrete classes, that's the Dependency Inversion main principle. interface ITest { void DoSomething(); } class TestImpl : ITest { ...
user avatar
1 vote
2 answers
722 views

How to interpret Dependency Inversion Principle

I am working on trying to understand the SOLID object oriented design principles. I was able to get the "SOL" pretty easily, though "L" required some hand holding because I am bad at definitions. I ...
user avatar
  • 119
0 votes
3 answers
218 views

Circular dependency in composition root

I have a MDI MyMDIWinForm that needs an instance of IGUIErrorHanlder for error handling, At the same time IGUIErrorHanlder depends on the MDI MyMDIWinForm for having a place from where to launch pop-...
user avatar
  • 592
13 votes
5 answers
15k views

How to avoid bidirectional class and module dependencies

To give some context, I'm using python. We have the following package structure: /package_name /request.py # defines class Request /response.py # defines class Response Let also assume ...
user avatar
  • 291
9 votes
2 answers
707 views

I'm struggling to see how dependency inversion doesn't lead to tighter coupling in lower level modules and less reuseability

I'm refactoring a project I did for my work and I'm trying to apply the SOLID principles to make the architecture cleaner. I've run into an issue with the Dependency Inversion Principle that I can't ...
user avatar
2 votes
2 answers
706 views

Dependency Injection and DI Container

I have implemented clean architecture for my app, and I have a few questions. Typically, pure DI is argued for over a Service Locator pattern, because it is very explicit and more testable. However, ...
user avatar
  • 129
5 votes
1 answer
2k views

Is there really such a thing as the onion architecture?

Note: BLL = Business Logic Layer (can also mean your domain) I'm trying to understand the onion architecture. It seems to me that it's actually the same thing as the layered architecture, only with ...
user avatar
  • 2,257
3 votes
1 answer
447 views

How Dependency inversion is an extension of OCP?

I am reading about SOLID principles and have just read that Dependency Inversion (DI, to be distinguished here from Dependency injection, which is one way of achieving the inversion) is an extension ...
user avatar
0 votes
3 answers
345 views

Is it generally okay to use concrete classes from OS libraries on an interface?

I do believe that my question is similar to: Is it OK for interfaces to depend on concrete classes? and see/understand what the answer explains about how the dependency-inversion principle should be ...
user avatar
  • 2,728
0 votes
3 answers
1k views

Inject type as dependency injection, when new instances are required on each method call - How to avoid?

I have a class public class CertificadoHandler : ICertHandler { Type typeAfirmaValidate; public CertificadoHandler(){ typeAfirmaValidate = typeof(AfirmaValidateCertificate); } ...
user avatar
  • 592
6 votes
6 answers
3k views

Coding to Interfaces vs Abstract Inheritance

Inheritance vs coding to an interface is something I have wondered with respect to proper architecture design but actually have not run into an problems when using abstract inheritance over coding to ...
user avatar
  • 508
1 vote
2 answers
144 views

Testable design for a class that can only be instantiated through a static method

I'm attempting to design a class that is to be instantiated through the use of a static method, something like newInstance(param1, param2). The reason behind this is that 2 of the 4 parameters it ...
user avatar
3 votes
3 answers
735 views

How to handle common functionality that is not business logic in clean architecture

The dependency rule in Clean Architecture states that: ... that source code dependencies can only point inwards. I now came across a problem that I cannot figure out myself. Lets assume I have a ...
user avatar
3 votes
3 answers
1k views

Clarification on the Dependency Inversion Principle

I'm reading the book "Agile Software Development, Principles, Patterns, and Practices" by Robert C. Martin. When he talks about the Dependency Inversion Principle he gives the following example of a ...
user avatar
1 vote
2 answers
467 views

Dependency Injection - Return Types

I am confused about Dependency Inversion in general. Lets's say we have 2 layers: Layer0 the low level layer, and Layer1 the high level layer. Layer1 should define the abstract interface, and Layer0 ...
user avatar