ninject - Named binding - MVC3 -
i'm trying register implementations of same interface using named instances
kernel.bind<irepository>().to<cachedrepository>().insingletonscope(); kernel.bind<irepository>().to<dbrepository>().insingletonscope().named("db");
the idea, if not specify name cachedrepository gets created, if need db oriented 1 i'd use named attribute, miserable fails when simple object created
public class tripmanagercontroller : controller { [inject] public irepository repository { get; set; } // default cached repo must created public tripmanagercontroller() { viewbag.logedemail = "test@test.com"; } }
the error is
error activating irepository more 1 matching bindings available. activation path: 2) injection of dependency irepository parameter repository of constructor of type tripmanagercontroller 1) request tripmanagercontroller
suggestions: 1) ensure have defined binding irepository once.
is there way achieve want without creating new interface bd oriented repositories? thx
the [named]
attribute as shown in wiki should work.
btw stay away other ctor injection!
Comments
Post a Comment