microsoft / Appsample-Photosharing

Sample code for a UWP photo sharing app.
Other
286 stars 116 forks source link

DesignTime error "ServiceLocationProvider must be set" #35

Closed ToddBonnewell closed 8 years ago

ToddBonnewell commented 8 years ago

Following the documentation I notice I cannot view Design Time data. When I open LeaderboardsPage.xaml I am not seeing the data, just a ListView of categories. In the Error List in Visual Studio it reports:

ServiceLocationProvider must be set

image

image

How can I get some DesignTime data working? Thanks!

ToddBonnewell commented 8 years ago

9 days. Not one comment?

andystumpp commented 8 years ago

Hi @ToddBonnewell, sorry for the delay on this. We might have broken this with one of our latest check-ins. Good finding, here's a solution that brings back the configuration of the dependency container at design time:

Add this class to the PhotoSharing.Universal project:

namespace PhotoSharingApp.Universal.Unity
{
    public class DesignTimeInitializer
    {
        public DesignTimeInitializer()
        {
            if (DesignMode.DesignModeEnabled && UnityBootstrapper.Container == null)
            {
                UnityBootstrapper.Init();
                UnityBootstrapper.ConfigureRegistries();
            }
        }
    }
}

And in Styles.xaml, add following initialization at the beginning of the file:

<unity:DesignTimeInitializer x:Key="DesignTimeInitializer"/>

Once you've configured Unity to load up at design time, it will populate data from the PhotoDummyService, if you're in Debug mode and have the DUMMY_SERVICE compiler directive set.

image

Let me know if you have any questions.

ToddBonnewell commented 8 years ago

Thanks!!!!