Reputation: 3718
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?
Upvotes: 5
Views: 1740
Reputation: 2314
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.
Upvotes: 8