Ninject:激活字符串时出错 [英] Ninject: Error activating string

查看:106
本文介绍了Ninject:激活字符串时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在遵循有关如何设置SQLite的指南.在指南中,他使用如下代码:

Im following a guide of how to setup SQLite. In the guide he uses code-behind like this:

public MainPage()
{
     InitializeComponent();

     // Setup database
     var path = Path.Combine(Path.Combine(ApplicationData.Current.LocalFolder.Path, "test.sqlite"));
     _connection = new SQLiteConnection(new SQLitePlatformWP8(), path); 
}

我正在尝试做同样的事情,而是通过遵循MVVM. 我以为他是要走的路:

Im trying to do the same thing but instead by following MVVM. I thought his would be the way to go:

public override void Load()
{
    var path = Path.Combine(Path.Combine(ApplicationData.Current.LocalFolder.Path, "test.sqlite"));

    Bind<ISQLitePlatform>().To<SQLitePlatformWP8>().WithConstructorArgument("test.sqlite", path);
}

Ninject回应:

Ninject responds with:

No matching bindings are available, and the type is not self-bindable.

Activation path:

  4) Injection of dependency string into parameter databasePath of constructor

  3) Injection of dependency SQLiteConnection into parameter connection of constructor

  2) Injection of dependency ICarRepository into parameter carRepository of constructor

  1) Request for MainVModel

有关如何解决这一问题的任何提示?

Any tips on how to solve this one?

推荐答案

SQLiteConnection需要参数,而不需要SQLitePlatformWP8.

The SQLiteConnection needs the parameter and not the SQLitePlatformWP8.

因此将您的注册更改为:

So change your registration to:

Bind<SQLiteConnection>.ToSelf().WithConstructorArgument("databasePath", path);
Bind<ISQLitePlatform>().To<SQLitePlatformWP8>();

注意:您需要使用正确的参数名称"databasePath",该名称在SQLiteConnection类的

Note: you need to use the correct paramter name "databasePath" which is definied in the SQLiteConnection class's constructor.

这篇关于Ninject:激活字符串时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆