I’m building a live sports app and because it’s going to be commercial one, I wanted it to support the trial mode. In my case it was easy to decide on how to restrict the trial version: Instead of showing scores from all of the matches, the trial version shows only first two. Same with news and statistics. I’m using Caliburn.Micro to build the app and building on its features made the adding of the trial mode a really simple task.

Caliburn.Micro has a built-in dependency injection tool called the SimpleContainer and he container is initialized in the AppBootstrapper’s Configure-method. This is also a perfect place to add support for the trial-mode: Instead of always injecting the same services, check if the app is run in the trial mode and if it is, inject the services which are modified to return only a subset of results.

To do this, the first thing required is a method to check if the app is in trial mode. This can be added to the AppBootstrapper.cs:

   1: private static bool isTrial()
   2: {
   3:     return new LicenseInformation().IsTrial();
   4: }

The MSDN has a quite good article about the subject from which you can find more information about the LicenseInformation-class.

The next thing you need to do is to check for that value when adding implementations into the container and insert the correct ones based on the value. It maybe better to keep the check for trial mode in minimum (or at least adding caching to the isTrial-method) because every check for IsTrial-method takes around 60 ms.

   1: // If in trial mode, don't use the full versions of the following services
   2: if (isTrial())
   3: {
   4:     container.RegisterSingleton(typeof(ITeamStatsService), null, typeof(TrialTeamStatsService));
   5:     container.RegisterSingleton(typeof(NewsService), null, typeof(TrialNewsService));
   6:     container.RegisterSingleton(typeof(IPlayerStatsService), null, typeof(TrialPlayerStatsService));
   7:     container.RegisterSingleton(typeof(IScoreService), null, typeof(TrialSimpleScoreService));
   8: }
   9: else
  10: {
  11:     container.RegisterSingleton(typeof(ITeamStatsService), null, typeof(TeamStatsService));
  12:     container.RegisterSingleton(typeof(NewsService), null, typeof(NewsService));
  13:     container.RegisterSingleton(typeof(IPlayerStatsService), null, typeof(PlayerStatsService));
  14:     container.RegisterSingleton(typeof(IScoreService), null, typeof(SimpleScoreService));
  15: }

You can write the trial-versions of your service classes in any way you prefer. I decided to just derive from the full implementation and limit the data they return. For example:

   1: public class TrialSimpleScoreService : SimpleScoreService
   2: {
   3:     public TrialSimpleScoreService(AllMatchesParser parser, IHtmlProvider pageLoader) : base(parser, pageLoader)
   4:     {
   5:     }
   7:     protected override List<GameOverview> CreateResults(List<GameOverview> results)
   8:     {
   9:         if (results.Count < 1)
  10:             return base.CreateResults(results);
  12:         results = results.Take(2).ToList();
  14:         var trialScore = new GameOverview(long.MaxValue, "Trial Mode","Limited to 2 games", 0, 0, "", GameStatus.InProgress);
  15:         results.Add(trialScore);
  17:         return base.CreateEventArgs(results);
  18:     }
  19: }

The trial class removes everything else but the two first items from the list (results.Take(2)) and then adds one new item to the list. This item is shown on the UI to remind the user that the app is running in the trial mode.


And this is all that is required.

To test and debug an app running in the trial mode, I recommend the approach which Eric Malamisura presented in his blog post.