1

I have this interface:

   public interface IObjectFactory<T>
   {
      T NewObject();
   }

and I could have multiple classes that implement this interface with a different paramenter like this

   public class UserFactory : IObjectFactory<IUser>
   {
      public IUser NewObject() => new User(); 
   }

I would like to scan all the assemblies for binding all the classes so I can use without to create a direct binding instruction.
The problem I have is a generic interface and normal samples don't work.
How can I solve this?

Jan Muncinsky
  • 4,282
  • 4
  • 22
  • 40
Luca Morelli
  • 2,530
  • 3
  • 28
  • 45

1 Answers1

1

Use ninject.extensions.conventions.

kernel.Bind(
    c => c.FromThisAssembly()
        .SelectAllClasses()
        .InheritedFrom(typeof(IObjectFactory<>))
        .BindAllInterfaces());
Jan Muncinsky
  • 4,282
  • 4
  • 22
  • 40