0

I want to access the IoC Container from the FinishedLoading and the RegisteredForRemoteNotifications/OpenUrl functions in the App Delegate, is this possible?

I tried to access the container after the App was initialised in the Finishedloading function but it throws an error saying it's unable to resolve.

    public override bool FinishedLaunching(UIApplication app, NSDictionary options)
    {
        global::Xamarin.Forms.Forms.Init();

        var iosApp = new App(new iOSInitializer());

        LoadApplication(iosApp);

        var container = iosApp.Container;

        _appModel = container.Resolve<IAppModel>();
        _configuration = container.Resolve<IConfiguration>();
        _notificationService = container.Resolve<INotificationService>();

        return base.FinishedLaunching(app, options);
    }
Jjohnny
  • 21
  • 2
  • `it throws an error saying it's unable to resolve` that's intentional to prevent people from light-heartedly making what is most of the times a grave mistake (using the container anywhere but at the resolution root). – Haukinger Jun 01 '20 at 08:12
  • there's actually no reason that shouldn't work... completely different story as to whether or not it's really something you should be doing... @Jjohnny can you provide more context as to what the error is that you're getting – Dan Siegel Jun 01 '20 at 18:35

1 Answers1

0

Adding DryIoc namespace worked for me.

using DryIoc;