Hello World with Microsoft Acropolis - Part Two: Services Dependencies
In my previous sample I showed how to create a Hello World sample using Microsoft Acropolis. Here we will modify that sample to use a service to retrieve the Hello World message.
- Download and open the previous sample. (AcropolisHelloWorld.zip).
- Add an interface called IMessageService.
- Add a class to implement the preceding interface. This class also has to inherit from the ServiceBase class and needs to be decorated with the [ServiceProduction] attribute. Name it MessageService.
- Open HelloWorldPart.xaml. In the User ConnectionPoints (Acropolis) tab, you will see your service interface, double click to add it as a service dependency. Notice the warning icon for the service dependency, which indicates that the dependency must be fulfilled before the part will be functional.
- Rename the service dependency to MessageService.
- Open HelloWorldPart.cs (the HelloWorldPart.xaml code-behind) and modify the OnShowMessage method in order to use the service to retrieve the message
- Open Application.xaml. In the User Components (Acropolis) tab, you will see your service, double click to add it to fulfills the service dependency of the child HelloWorldPart. Notice that the warning icons have been replaced with check marks.
- Build and run the solution. Click on the triangle to see the list of commands. Select ShowMessageCommand.
My idea was to finish the sample here, but I have received good feedback from Alex Bulankou (Microsoft Corporation), so I’m going to implement what he points me. We are going to change the way we display the message. Instead of using a WPF MessageBox, we are going to use the Acropolis UIService. Why? Alex explained me that this service is used by the Acropolis Framework to show our MessageBox whatever platform it’s running on. Now our MessageBox is platform-agnostic!.
- Open the HelloWorldPart.xaml. Double click over the IUIService Dependency in the Acropolis Framework tab to add a dependency to this service (same as we did in the step 4).
- Rename the service dependency to UIService.
- Open HelloWorldPart.cs (the HelloWorldPart.xaml code-behind) and modify the OnShowMessage method in order to use the UIService to retrieve the message.
- Build, run and enjoy!
Source code
- You can get the source code of the Hello World sample by downloading the AcropolisHelloWorld-Part2.zip file below.
- Important: The code is provided "as is" without warranty of any kind.
Attachment: AcropolisHelloWorld-Part2.zip