Тёмный

Dependency Injection in C# using Autofac 

Claudio Bernasconi
Подписаться 18 тыс.
Просмотров 50 тыс.
50% 1

Опубликовано:

 

15 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 66   
@ClaudioBernasconi
@ClaudioBernasconi 5 лет назад
What's your favorite Dependency Injection framework? Have you been using Autofac? Let me know!
@dcernach
@dcernach 5 лет назад
Used to be Ninject, now it's Autofac, thanks for your video...
@digitaldias
@digitaldias 4 года назад
StructureMap. Still by far the nicest one to work with.
@siddharthshinde4480
@siddharthshinde4480 2 года назад
I love using AutoFac irrespective of the project size. Bdw great video!
@angel_machariel
@angel_machariel Год назад
Good explanation. No-nonsense code, everything is easy to understand.
@ClaudioBernasconi
@ClaudioBernasconi Год назад
Thank you so much. 🙏😉
@eternalwanderer3785
@eternalwanderer3785 4 года назад
Thank you very much for making this video. As stated, you're moving incredibly fast through this. This is my first time learning DI and I had to watch this 3 times to get the concept of what was done. It would probably help to slow down and explain why each step is taken and the negative impact of not doing so, or how it's removing dependencies. To me (and I have no clue about dependency injection) iit just looks like beautifying the code initially, I had to really repeat the video and test it to understand the concept - which I'm still kind of foggy. Not to nitpick, but I noticed you're moving so quickly there was syntax error in 8:29 and it still compiled? Furthermore, I don't think it's necessary in the end to tell me what I learned, this should be apparent, unless you're moving so quickly I had to be reminded that I missed something. Anyways, thank you for introducing Autofac and I look forward to more of your videos.
@ClaudioBernasconi
@ClaudioBernasconi 4 года назад
Thank you very much for this detailed feedback. This is the second video I did for my channel, and I learned a lot since I started in December 2018. One of my goals was to deliver as much value as possible without wasting time. As it turned out, I was moving too quickly for most people. I adapted in future videos, and I'm going to improve even further. I have a lot of respect for you that you went through the video multiple times instead of searching for another video. It shows how committed you are to learn this topic. The summary at the end does not take a long time, and I was always happy when the teacher at my university did it. I haven't received negative comments on this so far, but I'll consider leaving it out in the future. It depends on the topics of the video. About the syntax error, it seems to me like Visual Studio just took its time to update the error list. Usually, I do not take a look at the error list unless I tried to compile the code, and it did not succeed. Again, thank you very much for taking the time to provide this insightful feedback. I'll take everything into account for future videos.
@YogeshSharma-qb6ch
@YogeshSharma-qb6ch 3 года назад
I completely agree with Gene but still great job. Thanks.
@prasadmadushan
@prasadmadushan Год назад
Nice explained. it's really nice how u use module. keep making videos. thanks
@ClaudioBernasconi
@ClaudioBernasconi Год назад
Thanks, very kind of you. 🙂
@dcernach
@dcernach 5 лет назад
Great video, straight to the point... Congrats!
@ClaudioBernasconi
@ClaudioBernasconi 5 лет назад
Hey Dalton, thank you very much for your feedback. I am very happy that this video helped you in some way.
@matheshwaran602
@matheshwaran602 3 года назад
very nice explanation , My understanding dependency injection is passing object param itself with autofac when we register class . in example userservice class we had constructor expect INotifcationService from object creation public UserService(INotifcationService notficationservice) { _notficationservice = notficationservice; } but we have not passed respective object. instead of that we register UserService , INotifcationService with DI var notificationService = container.Resolve(); var userService = container.Resolve(); so we calling directly an method userService.ChangeUserName(user1, "waran"); please correct me if am wrong Thanks
@tondar2127
@tondar2127 4 года назад
Your describing skill is on another level !
@ClaudioBernasconi
@ClaudioBernasconi 4 года назад
Thank you so much for your very kind feedback. I'm glad you learned something.
@tipster360
@tipster360 11 месяцев назад
Very well explained!
@ClaudioBernasconi
@ClaudioBernasconi 11 месяцев назад
Thank you! 🙂
@amannur8604
@amannur8604 4 года назад
Great video. Straight to the point very cleared.
@ClaudioBernasconi
@ClaudioBernasconi 4 года назад
Thank you very much, Aman.
@fingodiel
@fingodiel 2 года назад
Just here to say thanks, gracias!
@ClaudioBernasconi
@ClaudioBernasconi 2 года назад
Thank you so much. Very kind of you. 🙏
@jackquaddy
@jackquaddy 4 года назад
Thanks for this excellent video Claudio, I'm certainly a lot closer to understanding dependency injection having watched it! I'm not quite sure what's the point of adding the ProgramModule class at the end - what does this do? Also, for us beginners it might be useful to include another diagram at the end showing the relationship between the classes after refactoring.
@ClaudioBernasconi
@ClaudioBernasconi 4 года назад
Thanks, I appreciate your feedback, and I'm happy you learned a thing or two while watching the video. It was one of the first videos on my channel, and I'd include another diagram at the end if I would recreate it. The ProgramModule class allows you to group the registrations. You can use Autofac modules to organize registrations. I might create another more in-depth video about why that could be useful. But let's say you have a library. You can create a module class that contains all registrations, and then you could use that module class in the application.
@انامسلموكفى
@انامسلموكفى 2 года назад
Thank u for this great genial video, i got the point when u register the consoleNotification in the container because of its dependency from the user class but i see tht the userService has a dependency to user class so why the register inversly called instead of register the user class u re registering the userService class i didnt get it ? Could u please explaint ut for me
@ClaudioBernasconi
@ClaudioBernasconi 2 года назад
The User class is a data class and does not include logic. That's why I reference it directly from the service class.
@frankray3289
@frankray3289 2 года назад
Seriously good video, thank you.
@ClaudioBernasconi
@ClaudioBernasconi 2 года назад
Seriously, thank you. 🙏🙂
@RAULKMILOF35
@RAULKMILOF35 4 года назад
Great video, one of the most clear explanation. The resolve for the notification services it's not needed because at resolve the user service all of the inside dependencies that needed will be resolved, I'm right?
@ClaudioBernasconi
@ClaudioBernasconi 4 года назад
Thank you. I'm not sure if I understand your question, but I think you are right. 😊
@OeHomestead
@OeHomestead Год назад
So you took something really simple and straight forward and made it more complex, adding more dependencies. Could've gotten the same result using the built-in IoC, with less code :-) Other than that, nice video.
@ClaudioBernasconi
@ClaudioBernasconi Год назад
I understand the criticism, and for this simple example, the built-in container would be enough. The video is targeted toward people who use Autofac at work (have no choice) and want to learn how it works. Still, I appreciate your comment; thanks for watching.
@tassisto
@tassisto 3 года назад
Do we still have to use Autofac in .NET Core or is there a feature built in. I heard that we’ll no longer have to use it, but I’m not sure
@ClaudioBernasconi
@ClaudioBernasconi 3 года назад
The built-in DI mechanism is great. In most projects, it's good enough. I might create a video about it. Autofac offers additional features that you might or might not treat as useful depending on your use case.
@tassisto
@tassisto 3 года назад
@@ClaudioBernasconi that was my next question 😅, it would be really nice to watch it. Thank you so much
@chrisauret3785
@chrisauret3785 3 года назад
You didnt explain why you introduced the Autofac.Module at all. "We want to make use of Autofacs modularity feature".. OK, why? What is Autofac Modularity feature? When and why would I use it? How would I combine it with othe Modules?
@ClaudioBernasconi
@ClaudioBernasconi 3 года назад
Thanks for your feedback. Yes, I could have talked more about Autofac modules. I focused on how to get things done and didn't explain the Autofac modules a lot. To fill your gap and to provide you with as much detail as I can, I recommend reading the docs here: autofac.readthedocs.io/en/latest/configuration/modules.html
@austinmrakpor4863
@austinmrakpor4863 3 года назад
Why is every tutorial on autofac is console app? I need it to work in my desktop app, haven't been able to get it to work can you help??
@GammaSouljah
@GammaSouljah 3 года назад
Use Prism for a WPF/UWP app famework including dependecy injection (it uses either Unity or DryIOC) amoung other things
@neelimawaghchoude2990
@neelimawaghchoude2990 4 года назад
Good video! I am trying to learn Autofac from this video however run into the exception in Program class on line 15 saying Inotification service is not registered. What could be the problem?
@ClaudioBernasconi
@ClaudioBernasconi 4 года назад
Can you share your project online and link it here? I would give it a look. Thanks for watching the video.
@MSK12357
@MSK12357 4 года назад
Very well explained. But had to watch at 0.75x speed.
@ClaudioBernasconi
@ClaudioBernasconi 4 года назад
Thanks. I tried to speak slower in future videos.
@limsky8012
@limsky8012 3 года назад
UserService creation purpose was not clear also not clarified why it's empty.
@henriknielsen8097
@henriknielsen8097 4 года назад
Can I download the source somewhere ?
@cg-tespy3098
@cg-tespy3098 4 года назад
Very nice!
@yasser2768
@yasser2768 4 года назад
I just don't really find DI useful that much
@PalashBansal
@PalashBansal 4 года назад
what is autofac full form?
@ClaudioBernasconi
@ClaudioBernasconi 4 года назад
I don't know. Where have you seen that?
@PalashBansal
@PalashBansal 4 года назад
@@ClaudioBernasconi I am not finding, but wondering "autofac" must have got "fac" from somewhere. May be only creator can tell
@MSK12357
@MSK12357 4 года назад
Could be derived from automatic factory.
@rjcwaring
@rjcwaring 4 года назад
Dude - slow down :)
@rjcwaring
@rjcwaring 4 года назад
Let me qualify that. Thanks for this video, and the one before it, both of which I've found really helpful. I'm grateful for your time and generosity in sharing what you know. I just wanted to offer some feedback on how this video was for me as a learner - I'm watching this because dependency injection in C# is new to me - I'm very much a student rather than a master. As a student, I'd love to have a little more time to take in the code that you've written in the different classes and interfaces - to see how they fit together. As a student, it's a challenge for me to stay with you at the speed that you are going - I would love the ease of a little more time and simplicity (perhaps in relating the implementation details back to a simple overview?).
@ClaudioBernasconi
@ClaudioBernasconi 4 года назад
Hey Rich. Thank you very much for your detailed feedback. In my first videos, I wanted to make sure that I am not telling boring stuff and taking too long to explain a concept. I learned from your feedback and a few other people that I need to slow down and that I can take a few more seconds to explain a topic without having a fear of annoying people. I'll consider that feedback in my future videos. I'm glad you enjoyed it, and you've learned something here. I hope to provide you with exciting videos in the future.
@hshxy
@hshxy 3 года назад
Yeah agreed :)
@jasonmeyer495
@jasonmeyer495 2 года назад
Useful video, but your claim in the summary that we've learned "How DI frameworks help your code" isn't actually true. You gave an example usage of a DI framework, but that's it. For the claim to be true, you'd have to first show what the equivalent code looked like *without* Autofac. And then show the difference with Autofac and explain why it's better with Autofac. Then your video would truly be fantastic.
@ClaudioBernasconi
@ClaudioBernasconi 2 года назад
Thanks for your well-thought feedback. I agree with you.
@konst3d
@konst3d 2 года назад
Isn't it basically a service locator that everyone hates?
@ClaudioBernasconi
@ClaudioBernasconi 2 года назад
Great question. The difference between dependency injection and service locator is the following: If you use a service locator it means that you have a hard dependency on the said locator. That means that almost every class of your system ends up with a dependency on that service locator. If you use the built-in dependency mechanism of the .NET applications, you don't have the same reference in every single class. You only reference the types/interfaces you need for your type. I hope this helps a little.
@konst3d
@konst3d 2 года назад
@@ClaudioBernasconi Yeah, thanks for the answer. I see, this way we only have locator\container dependency on the module that registers all the types within locator\container.
@goffredo81
@goffredo81 4 года назад
troppo veloce nella spiegazione, è possibile pubblicare video più lunghi di 10 minuti, in ogni caso molto utile alla comunità di developers.
@ClaudioBernasconi
@ClaudioBernasconi 4 года назад
Grazie mille per il tuo feedback. Proverò a parlare più lentamente in futuro.
@kananian_saba
@kananian_saba 3 года назад
I prefer not to use it.
@STUPIDYOUTUBE_HIDINGMSGS
@STUPIDYOUTUBE_HIDINGMSGS 3 года назад
This is awesome, perfectly paced and clear, simple explanations! Have you considered making other tutorials about DI using microsoft container? Thanks
@K4MR4N1UK123
@K4MR4N1UK123 4 года назад
Its hard to understand your accent. Clauses? Do you mean by classes?
@ClaudioBernasconi
@ClaudioBernasconi 4 года назад
Thanks for ypur feedback. I'm working on it. English is my third language. Where are you from?
Далее
Extensible C# Applications using Autofac
13:01
Просмотров 12 тыс.
小丑调戏黑天使的后果#short #angel #clown
00:16
Silent Hill 2 - Мульт Обзор
07:26
Просмотров 260 тыс.
Introduction to Dependency Injection in C#
7:25
Просмотров 111 тыс.
Dependency Injection & Inversion of Control
11:00
Просмотров 198 тыс.
C# Dependency Injection with Autofac
54:45
Просмотров 296 тыс.
How Dependency Injection Works in #csharp
43:52
Просмотров 54 тыс.
Dependency Injection
4:47
Просмотров 942 тыс.
8 await async mistakes that you SHOULD avoid in .NET
21:13
.NET 8 | Everything you NEED to KNOW!
9:04
Просмотров 28 тыс.
Dependency Injection
45:17
Просмотров 147 тыс.
Dependency Injection in .NET Core (.NET 6)
1:00:32
Просмотров 192 тыс.