Skip to content

Commit 68ad899

Browse files
committed
Added a example session to the fullduplex sample in order to show the
intended use of the new support for using lambdas when creating components
1 parent 45a2674 commit 68ad899

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

Samples/FullDuplex/MyServer/MyOwnUnitOfWork.cs

+25-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ namespace MyServer
77

88
public class MyOwnUnitOfWork : IManageUnitsOfWork
99
{
10+
public IMySession MySession { get; set; }
11+
1012
public void Begin()
1113
{
1214
LogMessage("Begin");
@@ -15,7 +17,10 @@ public void Begin()
1517
public void End(Exception ex)
1618
{
1719
if (ex == null)
20+
{
1821
LogMessage("Commit");
22+
MySession.SaveChanges();
23+
}
1924
else
2025
LogMessage("Rollback, reason: " + ex);
2126
}
@@ -26,11 +31,30 @@ void LogMessage(string message)
2631
}
2732
}
2833

34+
public interface IMySession
35+
{
36+
void SaveChanges();
37+
}
38+
39+
public class ExampleSession:IMySession
40+
{
41+
public void SaveChanges()
42+
{
43+
Console.WriteLine(string.Format("ExampleSession({0}) - {1}", GetHashCode(), "Saving changes"));
44+
}
45+
}
46+
2947
public class UoWIntitializer : IWantCustomInitialization
3048
{
3149
public void Init()
3250
{
33-
Configure.Instance.Configurer.ConfigureComponent<MyOwnUnitOfWork>(DependencyLifecycle.InstancePerUnitOfWork);
51+
Configure.Instance.Configurer.
52+
ConfigureComponent<MyOwnUnitOfWork>(DependencyLifecycle.InstancePerUnitOfWork);
53+
54+
//this shows the new lambda feature introduced in NServiceBus 3.2.3
55+
Configure.Instance.Configurer.
56+
ConfigureComponent<IMySession>(()=> new ExampleSession(),DependencyLifecycle.InstancePerUnitOfWork);
57+
3458
}
3559
}
3660
}

0 commit comments

Comments
 (0)