я получил помощь раньше с этим вопросом:Ninject: Инъекция зависимостей IntPtr в метод параметра конструктора
http://stackoverflow.com/questions/27723011/ninject-error-activating-string/27723071?noredirect=1#comment43864067_27723071
@nemensv решил, что один, но я immediatley получил новое исключение в отношении IntPtr. (см. путь активации ниже).
Искал через ctor
здесь:
https://github.com/oysteinkrog/SQLite.Net-PCL/blob/ecc19e91a94307d4e739c0f08884ff325c4810ae/src/SQLite.Net/SQLiteConnection.cs#L94-L98
Только место IntPtr появляется в этой строке:
Result r = Platform.SQLiteApi.Open(databasePathAsBytes, out handle, (int)openFlags, IntPtr.Zero);
Как я могу решить эту проблему с помощью Ninject?
Полное исключение:
Activation path:
6) Injection of dependency IntPtr into parameter method of constructor
5) Injection of dependency BlobSerializerDelegate+SerializeDelegate into parameter serializeDelegate of constructor
4) Injection of dependency IBlobSerializer into parameter serializer 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 MainViewModel
Мой код в Ninject:
Bind<SQLiteConnection>()
.ToSelf()
.WithConstructorArgument("databasePath", path);
Bind<ISQLitePlatform>().To<SQLitePlatformWinRT>();
Bind<IBlobSerializer>().To<BlobSerializerDelegate>();
Спасибо!
EDIT:
Это работает для меня:
Bind<SQLiteConnection>().ToMethod(ctx => new SQLiteConnection(new SQLitePlatformWP8(), path))
;
Спасибо, что ответили, но я не понимаю. Что такое «...» infront нового BlobSeriaLizerDelegate? До этого момента я получил следующее: Bind(). ToMethod (путь, «путь к базе данных», –
Wranglerino
Параметры ctor - это просто «псевдокод». Вы помещаете там параметры, которые вы хотите/которые определены конструктором 'SQLiteConnection'. – BatteryBackupUnit