DEV Community 👩‍💻👨‍💻

DEV Community 👩‍💻👨‍💻 is a community of 963,274 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in

Discussion on: Episode 005 - Dependency Injection - ASP.NET Core: From 0 to overkill

Collapse
 
dyagzy profile image
dyagzy

Many thanks for this chapter, see questions below:

  1. How do I when to use a 3rd party DI or IoC in my project

  2. Why did you use an extension method for ToViewModel and ToServiceModel? Although it seems a little confusing to me but I will go over it again till am able to understand it's use case.

  3. Which other way can be use to achieve the use of the extension method as you have done without using an extension method?

Thank you for your reply always.

Collapse
 
joaofbantunes profile image
João Antunes Author

Hi there!
Let's see if I can answer all of them:

  1. If the built-in container is good enough for your needs, probably just stick with it. Otherwise, you can look at alternatives if:
    • You already have experience and like a different container
    • You need some features that another container provides (including performance)
  2. These extension methods are just to move the boilerplate mapping code out of the controller. I could just have mapped everything in there, but the controller code would be polluted with things that are not really relevant for its logic.
  3. Not sure I understand this one. An extension method is a normal static method, with syntactic sugar to make things more readable, so instead of doing GroupMappings.ToViewModel(group), we can do group.ToViewModel(). Was this the question, or another thing?
Collapse
 
dyagzy profile image
dyagzy

Thank you for your responses.
I quite understand your answers to my questions (1 and 2).

I guess I should follow up with your tutorial to the next episode perhaps I will better understand your answer to the 3rd question.

I will revert back to you with more questions.