What options do I have for automating bindings using NInject

Instead of manually binding each class, what methods and templates, if any, are recommended for automatically setting up bindings?

For example, the vast majority of bindings simply look like this:

Bind<ICustomerRepository>.To<CustomerRepository>(); 

After the modules become large, you can get 100s of bindings that look exactly the same. Could this be automated?

+7
source share
1 answer

check the legend extension: https://github.com/ninject/ninject.extensions.conventions

  using (IKernel kernel = new StandardKernel()) { var scanner = new AssemblyScanner(); scanner.From(Assembly.GetExecutingAssembly()); scanner.BindWith<DefaultBindingGenerator>(); kernel.Scan(scanner); var instance = kernel.Get<IDefaultConvention>(); instance.ShouldNotBeNull(); instance.ShouldBeInstanceOf<DefaultConvention>(); } 
+7
source

All Articles