51 lines
1.6 KiB
C#
51 lines
1.6 KiB
C#
using Autofac;
|
|
using System.Configuration;
|
|
using System.Data;
|
|
using System.Net.Http;
|
|
using System.Reflection;
|
|
using System.Windows;
|
|
using Client.ViewModels;
|
|
|
|
namespace Client
|
|
{
|
|
public partial class App : Application
|
|
{
|
|
public IContainer Container { get; set; }
|
|
|
|
protected override void OnStartup(StartupEventArgs e)
|
|
{
|
|
base.OnStartup(e);
|
|
|
|
var containerBuilder = new ContainerBuilder();
|
|
|
|
containerBuilder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly())
|
|
.Where(t => t.IsClass && (t.Namespace.Contains("Client")));
|
|
// .Where(t => t.IsClass && (t.Namespace.Contains("Models") || t.Namespace.Contains("ViewModels") || t.Namespace.Contains("Views")));
|
|
|
|
// Code von ChatGPT um den Autogenerierten ServiceClient
|
|
// mit Dependency Injektion zu machen
|
|
containerBuilder.Register(c =>
|
|
new HttpClient
|
|
{
|
|
BaseAddress = new Uri("https://localhost:7118")
|
|
}).SingleInstance();
|
|
|
|
containerBuilder.Register(c =>
|
|
{
|
|
var httpClient = c.Resolve<HttpClient>();
|
|
var baseUrl = "https://localhost:7118";
|
|
return new ServiceClient(baseUrl, httpClient);
|
|
}).AsSelf();
|
|
// --------------------------------------------
|
|
|
|
containerBuilder.RegisterInstance(this);
|
|
this.Container = containerBuilder.Build();
|
|
|
|
var instanz = this.Container.Resolve<MainWindowViewModel>();
|
|
instanz.ReloadCommand.Execute(null);
|
|
instanz.Initialize();
|
|
}
|
|
}
|
|
|
|
}
|