2

I am unable to use Portable.Ninject in Xamarin.Mac project.

I am creating a container like this:

public class MainClass
{
    public static StandardKernel Container { get; set; }

    static void Main(string[] args)
    {
        var kernel = new StandardKernel(new CoreModule());           

        Container = kernel;

        NSApplication.Init();
        NSApplication.Main(args);
    }
}

CoreModule is this:

public class CoreModule: NinjectModule
{
    public override void Load()
    {
        Bind<ISettings>().To<EyeLeoSettings>().InSingletonScope ();
    }
}

And when I am trying to use it in AppController constructor as a service-locator:

private ISettings _settings;

public AppController()
{
    _settings = MainClass.Container.Get<ISettings> ();
}

I get NullReferenceException. Here are a few lines from a stack trace:

System.NullReferenceException: Object reference not set to an instance of an object at at Ninject.Infrastructure.Language.ExtensionsForMemberInfo.get_ParentDefinitionMethodInfo () at at Ninject.Infrastructure.Language.ExtensionsForMemberInfo.GetParentDefinition (System.Reflection.MethodInfo,System.Reflection.BindingFlags) ...

Please let me if using Portable.Ninject is possible in Xamarin.Mac applications. Thank you.

Maxim V. Pavlov
  • 10,303
  • 17
  • 74
  • 174
  • I'm having the same issue with the same stack trace under Mono 3.2.8 on Ubuntu 14.04.1 (Mono JIT Compiler 3.2.8), any ideas? – user1454265 Oct 13 '14 at 20:06
  • It didn't work. I used TinyIOC and am using it happily ever after. Ninject has nothing to offer for my Xamarin project that ti can't. – Maxim V. Pavlov Oct 14 '14 at 13:01

0 Answers0