wabbajack/Wabbajack.App/Views/ViewBase.cs

20 lines
550 B
C#
Raw Normal View History

2021-09-27 12:42:46 +00:00
using System;
using Avalonia.ReactiveUI;
using Microsoft.Extensions.DependencyInjection;
using Wabbajack.App.ViewModels;
2021-10-23 16:51:17 +00:00
namespace Wabbajack.App.Views;
public abstract class ViewBase<T> : ReactiveUserControl<T>
2021-09-27 12:42:46 +00:00
where T : ViewModelBase
2021-10-23 16:51:17 +00:00
{
public ViewBase(bool createViewModel = true)
2021-09-27 12:42:46 +00:00
{
2021-10-23 16:51:17 +00:00
if (createViewModel)
2021-09-27 12:42:46 +00:00
{
2021-10-23 16:51:17 +00:00
ViewModel = App.Services.GetService<T>();
if (ViewModel == null)
throw new Exception($"View model {typeof(T)} not found, did you forget to add it to DI?");
2021-09-27 12:42:46 +00:00
}
}
}