@@ -39,6 +39,7 @@ public class HomeViewModel : ObservableObject, IDisposable, IRecipient<Initializ
3939 // Map AlarmSchedule IDs to ScheduleListItem ViewModels for UI binding
4040 private readonly Dictionary < long , ScheduleListItem > _scheduleViewModels = [ ] ;
4141
42+ private readonly Func < AlarmSchedule , ScheduleListItem > _scheduleListItemFactory ;
4243
4344 private readonly Fluxor . IDispatcher _dispatcher ;
4445 private readonly IState < ApplicationState > _state ;
@@ -53,6 +54,7 @@ public HomeViewModel(
5354 IAlarmService alarmService ,
5455 INotificationService notificationService ,
5556 IServiceScopeFactory scopeFactory ,
57+ Func < AlarmSchedule , ScheduleListItem > scheduleListItemFactory ,
5658 Fluxor . IDispatcher dispatcher ,
5759 IState < ApplicationState > state )
5860 {
@@ -62,6 +64,7 @@ public HomeViewModel(
6264 _alarmService = alarmService ;
6365 _notificationService = notificationService ;
6466 _scopeFactory = scopeFactory ;
67+ _scheduleListItemFactory = scheduleListItemFactory ;
6568 _dispatcher = dispatcher ;
6669 _state = state ;
6770
@@ -218,9 +221,6 @@ public ObservableHashSet<ScheduleListItem> Schedules
218221
219222 private void UpdateScheduleViewModels ( ObservableHashSet < AlarmSchedule > schedules )
220223 {
221- using var scope = _scopeFactory . CreateScope ( ) ;
222- var logger = scope . ServiceProvider . GetRequiredService < ILogger > ( ) ;
223-
224224 var newViewModels = new ObservableHashSet < ScheduleListItem > ( ) ;
225225 var currentViewModelIds = new HashSet < long > ( ) ;
226226
@@ -232,14 +232,14 @@ private void UpdateScheduleViewModels(ObservableHashSet<AlarmSchedule> schedules
232232 if ( _scheduleViewModels . TryGetValue ( schedule . Id , out var existingViewModel ) )
233233 {
234234 // Update existing ViewModel's Schedule property
235- existingViewModel . Schedule = schedule ;
235+ existingViewModel . Initialize ( schedule ) ;
236236 existingViewModel . IsEnabled = schedule . IsEnabled ;
237237 newViewModels . Add ( existingViewModel ) ;
238238 }
239239 else
240240 {
241- // Create new ViewModel
242- var viewModel = new ScheduleListItem ( schedule , logger , _scopeFactory ) ;
241+ // Create new ViewModel using factory with full DI
242+ var viewModel = _scheduleListItemFactory ( schedule ) ;
243243 _scheduleViewModels [ schedule . Id ] = viewModel ;
244244 newViewModels . Add ( viewModel ) ;
245245 }
0 commit comments