Hello tout le monde
J'ai toujours cru qu'on pouvait persister des données dans un DomainService mais ça ne fonctionne pas chez moi.
Un peu de code.
Mon RIA Service:
Côté SL, au niveau du App.xaml.cs:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 EnableClientAccess()] [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] [ServiceBehavior(MaxItemsInObjectGraph = Int32.MaxValue, ConcurrencyMode = ConcurrencyMode.Multiple)] public class CommonDomainService : DomainService { private Int32 userID; [Invoke] public void SetUserID(Int32 userID) { this.userID = userID; } [Invoke] public String HelloWorld(String name) { return "Hello " + name + " - userID: " + userID; } }
Ensuite, au niveau de mon ViewModel
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 public partial class App : Application { private CommonDomainContext commonDomainContext; public CommonDomainContext CommonDomainContext { get { if (commonDomainContext == null) { commonDomainContext = new CommonDomainContext(); } return commonDomainContext; } } private void Application_UserLoaded(LoadUserOperation op) { if (op.Error == null) { CommonDomainContext.SetUserID(23); } else { //... } } }
Et là, je récupère 0 comme userID.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 [Export] [PartCreationPolicy(CreationPolicy.Shared)] public class MainViewModel : DependencyObject, ICommonViewModel { private RiaServices.CommonDomainContext commonDomainContext { get { return App.Current.CommonDomainContext; } } public MainViewModel() { if (!DesignerProperties.IsInDesignTool) { Initialize(); } } // / <summary> // / Initialize all the component needed. // / </summary> private void Initialize() { commonDomainContext.HelloWorld(App.Current.CurrentUser.Name, HelloCompleted, null); } }
Une idée??
PS: en mode débug, je rentre bien dans ma fonction SetUserID(23)
Partager