This is a follow on question from How to register multiple IDbConnectionFactory instances using Funq in ServiceStack.net
I need to do the same (have one service access different db connections) - but the answers on the above-mentioned stackoverflow discussion don't completely make sense to me (and SO wouldn't let me add comments).
Does it mean, that you cannot use an implementation of a dependancy class eg IDbConnectionFactory (OrmLiteConnectionFactory) more than once per service? So if you need to use more than one, you need to create new implementations of it (for no other reason than to get a unique class name)?
I had hoped that, that was what the name parameter (in the container.Register method) was for (for identifying additional instances of the same class). Eg It would be handy if you could have something like this: container.Register("Db_1", c => new OrmLiteConnectionFactory(connString1, SqlServerOrmLiteDialectProvider.Instance)); container.Register("Db_2", c => new OrmLiteConnectionFactory(connString2, SqlServerOrmLiteDialectProvider.Instance)); Then to use each connection within your service like this: Db["DB_1"].Select... Db["DB_2"].Select or Db_1.Select.. Db_2.Select...
Call me lazy, but writing a class for no other purpose than to get a new type name (because it's 100% inheriting with no additional properties/methods) seems redundant.
I'm assuming I'm missing some crucial point of IoC/DI so would appreciate someone setting me straight.
Thanks Tim