I want to use Dependecy injection in my new .net core project, but my manager thinks it is an anti-pattern usage. I already know benefits of dependency injection. But my manager cares architecture more than everything. Anyway, when search about it, i have read enough reviews. There are different opinions about it and i am still not sure. So asking here. Is it an antipattern example or not? If it is not what is the best practice, is it okey to reference data and businness layers on UI layer? I always use this structure but just want to do deeper research best practice about that.
-
2It is not an anti-pattern. But we cannot help you unless you tell us in detail why your manager thinks it is.Euphoric– Euphoric2020-01-27 08:15:41 +00:00Commented Jan 27, 2020 at 8:15
-
The reason is that, we need to reference to business layer, even data layer. This happening at the top level of the project structure. I mean in start up you need to register types to use dependency injection. So he has right about that. There are another ways to register types like using extensions from different layers. But even then you need to reference Businnes layer from UI which is the top level of the project. My manager may be wrong but i need more detail to explain and convince him.cansu– cansu2020-01-27 08:23:52 +00:00Commented Jan 27, 2020 at 8:23
-
1Yes or no questions are not good for this site. The best answer you can get for the question as it stands at this moment is the one above: "it isn't an anti-pattern". However, perhaps you are trying to use dependency injection where you should not, or perhaps you call dependency injection something different than what we understand by that topic (some people say dependency injection and mean IoC containers, for example). If you edit the question adding more detail, we could be able to tell why dependency injection is a good idea or a bad idea for what you are doing.Theraot– Theraot2020-01-27 08:23:54 +00:00Commented Jan 27, 2020 at 8:23
-
Thank you Theraot, i try to add some detail. I hope it could be more explanative. I mean .net core dependency injection, not IoC.cansu– cansu2020-01-27 08:30:08 +00:00Commented Jan 27, 2020 at 8:30
-
You should then focus on the difference between the two. Because to me, you are talking about two exactly same things.Euphoric– Euphoric2020-01-27 08:30:59 +00:00Commented Jan 27, 2020 at 8:30
|
Show 2 more comments
1 Answer
By defition the dependency injection is a pattern.
The ASP.NET Core is built around dependency injection as it allows great flexibility in the framework.
In a plain .NET Core application, the DI pattern can be used and also overused. As with any technology and patterns, in may be used inapropriately. This depends on your application and must be evaulated based on actual requirements for the app.