How can I declare ninject 3 to use the default Singleton scope for all types?

I want my application to always use services as singlets, how to configure Ninject to use the default Singleton scope. I use conventions to register my types, do I need to use the Bind <> method?

+5
source share
1 answer

Hy, Assuming all your services are inherited from IService, you can write the following

Add the following statement

using Ninject.Extensions.Conventions;

Use conventions like

kernel.Bind( x => x
.FromThisAssembly()
.SelectAllClasses().InheritedFrom<IService>()
.BindAllInterfaces()
.Configure(b => b.InSingletonScope()));

You may need to tweak it a little to your needs.

+8
source

All Articles