diff --git a/LoggingClient/LoggingClient/Container/Builder.cs b/LoggingClient/LoggingClient/Container/Builder.cs new file mode 100644 index 0000000..285a2e6 --- /dev/null +++ b/LoggingClient/LoggingClient/Container/Builder.cs @@ -0,0 +1,31 @@ +using Autofac; +using LoggingClient.Model; +using LoggingClient.Repository; +using LoggingClient.ViewModel; + +namespace LoggingClient.Container +{ + public class Builder + { + public static IContainer BuildAutofacContainer() + { + var builder = new ContainerBuilder(); + + // ViewModel + builder.RegisterType().As(); + builder.RegisterType().As(); + builder.RegisterType().As(); + builder.RegisterType().As(); + + + // Repositories + builder.RegisterType().As>(); + builder.RegisterType().As>(); + builder.RegisterType().As>(); + builder.RegisterType().As>(); + builder.RegisterType().As>(); + + return builder.Build(); + } + } +} diff --git a/LoggingClient/LoggingClient/LoggingClient.csproj b/LoggingClient/LoggingClient/LoggingClient.csproj index cd4372b..be7aa1c 100644 --- a/LoggingClient/LoggingClient/LoggingClient.csproj +++ b/LoggingClient/LoggingClient/LoggingClient.csproj @@ -100,6 +100,7 @@ MSBuild:Compile Designer + Inventar.tt diff --git a/LoggingClient/LoggingClient/MainWindow.xaml.cs b/LoggingClient/LoggingClient/MainWindow.xaml.cs index e6f56ce..dd8d708 100644 --- a/LoggingClient/LoggingClient/MainWindow.xaml.cs +++ b/LoggingClient/LoggingClient/MainWindow.xaml.cs @@ -1,4 +1,4 @@ -using System.Windows; +using System.Windows; using LoggingClient.ViewModel; namespace LoggingClient @@ -6,12 +6,14 @@ namespace LoggingClient /// /// Interaction logic for MainWindow.xaml /// - public partial class MainWindow : Window - { + public partial class MainWindow : Window + { public MainWindow() { InitializeComponent(); - this.DataContext = new NavigationViewModel(); - } - } + //Container = Builder.BuildAutofacContainer(); + //DataContext = Container.Resolve(); + DataContext = new NavigationViewModel(); + } + } } \ No newline at end of file diff --git a/LoggingClient/LoggingClient/Repository/CustomerRepositoryEF.cs b/LoggingClient/LoggingClient/Repository/CustomerRepositoryEF.cs index a78b8f6..348f671 100644 --- a/LoggingClient/LoggingClient/Repository/CustomerRepositoryEF.cs +++ b/LoggingClient/LoggingClient/Repository/CustomerRepositoryEF.cs @@ -6,7 +6,7 @@ using System.Linq; namespace LoggingClient.Repository { - public class CustomerRepositoryEF + public class CustomerRepositoryEF : IRepositoryBase { public CustomerRepositoryEF() { diff --git a/LoggingClient/LoggingClient/ViewModel/NavigationViewModel.cs b/LoggingClient/LoggingClient/ViewModel/NavigationViewModel.cs index 830c2c1..c2c3876 100644 --- a/LoggingClient/LoggingClient/ViewModel/NavigationViewModel.cs +++ b/LoggingClient/LoggingClient/ViewModel/NavigationViewModel.cs @@ -1,8 +1,9 @@ -using LoggingClient.Repository; +using LoggingClient.Container; using LoggingClient.ViewModel.Commands; -using System; using System.ComponentModel; using System.Windows.Input; +using Autofac; +using IContainer = Autofac.IContainer; namespace LoggingClient.ViewModel { @@ -18,26 +19,27 @@ namespace LoggingClient.ViewModel get => _selectedViewModel; set { _selectedViewModel = value; OnPropertyChanged("SelectedViewModel"); } } - + private IContainer container; public NavigationViewModel() { LogsCommand = new BaseCommand(OpenLogs); LocationsCommand = new BaseCommand(OpenLocations); CustomersCommand = new BaseCommand(OpenCustomers); + container = Builder.BuildAutofacContainer(); } private void OpenLogs(object obj) { - SelectedViewModel = new LogViewModel(); + SelectedViewModel = container.Resolve(); } private void OpenLocations(object obj) { - SelectedViewModel = new LocationViewModel(); + SelectedViewModel = container.Resolve(); } private void OpenCustomers(object obj) { - SelectedViewModel = new CustomerViewModel(); + SelectedViewModel = container.Resolve(); } public event PropertyChangedEventHandler PropertyChanged;