새 Azure WebJobs 프로젝트에서 Ninject를 사용하고 있습니다. 내 저장소 중 하나를 전달하려면 Db 클라이언트가 필요합니다. 이 클라이언트를 어떻게 통과합니까?
내 바인딩 클래스는 다음과 같습니다.
public class NinjectBindings : Ninject.Modules.NinjectModule
{
public override void Load()
{
Bind<IMyRepository>().To<MyRepository>();
}
}
콘솔 앱의 내 주요 기능은 다음과 같습니다.
static void Main()
{
var kernel = new StandardKernel();
kernel.Load(Assembly.GetExecutingAssembly());
var config = new Configuration();
config.AddJsonFile("appsettings.json");
DbClient _dbClient = new DbClient(config);
IMyRepository myRepository = kernel.Get<IMyRepository>(); // This is where I get an error
}
내 저장소 코드는 DbClient를 기대하는 것과 같습니다.
public class MyRepository : IMyRepository
{
private DbClient _client;
public MyRepository(DbClient client)
{
_client = client;
}
}
DbClient에 대한 바인딩을 설정해야합니다.
구성 요소가 출시 될 때주의를 기울이는 것이 좋습니다. 웹 작업에 대한 좋은 예를 아직 보지 못했기 때문에 수동으로 연결했습니다. 하지만 그건 내 생각 일 뿐이야 ...
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다