开发者

How to add mycustom object to Ninject for IoC handling

I have an configuration object that I store in the database. When the app开发者_如何转开发lication starts I want to reconstitute the object from the database then have Ninject control it's lifecycle. For example "InSingletonScope" and when ever another object requests this object it will come from the Ninject kernel.

Something like:

Bind(myInstance).ToSelf().InSingletonScope();


You have several options

  1. Bind<IFoo>().ToConstant(foo) if the object is known at the time you create the binding
  2. Bind<IFoo>().ToMethod(ctx => SomeCallToCreateToObject())
  3. Bind<IFoo>().ToProvider<FooProvider>() and implement your own provider
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜