Problem: NSB won't use our Custom NHB ConnectionProvider.
Im configuring NSB in code with the following setup (log4net is the only thing in the app.config file):
NServiceBus.SetLoggingLibrary.Log4Net(log4net.Config.XmlConfigurator.Configure);
NServiceBus.Configure.With()
.CustomConfigurationSource(ObjectFactory.GetInstance<IConfigurationSource>())
.StructureMapBuilder()
.XmlSerializer()
.DBSubcriptionStorage(GetNHibernateConfiguration(), false)
.MsmqTransport()
.IsTransactional(false)
.PurgeOnStartup(false)
.UnicastBus()
.LoadMessageHandlers( First<MyEventHandler1>
.Then<MyEventHandler2>())
.CreateBus()
.Start();
And this works as long as I do not use DBSubscription storage instead of MSMQ storage. But I need the DBStorage.
Currently we have our own custom ConnectionProvider, which works fine in about 10-15 other projects, but when I try to use it with NSB i get an error which dosent make any sense to me. If I leave out the ConnectionProvider and go with standard NHB then it works just fine.
Custom Provider:
public class MyProvider : DriverConnectionProvider
{
public override IDbConnection GetConnection()
{
var oracleRoleProvider = new OracleRoleProvider();
var dbConnection = Driver.CreateConnection();
return oracleRoleProvider.SetUserRoles(dbConnection); }
}
Config which works with standard NHB provider (but this is not what I want):
retval.Add("connection.provider", "NHibernate.Connection.DriverConnectionProvider");
retval.Add("connection.driver_class", "NHibernate.Driver.OracleDataClientDriver");
retval.Add("connection.connection_string", "User Id=user;Password=pass;Pooling=False;Data Source=test");
retval.Add("dialect", "NHibernate.Dialect.Oracle10gDialect");
Config that doesnt work, but should:
retval.Add("connection.provider", "MyNamespace.MyProvider, MyNamespace");
retval.Add("connection.driver_class", "NHibernate.Driver.OracleDataClientDriver");
retval.Add("connection.connection_string", "User Id=user;Password=pass;Pooling=False;Data Source=test");
retval.Add("dialect", "NHibernate.Dialect.Oracle10gDialect");
Exception thrown:
Exception:
Could not instantiate connection provider: MyProvider
Inner:
Unable to cast object of type 'MyProvider' to type 'NHibernate.Connection.IConnectionProvider'.
Versions used
NServiceBus: 2.5.0.1476
NHibernate: 3.1.0.4000
Can anyone shed some light on this issue?
I'm pulling out my hair here sine obviously MyProvider implements IConnectionProvider via DriverConnectionProvider :) :S.
Kind regards