Strange exception in Prism app

I try to run the Prism application and I get a very strange error:

InvalidOperationException: ServiceLocationProvider must be set.

I use MainWindowin the main (modular host) application as an area for one main shell, which has its own areas. Thus, I can change the layout of the main window, if necessary.

I get an error when called InitializeComponent();, the only line of code in the constructor MainWindow. Google and Bing both return null results for this exact phrase.

XAML element in MainWindow:

<ContentControl regions:RegionManager.RegionName="MainShellRegion" />

Do I need to implement any interface or something on MainWindowto solve this problem? I am completely at a dead end.

+4
source share
2 answers

You need to set up dependency injection for your Prism application, otherwise it will not work. This should be done from inside the bootstrapper , inside ConfigureServiceLocator.

To expand the bit above, Prism is connected so that whenever it needs access to the application component, it does not directly initialize the component (how does it know which implementation to use and how to initialize it?), But rather delegates this work to the service locator .

- , , , . Prism; (, ).

+2

, Prism ServiceLocator. ConfigureServiceLocator. MefBootstrapper UnityBootstrapper , ( ConfigureContainer).

( ) Run .

, , . :

public class App : Application
{
    protected override void OnStartup(StartupEventArgs e)
    {
        var bootstrapper = new MyBootstrapper();
        bootstrapper.Run();
    }
}

.

+1

Source: https://habr.com/ru/post/1529986/


All Articles