Please see the Autowire registration section in the IOC wiki docs. This just registers a singleton instance, since you're passing in an existing instance the IOC is not able to control the creation of the type:
container.Register(new TodoRepository());
If you want it auto-wired, you need to use one of the auto-wired APIs:
container.RegisterAutoWired<TodoRepository>();
container.RegisterAutoWiredAs<TodoRepository,ITodoRepository>();
container.RegisterAs<TodoRepository,ITodoRepository>(); //shorter alias
container.RegisterAutoWiredType(typeof(MyType));
container.RegisterAutoWiredType(typeof(MyType),typeof(IMyType));
container.RegisterAutoWiredTypes(typeof(MyType),typeof(MyType2),typeof(MyType3));
Or you can manually control the creation of your instance by specifying a factory method:
container.Register(c => new TodoRepository {
DbFactory = c.Resolve<IDbConnectionFactory>()
});
If you want to inject an IDbConnection
instead make sure it's in Request
or None
Scope:
container.Register<IDbConnection>(c =>
c.Resolve<IDbConnectionFactory>().OpenDbConnection()
)
.ReusedWithin(ReuseScope.Request);