Dishan Samarawickrama
Dishan Samarawickrama

Reputation: 159

ninject convention based bindings not working when using different namespaces

I'm trying to keep a single ninject load() method in my solution and trying to use convention based bindings. Below is my class hierarchy. AccountTypes and PaymentTypes are separate namespaces in the same project. they are all public classes and interfaces.

AccountTypes
  IAccountTypes
  AccountTypeA
  AccountTypeB

PaymentTypes
  IPaymentTypes
  PaymentTypeA
  PaymentTypeB

I have a class where I have overriden the ninject Load() method Like below.

public class NinjectLoader : NinjectModule
{
        public override void Load()
        {
            Kernel.Bind(x => x
             .FromThisAssembly()
             .SelectAllClasses()
             .InheritedFrom<IAccountTypes>()
             .BindAllInterfaces());

           Kernel.Bind(x => x
             .FromThisAssembly()
             .SelectAllClasses()
             .InheritedFrom<IPaymentTypes>()
             .BindAllInterfaces());
        }
}

When load() method is run and when the below constructor is called accountTypes is still empty.

private readonly IEnumerable<IAccountTypes> _accountTypes;

        public OtherDeliveryMethodWorkflow(IEnumerable<IAccountTypes> accountTypes)
        {
            _accountTypes = accountTypes;
        }

I have already got these working with ninject bindings but I need to do this via conventions since my code will expand over the time and binding each class to interface is not a good solution.

Upvotes: 1

Views: 174

Answers (0)

Related Questions