Skip to content

Commit f9e807b

Browse files
Simplify postgresql samples (#6943)
* Simplify snippets by relying on docker * Cleanup sample description * Change the include (let's see if include in include works) * Some spacing for better reability * remove unnecessary named param * Further cleanup of transition sample to be aligned * Simplify lambda * Simplify lambda --------- Co-authored-by: Daniel Marbach <[email protected]> Co-authored-by: Mauro Servienti <[email protected]>
1 parent ac22f16 commit f9e807b

File tree

22 files changed

+86
-306
lines changed

22 files changed

+86
-306
lines changed

samples/sql-persistence/injecting-services/SqlPersistence_7/Endpoint/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
var persistence = endpointConfiguration.UsePersistence<SqlPersistence>();
2222
persistence.SqlDialect<SqlDialect.MsSqlServer>();
23-
persistence.ConnectionBuilder(connectionBuilder: () => new SqlConnection(connectionString));
23+
persistence.ConnectionBuilder(() => new SqlConnection(connectionString));
2424

2525
var subscriptions = persistence.SubscriptionSettings();
2626
subscriptions.CacheFor(TimeSpan.FromMinutes(1));

samples/sql-persistence/injecting-services/SqlPersistence_8/Endpoint/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
var persistence = endpointConfiguration.UsePersistence<SqlPersistence>();
2424
persistence.SqlDialect<SqlDialect.MsSqlServer>();
25-
persistence.ConnectionBuilder(connectionBuilder: () => new SqlConnection(connectionString));
25+
persistence.ConnectionBuilder(() => new SqlConnection(connectionString));
2626

2727
var subscriptions = persistence.SubscriptionSettings();
2828
subscriptions.CacheFor(TimeSpan.FromMinutes(1));

samples/sql-persistence/saga-rename/SqlPersistence_7/Shared/SharedConfiguration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public static void Apply(EndpointConfiguration endpointConfiguration)
1818
var connectionString = @"Server=localhost,1433;Initial Catalog=NsbSamplesSqlPersistenceRenameSaga;User Id=SA;Password=yourStrong(!)Password;Encrypt=false";
1919

2020
persistence.ConnectionBuilder(
21-
connectionBuilder: () => new SqlConnection(connectionString));
21+
() => new SqlConnection(connectionString));
2222

2323
endpointConfiguration.EnableInstallers();
2424
endpointConfiguration.UseSerialization<SystemJsonSerializer>();

samples/sql-persistence/saga-rename/SqlPersistence_8/Shared/SharedConfiguration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public static void Apply(EndpointConfiguration endpointConfiguration)
1818
var connectionString = @"Server=localhost,1433;Initial Catalog=NsbSamplesSqlPersistenceRenameSaga;User Id=SA;Password=yourStrong(!)Password;Encrypt=false";
1919

2020
persistence.ConnectionBuilder(
21-
connectionBuilder: () => new SqlConnection(connectionString));
21+
() => new SqlConnection(connectionString));
2222

2323
endpointConfiguration.EnableInstallers();
2424
endpointConfiguration.UseSerialization<SystemJsonSerializer>();

samples/sql-persistence/simple/SqlPersistence_7/EndpointMySql/Program.cs

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,21 @@
44

55
Console.Title = "EndpointMySql";
66

7-
#region MySqlConfig
8-
97
var endpointConfiguration = new EndpointConfiguration("Samples.SqlPersistence.EndpointMySql");
108
endpointConfiguration.UseSerialization<SystemJsonSerializer>();
119

10+
#region MySqlConfig
1211
var persistence = endpointConfiguration.UsePersistence<SqlPersistence>();
13-
14-
var password = Environment.GetEnvironmentVariable("MySqlPassword");
15-
if (string.IsNullOrWhiteSpace(password))
16-
{
17-
throw new Exception("Could not extract 'MySqlPassword' from Environment variables.");
18-
}
19-
var username = Environment.GetEnvironmentVariable("MySqlUserName");
20-
if (string.IsNullOrWhiteSpace(username))
21-
{
22-
throw new Exception("Could not extract 'MySqlUserName' from Environment variables.");
23-
}
24-
var connection = $"server=localhost;user={username};database=sqlpersistencesample;port=3306;password={password};AllowUserVariables=True;AutoEnlist=false";
2512
persistence.SqlDialect<SqlDialect.MySql>();
26-
persistence.ConnectionBuilder(
27-
connectionBuilder: () =>
28-
{
29-
return new MySqlConnection(connection);
30-
});
31-
var subscriptions = persistence.SubscriptionSettings();
32-
subscriptions.CacheFor(TimeSpan.FromMinutes(1));
3313

14+
var connection = "server=localhost;user=root;database=sqlpersistencesample;port=3306;password=yourStrong(!)Password;AllowUserVariables=True;AutoEnlist=false";
15+
16+
persistence.ConnectionBuilder(() => new MySqlConnection(connection));
3417
#endregion
3518

19+
var subscriptions = persistence.SubscriptionSettings();
20+
subscriptions.CacheFor(TimeSpan.FromMinutes(1));
21+
3622
endpointConfiguration.UseTransport(new LearningTransport());
3723
endpointConfiguration.EnableInstallers();
3824

@@ -43,4 +29,4 @@
4329
Console.WriteLine("Press any key to exit");
4430
Console.ReadKey();
4531

46-
await endpointInstance.Stop();
32+
await endpointInstance.Stop();

samples/sql-persistence/simple/SqlPersistence_7/EndpointOracle/Program.cs

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,21 @@
55

66
Console.Title = "EndpointOracle";
77

8-
#region OracleConfig
9-
108
var endpointConfiguration = new EndpointConfiguration("EndpointOracle");
119
endpointConfiguration.UseSerialization<SystemJsonSerializer>();
1210

11+
#region OracleConfig
1312
var persistence = endpointConfiguration.UsePersistence<SqlPersistence>();
14-
15-
var password = Environment.GetEnvironmentVariable("OraclePassword");
16-
if (string.IsNullOrWhiteSpace(password))
17-
{
18-
throw new Exception("Could not extract 'OraclePassword' from Environment variables.");
19-
}
20-
21-
var username = Environment.GetEnvironmentVariable("OracleUserName");
22-
23-
if (string.IsNullOrWhiteSpace(username))
24-
{
25-
throw new Exception("Could not extract 'OracleUserName' from Environment variables.");
26-
}
27-
28-
var connection = $"Data Source=localhost;User Id={username}; Password={password}; Enlist=false";
29-
3013
persistence.SqlDialect<SqlDialect.Oracle>();
3114

32-
persistence.ConnectionBuilder(
33-
connectionBuilder: () =>
34-
{
35-
return new OracleConnection(connection);
36-
});
15+
var connection = $"Data Source=localhost;User Id=SYSTEM; Password=yourStrong(!)Password; Enlist=false";
16+
17+
persistence.ConnectionBuilder(() => new OracleConnection(connection));
18+
#endregion
3719

3820
var subscriptions = persistence.SubscriptionSettings();
3921
subscriptions.CacheFor(TimeSpan.FromMinutes(1));
4022

41-
#endregion
42-
4323
endpointConfiguration.UseTransport(new LearningTransport());
4424
endpointConfiguration.EnableInstallers();
4525

@@ -48,4 +28,4 @@
4828
Console.WriteLine("Press any key to exit");
4929
Console.ReadKey();
5030

51-
await endpointInstance.Stop();
31+
await endpointInstance.Stop();

samples/sql-persistence/simple/SqlPersistence_7/EndpointPostgreSql/Program.cs

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,17 @@
66

77
Console.Title = "EndpointPostgreSql";
88

9-
#region PostgreSqlConfig
10-
119
var endpointConfiguration = new EndpointConfiguration("EndpointPostgreSql");
1210
endpointConfiguration.UseSerialization<SystemJsonSerializer>();
1311

14-
12+
#region PostgreSqlConfig
1513
var persistence = endpointConfiguration.UsePersistence<SqlPersistence>();
16-
var password = Environment.GetEnvironmentVariable("PostgreSqlPassword");
17-
18-
if (string.IsNullOrWhiteSpace(password))
19-
{
20-
throw new Exception("Could not extract 'PostgreSqlPassword' from Environment variables.");
21-
}
22-
var username = Environment.GetEnvironmentVariable("PostgreSqlUserName");
23-
24-
if (string.IsNullOrWhiteSpace(username))
25-
{
26-
throw new Exception("Could not extract 'PostgreSqlUserName' from Environment variables.");
27-
}
14+
var dialect = persistence.SqlDialect<SqlDialect.PostgreSql>();
2815

29-
var connection = $"Host=localhost;Username={username};Password={password};Database=NsbSamplesSqlPersistence";
16+
var connection = "Host=localhost;Username=postgres;Password=yourStrong(!)Password;Database=NsbSamplesSqlPersistence";
3017

31-
var dialect = persistence.SqlDialect<SqlDialect.PostgreSql>();
18+
persistence.ConnectionBuilder(() => new NpgsqlConnection(connection));
19+
#endregion
3220

3321
dialect.JsonBParameterModifier(
3422
modifier: parameter =>
@@ -37,17 +25,9 @@
3725
npgsqlParameter.NpgsqlDbType = NpgsqlDbType.Jsonb;
3826
});
3927

40-
persistence.ConnectionBuilder(
41-
connectionBuilder: () =>
42-
{
43-
return new NpgsqlConnection(connection);
44-
});
45-
4628
var subscriptions = persistence.SubscriptionSettings();
4729
subscriptions.CacheFor(TimeSpan.FromMinutes(1));
4830

49-
#endregion
50-
5131
endpointConfiguration.UseTransport(new LearningTransport());
5232
endpointConfiguration.EnableInstallers();
5333

@@ -58,4 +38,4 @@
5838
Console.WriteLine("Press any key to exit");
5939
Console.ReadKey();
6040

61-
await endpointInstance.Stop();
41+
await endpointInstance.Stop();

samples/sql-persistence/simple/SqlPersistence_7/EndpointSqlServer/Program.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,17 @@
1010
endpointConfiguration.UseSerialization<SystemJsonSerializer>();
1111

1212
var persistence = endpointConfiguration.UsePersistence<SqlPersistence>();
13-
// for SqlExpress use Data Source=.\SqlExpress;Initial Catalog=NsbSamplesSqlPersistence;Integrated Security=True;Encrypt=false
14-
var connectionString = @"Server=localhost,1433;Initial Catalog=NsbSamplesSqlPersistence;User Id=SA;Password=yourStrong(!)Password;Encrypt=false";
1513
persistence.SqlDialect<SqlDialect.MsSqlServer>();
16-
persistence.ConnectionBuilder(
17-
connectionBuilder: () => new SqlConnection(connectionString));
18-
var subscriptions = persistence.SubscriptionSettings();
19-
subscriptions.CacheFor(TimeSpan.FromMinutes(1));
2014

15+
// for SqlExpress use Data Source=.\SqlExpress;Initial Catalog=NsbSamplesSqlPersistence;Integrated Security=True;Encrypt=false
16+
var connectionString = "Server=localhost,1433;Initial Catalog=NsbSamplesSqlPersistence;User Id=SA;Password=yourStrong(!)Password;Encrypt=false";
17+
18+
persistence.ConnectionBuilder(() => new SqlConnection(connectionString));
2119
#endregion
2220

21+
var subscriptions = persistence.SubscriptionSettings();
22+
subscriptions.CacheFor(TimeSpan.FromMinutes(1));
23+
2324
SqlHelper.EnsureDatabaseExists(connectionString);
2425

2526
endpointConfiguration.UseTransport(new LearningTransport());

samples/sql-persistence/simple/SqlPersistence_8/EndpointMySql/Program.cs

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,21 @@
44

55
Console.Title = "EndpointMySql";
66

7-
#region MySqlConfig
8-
97
var endpointConfiguration = new EndpointConfiguration("Samples.SqlPersistence.EndpointMySql");
108
endpointConfiguration.UseSerialization<SystemJsonSerializer>();
119

10+
#region MySqlConfig
1211
var persistence = endpointConfiguration.UsePersistence<SqlPersistence>();
13-
14-
var password = Environment.GetEnvironmentVariable("MySqlPassword");
15-
if (string.IsNullOrWhiteSpace(password))
16-
{
17-
throw new Exception("Could not extract 'MySqlPassword' from Environment variables.");
18-
}
19-
var username = Environment.GetEnvironmentVariable("MySqlUserName");
20-
if (string.IsNullOrWhiteSpace(username))
21-
{
22-
throw new Exception("Could not extract 'MySqlUserName' from Environment variables.");
23-
}
24-
var connection = $"server=localhost;user={username};database=sqlpersistencesample;port=3306;password={password};AllowUserVariables=True;AutoEnlist=false";
2512
persistence.SqlDialect<SqlDialect.MySql>();
26-
persistence.ConnectionBuilder(
27-
connectionBuilder: () =>
28-
{
29-
return new MySqlConnection(connection);
30-
});
31-
var subscriptions = persistence.SubscriptionSettings();
32-
subscriptions.CacheFor(TimeSpan.FromMinutes(1));
3313

14+
var connection = "server=localhost;user=root;database=sqlpersistencesample;port=3306;password=yourStrong(!)Password;AllowUserVariables=True;AutoEnlist=false";
15+
16+
persistence.ConnectionBuilder(() => new MySqlConnection(connection));
3417
#endregion
3518

19+
var subscriptions = persistence.SubscriptionSettings();
20+
subscriptions.CacheFor(TimeSpan.FromMinutes(1));
21+
3622
endpointConfiguration.UseTransport(new LearningTransport());
3723
endpointConfiguration.EnableInstallers();
3824

samples/sql-persistence/simple/SqlPersistence_8/EndpointOracle/Program.cs

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,21 @@
55

66
Console.Title = "EndpointOracle";
77

8-
#region OracleConfig
9-
108
var endpointConfiguration = new EndpointConfiguration("EndpointOracle");
119
endpointConfiguration.UseSerialization<SystemJsonSerializer>();
1210

11+
#region OracleConfig
1312
var persistence = endpointConfiguration.UsePersistence<SqlPersistence>();
14-
15-
var password = Environment.GetEnvironmentVariable("OraclePassword");
16-
if (string.IsNullOrWhiteSpace(password))
17-
{
18-
throw new Exception("Could not extract 'OraclePassword' from Environment variables.");
19-
}
20-
21-
var username = Environment.GetEnvironmentVariable("OracleUserName");
22-
23-
if (string.IsNullOrWhiteSpace(username))
24-
{
25-
throw new Exception("Could not extract 'OracleUserName' from Environment variables.");
26-
}
27-
28-
var connection = $"Data Source=localhost;User Id={username}; Password={password}; Enlist=false";
29-
3013
persistence.SqlDialect<SqlDialect.Oracle>();
3114

32-
persistence.ConnectionBuilder(
33-
connectionBuilder: () =>
34-
{
35-
return new OracleConnection(connection);
36-
});
15+
var connection = "Data Source=localhost;User Id=SYSTEM; Password=yourStrong(!)Password; Enlist=false";
16+
17+
persistence.ConnectionBuilder(() => new OracleConnection(connection));
18+
#endregion
3719

3820
var subscriptions = persistence.SubscriptionSettings();
3921
subscriptions.CacheFor(TimeSpan.FromMinutes(1));
4022

41-
#endregion
42-
4323
endpointConfiguration.UseTransport(new LearningTransport());
4424
endpointConfiguration.EnableInstallers();
4525

0 commit comments

Comments
 (0)