Is this the best practice for injecting a class dependency into a repository? Bear in mind that other repositories will need this PetaPoco.Database instance as I want each repository to use a shared database connection object.
public class ConfigRepository : IConfigRepository
{
private Database DB;
public ConfigRepository(PetaPoco.Database db)
{
DB = db;
}
}
//Here is how structuremap is configured
ObjectFactory.Initialize(x =>
{
x.Scan(scan =>
{
scan.TheCallingAssembly();
scan.WithDefaultConventions();
scan.AddAllTypesOf<IController>();
});
x.Register<PetaPoco.Database>(new PetaPoco.Database("DBConnection"));
x.For<IConfigRepository>().Use<ConfigRepository>();
});
return ObjectFactory.Container;