I want my application to always use services as singletons, how do I set up Ninject to use singleton scope by default. I am using conventions to register my types, do I need to use the Bind<> method?
Hy,
Assuming all your services inherit from IService
you can write the following
Add the following using statement
using Ninject.Extensions.Conventions;
Use the conventions like
kernel.Bind( x => x
.FromThisAssembly()
.SelectAllClasses().InheritedFrom<IService>()
.BindAllInterfaces()
.Configure(b => b.InSingletonScope()));
You might need to tweek it a little bit to your needs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With