Birthday Reminders - Postscript - Don't Repeat Yourself - Dependency Injection
HTML-код
- Опубликовано: 7 окт 2024
- After completing the Blazor Birthday Reminders project I was frustrated that I had copied and pasted code between files but couldn't work out how to 'extract' the copied code into a separate file or method. Dependency injection is the answer and this is how I implemented it.
Excellent video. I didn't know you could do that! Very helpful!
Glad you liked it!
Thank you for the video.
I fixed the error. The error said: InvalidOperationException: Cannot consume scoped service 'BlazorBirthdayReminders.Data.IPersonService' from singleton 'BlazorBirthdayReminders.Data.IReminderService'. When I changed IRemiderService to Scoped, I got this error: Cannot resolve scoped service 'BlazorBirthdayReminders.Data.IReminderService' from root provider. Source=Microsoft.Extensions.DependencyInjection.
I fixed the error by making these services all Transient. 🙂
Thanks for letting me know. Hopefully it will help others that have the same problem.