2012-04-18 4 views
1

私はいくつかのリポジトリを持っています。それらの作業は、インタフェースIRepositoryによって実現されます。
sample projectHomeControllerコンストラクタがISessionで実現されました。私がこれを書きました:IRepository対ISession

public class TestingController : Controller 
{ 
    private ISession session; 

    public TestingController(ISession session) 
    { 
     this.session = session; 
    } 
//Some code here with this.session 
} 

それはうまくいきます。私が使用することを決めたときIRepository

public class TestingController : Controller 
{ 
    private IRepository repository; 

    public TestingController(IRepository repository) 
    { 
     this.repository = repository; 
    } 
//Some code here with this.repository 
} 
それは他のクラス WindsorControllerFactoryのこの方法では動作しません

protected override IController GetControllerInstance(System.Web.Routing.RequestContext requestContext, Type controllerType) 
    { 
     if (controllerType == null) 
     { 
      throw new HttpException(404, string.Format("The controller for path {0} culd not found!", requestContext.HttpContext.Request.Path)); 
     } 

     return (IController)this.kernel.Resolve(controllerType); 
    } 

私が持っている例外

コンポーネントを作成できません「MvcApplication1 .Controllers.ResultsController 'には依存関係があります。

「MvcApplication1.Controllers.ResultsControllerは」 次の依存を待っています: - 登録されていなかったサービス「dal.Repository.IRepository」を。

どのように解決するのですか?

P.S.アセンブリdal.Repositoryが動作しています。もし私がどこでも書いたらthis.repositoryの代わりにnew dal.Repository.Repository() - それは働いています。

答えて

3

IRepositoryのバインディングが不足しているようです。

IRepositoryインターフェイスを実装する具体的なクラス、たとえばMyRepositoryが必要です。次に、IRepositoryが何であるかを理解するためにウィンザーを設定する必要があります。

このDocumentation

と別のものに従うことによって、同じ問題を解決することができ

container.Register(Component.For<IRepository>().ImplementedBy<MyRepository>()); 
+1

IT WORKS !!!))) ありがとうございました)私にとっては難しい - これを理解すること) – LuckSound

0

何かのように、私たちはgithubのからこのプロジェクトの新しいバージョンをダウンロードした場合、我々は、このexpcetionは表示されませんですLink

関連する問題