From the course: C#: Design Patterns Part 1

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Solution: Factory Method with dependency injection

Solution: Factory Method with dependency injection - Python Tutorial

From the course: C#: Design Patterns Part 1

Start my 1-month free trial

Solution: Factory Method with dependency injection

(upbeat music) - [Instructor] How did you do? Were you able to create a factory method to run with a notification service was requested. For my solution, here in the Core project, I added the IUserNotifier that we used before, as well as the Email and TestUserNotifiers. I added some extra new lines, to help them show up in the debug log. In the OrderService, I added the IUserNotifier field, and added it to the constructor, all the way down here in the order method, on line 62, I called NotifyUser after the order, save changes is complete. Now, we'll look at where we created the factory method in Configure.cs. I add the UserNotifier to the ServiceCollection, and use the overload, that takes a function whose input is the ServiceProvider, and output is the requested type. The configuration access service, IConfiguration, is added to the ServiceProvider by default, and we can use it to read values in appsettings. I…

Contents