Toine db
Toine db

Reputation: 779

How to only use IOC container from MVVMCross

I'm working on a existing Windows Phone project and want to use the IOC container from MVVMCross, but not the other extra features (yet).

I installed MVVMCross.Core 4.x and try to use 'ConstructAndRegisterSingleton' from the App() constructor of the Windows app, but it throws an Null ref exception.

Tried to find any bootstrapper, setup or initialization for MVVMCross but can't find any in the new 4.x core.

Anyone any idea?

Upvotes: 1

Views: 560

Answers (1)

Toine db
Toine db

Reputation: 779

Found it.... and it seems to work.

Just get MVVMCross.Core from Nuget and create a setup like:

internal static class Setup
{
    public static void InitializeIoc()
    {
        CreateIocProvider();

        // Register all services
        Mvx.ConstructAndRegisterSingleton<ILoudnessLimitsRegulator, LoudnessLimitsRegulator>();
    }

    private static void CreateIocProvider()
    {
        // Ioc options
        var options = new MvxIocOptions();

        // initialize the IoC registry, then add it to itself
        var iocProvider = MvxSimpleIoCContainer.Initialize(options);
        Mvx.RegisterSingleton(iocProvider);
    }
}

Upvotes: 2

Related Questions