Dagger in business logic and presenters [closed] - dependency-injection

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
I'm already using Dagger2 and everything is working but I have a doubt about the proper way to integrate it into the business logic.
What Robert Martin says in "Clean Architecture" is that the DI frameworks, since they are frameworks, are details that should be kept away from the Entity and Use cases and more in general from all the classes that are at a higher level than the frameworks.
What R.M. suggests is to allow only the Main-module to know the DI framework used and to inject the other classes by yourself in such a way that you can replace one DI framework with another one without having to change the BL.
Is there a way to isolate Dagger in such a way that the business logic does not see it?

Strictly speaking, yes: DI frameworks should also not be used in use case or entities circle. (That includes attributes and annotations)
The question would be how strict u want to handle this rule in ur project. Every rule and decision has pros and cons. As u said the pro of keeping DI out of the inner circles would be that u could easily replace it later. U would have to decide how big the benefit is compared to the cons, e.g.: having to pass dependencies to use cases manually.
Personally I currently try to handle it very strict in my projects. But my usecases tend to have only few dependencies ...

Related

iOS container for an iPhone app written in Objective-C [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
Coming from Android, I got used to Dagger as my main DI framework.
Recently, I joined a new iPhone project written in Objective-C which have no DI framework.
I would like to add one to our project, and I wonder which one is the best one to use, when it comes to simplicity and performance.
I would like to hear your opinion and experience.
Thanks!
Dependency injection is a popular design pattern in many languages, such as Java and C#, but it hasn’t seen widespread adoption in Objective-C (yet!).
This is an excellent read to get you started on DI is Objective-C. Additionally, you'll find this, this & the Grand Daddy this indispensable for DI in iOS.
This framework seems to be making a lot of noise these days.
In my personal experience, more than anything else DI helps you a lot in testing. It's not all or nothing approach (which is common for many design patterns) allows for easy, no-cost adoption & definitely valuable returns.

Is it good or bad to use the same package for domain and controller classes? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I am new to grails. One thing I have noticed in the codebase of my current project is that the domain classes and the controller classes share the same package. So, you have something like this:
grails-app/controllers/foo/BarController.groovy
grails-app/domain/foo/Bar.groovy
So, is this a common practice? What are pros and cons of this? Thank you very much.
I think it's ok to use the same package for domain objects and controllers.
There is a practice called Package by Feature, which argues that grouping classes by what kind of component they are or what layer they are in is not as effective as grouping things together that contribute toward implementing the same functionality. When I work on projects packaged by layer I do a lot of hunting around going back and forth, grouping by feature would reduce that.
Usually domain objects have very little private about them. Also privacy in Groovy classes is nonexistent anyway.
This is how "convention" works over "configuration" in Grails. This is a common practice. I haven't found a demerit using it this way.
Normally, when you create-domain-class or create-controller even the tests are added in the same package as the domain class/controller respectively.
Best example of convention I can cite is when you use
grails generate-all yourPackage.Domain
Stumbled upon a similar post related to Grails where exactly the package by feature aspect as mentioned by Nathan is explained. Hope that helps.

The purpose of Unity, Dependency Injection [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am new to the concept of Unity/Dependency Injection.
My understanding is that you use DI to avoid tightly coupled class structure but I am struggling to see its benefits.
I followed "The Unity Container" section on this link http://www.refactorthis.net/post/2012/10/25/Dependency-Injection-and-Inversion-of-Control-Ioc-With-the-Microsoft-Unity-Container.aspx but I do not know why this is "better" - it introduces a lot more code and still, inside LoggingModule.cs I still have to have this line of code:
_iocContainer.RegisterType(typeof(ILogger), typeof(DBLogger));
Meaning there is still a dependency but I have just moved it into a secluded location. I still have to tell Unity which class I want to use
This question will probably be marked as non-constructive but I would like to be told the benefits and how to use Unity/DI correctly.
Thanks,
Andrew
The benefit is that your services now depend on abstractions (ILogger) and the resolution of the abstraction is responsibility of the container. Besides, the declaration of your dependencies and which concretions to use and their life time is centralized in the Composition Root (the place where you register the dependencies in the container).
I suggest you to read a good book about dependency injection, there are several out there.

How do i know if i need to use a design-pattern? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I'm just wondering, I'm new to this pattern subject, I started like couple of weeks ago but my main problem is, when I start writing small applications (for self purposes) I can't think where to put any pattern to use, maybe it's my thinking structure that needs to be tweaked ?
If I start a new project, how would I know if I need to use a pattern ? what questions do I ask myself ? what steps do I take before writing the actual code ?
Look at the Delphi VCL...it's basically took the Design Patterns and ran with them...
Forms are Composite Patterns.
Datasets use the Iterator Pattern.
Screen and Application are Singleton Patterns.
Components use lots of
different Patterns, the Chain of Responsibility, Decorator, Facade
to name a few...
Patterns are ways to organize your program and objects in lightly coupled objects that have jobs that you do over and over again...
Design patterns are just ways to approach solutions to common problems. As you internalize the patterns and as you understand the problem better you will sometimes see that the problem (or part of the problem) you are solving is addressed by a particular pattern.
That's when you use it. When you see it solving your problem.
Design patterns are reusable solutions for common problems.
The principles of Software Engineering cites the reusability of codes, when you use a design pattern you are using a concept previously tested that went trough several validations and is less prone to an design error than if you design your own model.
So first, you have to know the existing design patterns and what they're intended to solution. When you face a common problem you may remember the design patterns you previously studied and use them to solve the situation you're facing at the moment.

What is the value of OOP in ASP.NET MVC? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
As a C++ developer from the 90s during the great OOP wars, I put high value to OOP as a basis for hiring new C# developers into the company.
However, there are plenty of frameworks today like ASP.NET MVC that handles most of the OOP heavy lifting. Programmers without deep knowledge of OOP can just as easily follow the paradigm and still be able to complete their projects. OOP may not be as compelling as it was before for us application developers, especially with a framework like MVC.
I can see a few instance where OOP will be really handy, like for example developing a workflow type of a project. Or those with state-machine requirements. But really, most projects that really come by (at least to us here anyway) are just CRUD functionalities.
Below is my list when hiring. Is it fair to have OOP there as the number one item?
OOP and Design
Server side programming: C#, ASP.NET MVC and EF
Client side programming: JQuery, CSS, HTML, etc.
Database design
OOP-thinking indicates, that candidate is good at project-architecture. You always need to implement some reusable components, classes, functions, and of course libraries. From my point of view, it is must have for any candidate to know OOP and Design Patterns to be hired.

Resources