1
+ using System ;
2
+ using System . Data ;
3
+ using NHibernate . Mapping . ByCode ;
4
+ using NHibernate . Mapping . ByCode . Conformist ;
5
+ using NServiceBus ;
6
+ using NServiceBus . NHibernate . Outbox ;
7
+ using NServiceBus . Outbox . NHibernate ;
8
+
9
+ namespace NHibernate ;
10
+
11
+ public class Outbox
12
+ {
13
+ public void TransactionIsolation ( EndpointConfiguration endpointConfiguration )
14
+ {
15
+ #region OutboxTransactionIsolation
16
+
17
+ var outboxSettings = endpointConfiguration . EnableOutbox ( ) ;
18
+ outboxSettings . UseTransactionScope ( ) ;
19
+ outboxSettings . TransactionIsolationLevel ( IsolationLevel . ReadCommitted ) ;
20
+
21
+ #endregion
22
+ }
23
+
24
+ public void CustomTableName ( EndpointConfiguration endpointConfiguration )
25
+ {
26
+ #region OutboxNHibernateCustomTableNameConfig
27
+
28
+ var persistence = endpointConfiguration . UsePersistence < NHibernatePersistence > ( ) ;
29
+ persistence . CustomizeOutboxTableName (
30
+ outboxTableName : "MyEndpointOutbox" ,
31
+ outboxSchemaName : "MySchema" ) ;
32
+
33
+ #endregion
34
+ }
35
+
36
+ public void PessimisticMode ( EndpointConfiguration endpointConfiguration )
37
+ {
38
+ #region OutboxPessimisticMode
39
+
40
+ var outboxSettings = endpointConfiguration . EnableOutbox ( ) ;
41
+ outboxSettings . UsePessimisticConcurrencyControl ( ) ;
42
+
43
+ #endregion
44
+ }
45
+
46
+ public void TransactionScopeMode ( EndpointConfiguration endpointConfiguration )
47
+ {
48
+ #region OutboxTransactionScopeMode
49
+
50
+ var outboxSettings = endpointConfiguration . EnableOutbox ( ) ;
51
+ outboxSettings . UseTransactionScope ( ) ;
52
+
53
+ #endregion
54
+ }
55
+
56
+ public void CustomMapping ( EndpointConfiguration endpointConfiguration )
57
+ {
58
+ #region OutboxNHibernateCustomMappingConfig
59
+
60
+ var persistence = endpointConfiguration . UsePersistence < NHibernatePersistence > ( ) ;
61
+ persistence . UseOutboxRecord < MyOutboxRecord , MyOutboxRecordMapping > ( ) ;
62
+
63
+ #endregion
64
+ }
65
+
66
+ #region OutboxNHibernateCustomMapping
67
+
68
+ public class MyOutboxRecord :
69
+ IOutboxRecord
70
+ {
71
+ public virtual string MessageId { get ; set ; }
72
+ public virtual bool Dispatched { get ; set ; }
73
+ public virtual DateTime ? DispatchedAt { get ; set ; }
74
+ public virtual string TransportOperations { get ; set ; }
75
+ }
76
+
77
+ public class MyOutboxRecordMapping :
78
+ ClassMapping < MyOutboxRecord >
79
+ {
80
+ public MyOutboxRecordMapping ( )
81
+ {
82
+ Table ( "MyOutboxTable" ) ;
83
+ Id (
84
+ idProperty : record => record . MessageId ,
85
+ idMapper : mapper => mapper . Generator ( Generators . Assigned ) ) ;
86
+ Property (
87
+ property : record => record . Dispatched ,
88
+ mapping : mapper =>
89
+ {
90
+ mapper . Column ( c => c . NotNullable ( true ) ) ;
91
+ mapper . Index ( "OutboxRecord_Dispatched_Idx" ) ;
92
+ } ) ;
93
+ Property (
94
+ property : record => record . DispatchedAt ,
95
+ mapping : pm => pm . Index ( "OutboxRecord_DispatchedAt_Idx" ) ) ;
96
+ Property (
97
+ property : record => record . TransportOperations ,
98
+ mapping : mapper => mapper . Type ( NHibernateUtil . StringClob ) ) ;
99
+ }
100
+ }
101
+
102
+ #endregion
103
+
104
+ }
0 commit comments