我需要在主窗口构造函数上注入一个记录器来启动我的WPF应用程序 这个流是用于启动带有参数的MainWindow()吗? (我读了这个“how to edit..”并且我没有像他们建议那样做。)
public partial class App : Application
{
private void Application_Startup(object sender, StartupEventArgs e)
{
ILoggingService logger = new NLogService(string.Format("testLogger"));
MainWindow mainWindows = new MainWindow(logger);
mainWindows.Show();
}
public partial class MainWindow : Window
{
public MainWindow(ILoggingService logger)
{
InitializeComponent();
this.logger = logger;
}
<Application x:Class="Test.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Startup="Application_Startup">