DbContext (つまり、AdventureworksDB) をコンストラクターのパラメーターとして受け取るリポジトリ RepositoryDepartment があります。
public class RepositoryDepartment : Repository<Department>, IRepositoryDepartment
{
AdventureWorksDB _ctx;
public RepositoryDepartment(AdventureWorksDB dataContext)
: base(dataContext)
{
_ctx = dataContext;
}
Unity DIpublic interface IRepositoryDepartment : IRepository<Department>
を使用して をマッピングしました。RepositoryDepartment
したがって、次のように IRepositoryDepartment インターフェイスを解決すると:
Container.Resolve<IRepositoryDepartment>()
完全に機能する RepositoryDepartment オブジェクトを取得します。しかし、ここでの質問は次のとおりです。AdventureworksDB コンストラクター パラメーターはどのようにインスタンス化されるのでしょうか?型をどこにも登録していないのでしょうか? 基本クラスはオブジェクトを取得するだけで、インスタンス化ロジックはありません! ここで起こる魔法を誰か説明できる!?