私はMVCのもので私の最初のステップにいます。 MVC2 + Windsor Castle(そしてNHibernateも)を使って単純なアプリケーションを作成しようとしています。MVC +ウィンザー城。リポジトリが適切に登録されていない
私はリポジトリに問題があります...これらのリポジトリは登録されていないようですが、私は少し失われています。私はここで質問することにしました。コードを見てみましょう。
リポジトリ、クラス階層について:
public interface ICommonRepository{}
も
public interface IRepository<T> : ICommonRepository
{
IEnumerable<T> FindAll();
}
と
public class BookRepository:IRepository<Book>
{
public IEnumerable<Book> FindAll()
{
throw new NotImplementedException();
}
}
私のサービスについて:
public class BookService:IService
{
private IRepository<Book> _bookRepository;
public BookService(IRepository<Book> repository)
{
this._bookRepository = repository;
}
public IEnumerable<Book>FindAllBooks()
{
return this._bookRepository.FindAll();
}
}
、最終的にはアプリケーション
public class Installer : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
//Repositories
container.Register(AllTypes.FromThisAssembly()
.BasedOn<IService>(ICommonRepository)
.If(t => t.Name.EndsWith("Repository"))
.Configure(c => c.LifestyleTransient()));
//Services
container.Register(AllTypes.FromThisAssembly()
.BasedOn<IService>()
.If(Component.IsInSameNamespaceAs<BookService>())
.If(t => t.Name.EndsWith("Service"))
.Configure(c => c.LifestyleTransient()));
//Controllers
container.Register(AllTypes.FromThisAssembly()
.BasedOn<IController>()
.If(Component.IsInSameNamespaceAs<HomeController>())
.If(t => t.Name.EndsWith("Controller"))
.Configure(c => c.LifestyleTransient()));
}
}
だから... ...に作成されたすべてのものを登録するtrys私の「ウィンザーのインストーラ」私はBookController上のsomethinを要求しようとすると、私はエラーを以下の取得:
Can't create component 'Example_MVC.Services.BookService' as it has dependencies to be satisfied.'Example_MVC.Services.BookService' is waiting for the following dependencies: - Service 'Example_MVC.Repositories.IRepository`1[[Example_MVC.Class.Book, Example_MVC, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' which was not registered.
面白いことに、リポジトリが "潜在的に誤って構成されたコンポーネント"に表示されるので、このリポジトリが追加されていないか、エラーだけが別の場所にあるかどうかはわかりません。
アイデア?お時間を
おかげ
敬具
このリンク、Krysztofに感謝します。あなたはおそらく笑っていますが、私は登録に関するすべての可能性を要約したこのページを見つけることができませんでした。私はこの新しいリポジトリにリポジトリを登録する方法を変更しました: container.Register(Classes.FromThisAssembly( ).BasedOn(typeof(IRepository <>))。WithService.Base()); これですべてが機能しています。あなたの助けに感謝し、愚かな質問を申し訳ありません – JTH