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

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -