0

I'm using Ninject in a new Azure WebJobs project. One of my repositories requires a Db client to be passed. How do I pass this client?

My bindings class is:

public class NinjectBindings : Ninject.Modules.NinjectModule
{
   public override void Load()
   {
       Bind<IMyRepository>().To<MyRepository>();
   }
}

My Main function in the console app looks like this:

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
}

My repository code is like this which is expecting the DbClient

public class MyRepository : IMyRepository
{
   private DbClient _client;
   public MyRepository(DbClient client)
   {
      _client = client;
   }
}
Sam
  • 26,817
  • 58
  • 206
  • 383

1 Answers1

1

You need to setup a binding for your DbClient.

I'd suggest being cautious around when components are released. I've not seen a good ninject example for web jobs yet so I've wired up manually. But that's just my thoughts...

LightningShield
  • 680
  • 3
  • 13