我使用portable.ninject 3.3.1并希望通过以下方式访问ninject对象:
public partial class App : Application
{
public IKernel Kernel { get; set; }
public App (params INinjectModule[] platformModules)
{
InitializeComponent();
var mainPage = new NavigationPage(new MainPage());
// Register core services
Kernel = new StandardKernel(new FeruiCoreModule(), new FeruiNavModule(mainPage.Navigation));
// Register platform specific services
Kernel.Load(platformModules);
// Get the MainViewModel from the IoC
mainPage.BindingContext = Kernel.Get<MainViewModel>();
MainPage = mainPage;
}
在“mainPage.BindingContext = Kernel.Get();”我得到:在aot-only模式下运行时尝试JIT编译方法'Ninject.Injection.DynamicMethodInjectorFactory:Create(System.Reflection.ConstructorInfo)'。
我错过了什么?
我也有这个问题。确保您实际使用的是Portable.Ninject。使用Ninject的不可移植版本会导致这个问题,但是一旦我切换到Portable.Ninject并重新整理整个解决方案,问题就会消失。