-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make usage of NHibernate compatible with
SET NOCOUNT ON
DB-wide set…
…ting #112 -Allow customizing of SQL Transport connections with injectable factory, like NHibernate does.
- Loading branch information
1 parent
914190c
commit 8dec49a
Showing
11 changed files
with
96 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/NServiceBus.SqlServer/Config/SqlConnectionFactoryConfig.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
namespace NServiceBus.Transports.SQLServer.Config | ||
{ | ||
using System; | ||
using System.Data.SqlClient; | ||
using NServiceBus.Features; | ||
using NServiceBus.Settings; | ||
|
||
class SqlConnectionFactoryConfig : ConfigBase | ||
{ | ||
internal const string CustomSqlConnectionFactorySettingKey = "SqlServer.CustomSqlConnectionFactory"; | ||
|
||
static SqlConnection DefaultOpenNewConnection(string connectionString) | ||
{ | ||
var connection = new SqlConnection(connectionString); | ||
|
||
try | ||
{ | ||
connection.Open(); | ||
} | ||
catch (Exception) | ||
{ | ||
connection.Dispose(); | ||
throw; | ||
} | ||
|
||
return connection; | ||
} | ||
|
||
public override void SetUpDefaults(SettingsHolder settings) | ||
{ | ||
Func<string, SqlConnection> factoryMethod = DefaultOpenNewConnection; | ||
settings.SetDefault(CustomSqlConnectionFactorySettingKey, factoryMethod); | ||
} | ||
|
||
public override void Configure(FeatureConfigurationContext context, string connectionStringWithSchema) | ||
{ | ||
var factoryMethod = (Func<string, SqlConnection>)context.Settings.Get(CustomSqlConnectionFactorySettingKey); | ||
context.Container.ConfigureComponent(b => factoryMethod, DependencyLifecycle.SingleInstance); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters