Getting to grips with Ninject and at the moment and I have the Ninject configuration in my MVC application (which I want to figure out how not to do, but that is a different question).
I have several other working configurations, but I don't know how to set it up with PetaPoco.
These are two ways I've tried:
Bind<PetaPoco.Database>().ToConstructor(
context => new PetaPoco.Database("connectionStringName")
).InSingletonScope();
Bind<PetaPoco.Database>().ToMethod(
context =>
{
var db = new PetaPoco.Database("connectionStringName");
return db;
}
).InSingletonScope();
The error I get:
Error activating Database using implicit self-binding of Database
Several constructors have the same priority. Please specify the constructor using ToConstructor syntax or add an Inject attribute.
Constructors:
Database(string connectionStringstring providerName)
Database(string connectionStringDbProviderFactory provider)
How can I set up binding so that a single instance of PetaPoco is passed around?
UPDATE:
I have just seen a fork of PetaPoco called NPoco which contains an IDatabase interface so maybe this would be the better option?
UPDATE 2
I swapped to NPoco and used the IDatabase interface. Ninject picked it up and passed it through no problem. I now need to think about disposing of the database object.