Search code examples
c#dependency-injectionninjectinversion-of-controlioc-container

How to combine BindBase() with BindAllInterfaces()?


Can we combine BindBase() with BindAllInterfaces() to some Factory ?

kernel.Bind(x =>
    {
        x.FromThisAssembly()
         .SelectAllClasses()
         .WithAttribute<SomeAttribute>()
         .BindBase();
    });

and

  kernel.Bind(x =>
        {
            x.FromThisAssembly()
             .SelectAllClasses()
             .WithAttribute<SomeAttribute>()
             .BindAllInterfaces();
        });

Solution

  • .BindSelection((t, baseTypes) =>
        baseTypes.Where(bt => bt.IsInterface || bt == t.BaseType))