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 - Python Tutorial
From the course: C#: Design Patterns Part 1
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
-
-
-
-
-
-
(Locked)
Factory Method pattern definition5m 3s
-
(Locked)
Factory Method pattern to choose the implementation of an action dynamically4m 26s
-
(Locked)
Factory Method design pattern for unit testing6m 5s
-
(Locked)
Challenge: Factory Method with dependency injection1m 37s
-
(Locked)
Solution: Factory Method with dependency injection3m 18s
-
(Locked)
-
-