这个问题我早些得到帮助:
I got help earlier with this question:
Ninject:激活字符串时出错
@nemensv解决了一个问题,但是我立即获得了有关IntPtr的新例外. (请参见下面的激活路径).
@nemensv solved that one but I immediatley got a new exception regarding IntPtr. (see activation path below).
开始浏览ctor 此处
此行中只有IntPtr显示的地方:
Only place IntPtr shows up is in this line:
Result r = Platform.SQLiteApi.Open(databasePathAsBytes, out handle, (int)openFlags, IntPtr.Zero);如何使用ninject解决这个问题?
How can I solve this using 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中的代码:
My code in Ninject:
Bind<SQLiteConnection>() .ToSelf() .WithConstructorArgument("databasePath", path); Bind<ISQLitePlatform>().To<SQLitePlatformWinRT>(); Bind<IBlobSerializer>().To<BlobSerializerDelegate>();谢谢!
这对我有用:
Bind<SQLiteConnection>().ToMethod(ctx => new SQLiteConnection(new SQLitePlatformWP8(), path));
推荐答案ninject指出,由于不知道如何实例化BlobSerializerDelegate+SerializeDelegate,因此无法创建BlobSerializerDelegate.您可能需要告诉ninject如何创建BlobSerializerDelegate-甚至有必要-或告诉它如何实例化SQLiteConnection. 我认为对于给定的情景,ToMethod绑定将是最佳选择:
As ninject states it can't created an BlobSerializerDelegate because it doesn't know how to instanciated a BlobSerializerDelegate+SerializeDelegate. You either need to tell ninject how to created BlobSerializerDelegate - if that's even necessary - or tell it how to instanciate the SQLiteConnection. I think for the given situtation the ToMethod binding would be best:
Bind<SQLiteConnection>().ToMethod(ctx => new SQLiteConnection(...));ToMethod操作应该像没有DI容器一样只是new SQLiteConnection.
The ToMethod action should just new the SQLiteConnection as you would without a DI container.
更多推荐
Ninject:将依赖IntPtr注入构造函数的参数方法
发布评论