wabbajack/Wabbajack.App/Views/ViewBase.cs
2021-10-23 10:51:17 -06:00

20 lines
550 B
C#

using System;
using Avalonia.ReactiveUI;
using Microsoft.Extensions.DependencyInjection;
using Wabbajack.App.ViewModels;
namespace Wabbajack.App.Views;
public abstract class ViewBase<T> : ReactiveUserControl<T>
where T : ViewModelBase
{
public ViewBase(bool createViewModel = true)
{
if (createViewModel)
{
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?");
}
}
}