質問編集履歴

2

インターフェース等を記載

2022/02/23 04:24

投稿

neko_usagi
neko_usagi

スコア10

test CHANGED
File without changes
test CHANGED
@@ -93,4 +93,47 @@
93
93
  }
94
94
  ```
95
95
 
96
+ IEmployeeService.cs
97
+ ```C#
98
+ using EES.Database.Entities;
99
+ using System;
100
+ using System.Collections.ObjectModel;
101
+
102
+ namespace EES.Services.Interfaces
103
+ {
104
+ public interface IEmployeeService
105
+ {
106
+ ObservableCollection<DtEmployee> GetEmployees();
107
+ }
108
+ }
109
+ ```
110
+
111
+ EmployeeService.cs
112
+ ```C#
113
+ namespace EES.Service
114
+ {
115
+ public class EmployeeService : IEmployeeService
116
+ {
117
+
118
+ private readonly ITransactionContext _transactionContext;
119
+
120
+ public EmployeeService(ITransactionContext transactionContext)
121
+ {
122
+ _transactionContext = transactionContext;
123
+ }
124
+
125
+ public ObservableCollection<DtEmployee> GetEmployees()
126
+ {
127
+ ObservableCollection<DtEmployee> list = new ObservableCollection<DtEmployee>();
128
+
129
+ list.Add(new DtEmployee() { EmployeeId = 1, Name = "¼–{X" });
130
+ list.Add(new DtEmployee() { EmployeeId = 2, Name = "ŽR“cX" });
131
+
132
+ return list;
133
+
134
+ }
135
+ }
136
+ }
137
+ ```
138
+
96
139
  よろしくお願いいたします。

1

必要コードのみ記載

2022/02/23 04:22

投稿

neko_usagi
neko_usagi

スコア10

test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,4 @@
1
- **_《困っていること》
1
+ 《困っていること》
2
2
  prism full appを参考に、インターフェースを自作し、ViewModelにDI注入したいが、うまくいかない。
3
3
 
4
4
  《やりたいこと》
@@ -22,7 +22,75 @@
22
22
  ・IEmployeeServiceをコンストラクタの引数に指定することで、コンストラクタ内を通らなくなる。
23
23
  ・IEmployeeServiceを消すと、コンストラクタは実行される。
24
24
 
25
- コードは以下です。
25
+ コードは以下です。
26
- https://github.com/neko-usagi/EES
27
26
 
27
+ app.xaml.cs
28
+ ```C#
29
+ namespace EES
30
+ {
31
+ /// <summary>
32
+ /// Interaction logic for App.xaml
33
+ /// </summary>
34
+ public partial class App
35
+ {
36
+ protected override Window CreateShell()
37
+ {
38
+ return Container.Resolve<MainWindow>();
39
+ }
40
+
41
+ protected override void RegisterTypes(IContainerRegistry containerRegistry)
42
+ {
43
+ containerRegistry.RegisterSingleton<IEmployeeService, EmployeeService>();
44
+ }
45
+
46
+ protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog)
47
+ {
48
+ moduleCatalog.AddModule<EmployeeInfoModule>();
49
+ }
50
+ }
51
+ }
52
+ ```
53
+ EmployeeInfoModule.cs
54
+ ```C#
55
+ namespace EES.Modules.EmployeeInfo
56
+ {
57
+ public class EmployeeInfoModule : IModule
58
+ {
59
+ private readonly IRegionManager _regionManager;
60
+
61
+ public EmployeeInfoModule(IRegionManager regionManager)
62
+ {
63
+ _regionManager = regionManager;
64
+ }
65
+
66
+ public void OnInitialized(IContainerProvider containerProvider)
67
+ {
68
+ _regionManager.RequestNavigate(RegionNames.ContentRegion, "EmployeeList");
69
+ }
70
+
71
+ public void RegisterTypes(IContainerRegistry containerRegistry)
72
+ {
73
+ containerRegistry.RegisterForNavigation<EmployeeList>();
74
+ }
75
+ }
76
+ }
77
+ ```
78
+
79
+ EmployeeListViewModel.cs
80
+ ```C#
81
+ namespace EES.Modules.EmployeeInfo.ViewModels
82
+ {
83
+ public class EmployeeListViewModel : RegionViewModelBase
84
+ {
85
+ public EmployeeListViewModel(IRegionManager regionManager, IEmployeeService employeeService) : base(regionManager)
86
+ {
87
+ this.EmployeeList.Add(new DtEmployee() { EmployeeId = 1, Name = "¼–{" });
88
+ this.EmployeeList.Add(new DtEmployee() { EmployeeId = 2, Name = "ŽR“c" });
89
+ }
90
+
91
+ public ReactiveCollection<DtEmployee> EmployeeList { get; set; } = new ReactiveCollection<DtEmployee>();
92
+ }
93
+ }
94
+ ```
95
+
28
- よろしくお願いいたします。_**
96
+ よろしくお願いいたします。