Skip to content

Commit a37054d

Browse files
committed
add autofac and mvvmc support
1 parent 4929214 commit a37054d

31 files changed

+521
-134
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using MaSchoeller.Extensions.Desktop.Mvvm;
2+
using MaSchoeller.Extensions.Desktop.Sample1.ViewModels;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace MaSchoeller.Extensions.Desktop.Sample1.Controllers
10+
{
11+
public class Page1Controller : ControllerBase
12+
{
13+
public readonly Page1ViewModel _viewModel;
14+
public Page1Controller(Page1ViewModel viewModel)
15+
{
16+
_viewModel = viewModel;
17+
}
18+
19+
20+
public override object Initialize()
21+
{
22+
_viewModel.Property = 30;
23+
return _viewModel;
24+
}
25+
}
26+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using MaSchoeller.Extensions.Desktop.Mvvm;
2+
using MaSchoeller.Extensions.Desktop.Sample1.ViewModels;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace MaSchoeller.Extensions.Desktop.Sample1.Controllers
10+
{
11+
public class Page2Controller : ControllerBase
12+
{
13+
public readonly Page2ViewModel _viewModel;
14+
public Page2Controller(Page2ViewModel viewModel)
15+
{
16+
_viewModel = viewModel;
17+
}
18+
19+
20+
public override object Initialize()
21+
{
22+
_viewModel.Test = "some other string";
23+
return _viewModel;
24+
}
25+
}
26+
}

src/Desktop/MaSchoeller.Extensions.Desktop.Sample1/CustomeService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66
namespace MaSchoeller.Extensions.Desktop.Sample1
77
{
8-
public class CustomeService : IHostedService
8+
public class CustomService : IHostedService
99
{
1010
private readonly ISplashscreenWindow _splashscreen;
1111

12-
public CustomeService(
12+
public CustomService(
1313
ISplashscreenWindow splashscreen,
1414
IHostApplicationLifetime lifetime)
1515
{

src/Desktop/MaSchoeller.Extensions.Desktop.Sample1/Program.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
using Microsoft.Extensions.DependencyInjection;
66
using Microsoft.Extensions.Hosting;
77
using System.Threading.Tasks;
8+
using Autofac.Extensions.DependencyInjection;
9+
using Autofac;
10+
using MaSchoeller.Extensions.Desktop.Sample1.Controllers;
811

912
namespace MaSchoeller.Extensions.Desktop.Sample1
1013
{
@@ -14,18 +17,22 @@ class Program
1417
static async Task Main(string[] args)
1518
{
1619
await Host.CreateDefaultBuilder(args)
20+
.UseAutoFac()
21+
.UseMVVMC()
1722
.ConfigureSplashscreen<SplashscreenWindow>()
1823
.ConfigureDesktopDefaults<ShellWindow>(b =>
1924
{
20-
b.ConfigureServices((services) =>
25+
b.UseStartup<Startup>();
26+
b.ConfigureContainer(builder =>
2127
{
22-
services.AddSingleton<ShellViewModel>();
23-
services.AddHostedService<CustomeService>();
28+
builder.RegisterType<Page1ViewModel>();
29+
builder.RegisterType<Page2ViewModel>();
30+
2431
});
25-
b.ConfigureNavigation((nav) =>
32+
b.ConfigureNavigation(nav =>
2633
{
27-
nav.AddRoute<Page1, Page1ViewModel>(NavigationService.DefaultRoute);
28-
nav.AddRoute<Page2, Page2ViewModel>("other");
34+
nav.AddRoute<Page1, Page1Controller>(Navigation.DefaultRoute);
35+
nav.AddRoute<Page2, Page2Controller>("other");
2936
});
3037
})
3138
.Build()
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Autofac;
2+
using MaSchoeller.Extensions.Desktop.Sample1.ViewModels;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace MaSchoeller.Extensions.Desktop.Sample1
10+
{
11+
public class Startup
12+
{
13+
public void ConfigureContainer(ContainerBuilder builder)
14+
{
15+
builder.RegisterType<TestClass>();
16+
builder.RegisterType<ShellViewModel>();
17+
}
18+
19+
}
20+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace MaSchoeller.Extensions.Desktop.Sample1
8+
{
9+
public class TestClass
10+
{
11+
}
12+
}

src/Desktop/MaSchoeller.Extensions.Desktop.Sample1/ViewModels/Page1ViewModel.cs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace MaSchoeller.Extensions.Desktop.Sample1.ViewModels
1010
{
11-
public class Page1ViewModel : RoutableBase
11+
public class Page1ViewModel : NotifyPropertyChangedBase
1212
{
1313
public ICommand MyCommand{ get; }
1414
public Page1ViewModel()
@@ -19,16 +19,6 @@ public Page1ViewModel()
1919

2020
}
2121

22-
public int Property { get; set; }
23-
24-
protected override void Enter()
25-
{
26-
27-
}
28-
29-
protected override void Leave()
30-
{
31-
32-
}
22+
public int Property { get; set; } = 10;
3323
}
3424
}
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
using MaSchoeller.Extensions.Desktop.Helpers;
2+
using MaSchoeller.Extensions.Desktop.Mvvm;
23
using System;
34
using System.Collections.Generic;
45
using System.Text;
56

67
namespace MaSchoeller.Extensions.Desktop.Sample1.ViewModels
78
{
8-
public class Page2ViewModel : RoutableBase
9+
public class Page2ViewModel : NotifyPropertyChangedBase
910
{
11+
12+
public string Test { get; set; } = "Hallo";
1013
}
1114
}

src/Desktop/MaSchoeller.Extensions.Desktop.Sample1/ViewModels/ShellViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace MaSchoeller.Extensions.Desktop.Sample1.ViewModels
99
{
1010
public class ShellViewModel : NotifyPropertyChangedBase
1111
{
12-
public ShellViewModel(INavigationService navigationService)
12+
public ShellViewModel(INavigationService navigationService, TestClass @class)
1313
{
1414
NavigationCommand = ConfigurableCommand.Create(
1515
o =>

src/Desktop/MaSchoeller.Extensions.Desktop.Sample1/Views/Page1.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
Title="Page1">
1212

1313
<Grid>
14-
14+
<Label Content="{Binding Property}"/>
1515
</Grid>
1616
</Page>

0 commit comments

Comments
 (0)