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
Bind<IFoo>().ToConstant(foo)
if the object is known at the time you create the bindingBind<IFoo>().ToMethod(ctx => SomeCallToCreateToObject())
Bind<IFoo>().ToProvider<FooProvider>()
and implement your own provider
精彩评论