Add a factory for populating view models
This commit is contained in:
@@ -7,5 +7,7 @@ public class PrimaryWidgetProvider :
|
||||
IWidgetProvider
|
||||
{
|
||||
public void Create(IServiceCollection services) => services.AddConfiguration<PrimaryWidgetConfiguration>()
|
||||
.AddTransient<PrimaryWidgetViewModelFactory>()
|
||||
.AddTransient(provider => provider.GetRequiredService<PrimaryWidgetViewModelFactory>().Create())
|
||||
.AddWidgetTemplate<PrimaryWidgetViewModel>();
|
||||
}
|
||||
@@ -1,16 +1,16 @@
|
||||
namespace Hyperbar.Windows.Primary;
|
||||
|
||||
public class PrimaryWidgetViewModel :
|
||||
WidgetViewModelBase
|
||||
ObservableCollectionViewModel<IWidgetComponentViewModel>,
|
||||
IWidgetViewModel,
|
||||
ITemplatedViewModel
|
||||
{
|
||||
public PrimaryWidgetViewModel(ITemplateFactory templateFactory,
|
||||
public PrimaryWidgetViewModel(ITemplateFactory templateFactory,
|
||||
IServiceFactory serviceFactory,
|
||||
IMediator mediator) : base(templateFactory, serviceFactory)
|
||||
IEnumerable<IWidgetComponentViewModel> items) : base(serviceFactory, items)
|
||||
{
|
||||
Add<WidgetButtonViewModel>("Start", new Action(() => mediator.Send(new KeyAcceleratorCommand(VirtualKey.LeftWindows))));
|
||||
|
||||
//Add<WidgetButtonViewModel>("test 2", new Action(() => { }));
|
||||
//Add<WidgetButtonViewModel>("test 4", new Action(() => { }));
|
||||
//Add<WidgetButtonViewModel>("test 5", new Action(() => { }));
|
||||
TemplateFactory = templateFactory;
|
||||
}
|
||||
|
||||
public ITemplateFactory TemplateFactory { get; }
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
namespace Hyperbar.Windows.Primary;
|
||||
|
||||
public class PrimaryWidgetViewModelFactory :
|
||||
IViewModelFactory<PrimaryWidgetConfiguration, IEnumerable<IWidgetComponentViewModel>>
|
||||
{
|
||||
private readonly PrimaryWidgetConfiguration configuration;
|
||||
private readonly IServiceFactory service;
|
||||
|
||||
public PrimaryWidgetViewModelFactory(PrimaryWidgetConfiguration configuration,
|
||||
IServiceFactory service)
|
||||
{
|
||||
this.configuration = configuration;
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
public IEnumerable<IWidgetComponentViewModel> Create()
|
||||
{
|
||||
foreach (IPrimaryCommandConfiguration item in configuration)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return Enumerable.Empty<IWidgetComponentViewModel>();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user