This repository has been archived by the owner on Sep 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathscopingeventbrokertutorial.html
53 lines (50 loc) · 2.49 KB
/
scopingeventbrokertutorial.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
---
layout: documentation
title: Scoping Event Broker
teaser: Appccelerate your asynchronous events by scoping it
navigation:
- name: Overview
link: scopingeventbroker.html
- name: Tutorial
link: scopingeventbrokertutorial.html
- name: Unit Of Work
link: scopingeventbrokerunitofwork.html
- name: Transaction Scope
link: scopingeventbrokertransactionscope.html
- name: Restrictions
link: scopingeventbrokerrestrictions.html
---
<h2>Setup of the scoping event broker</h2>
<p>The usage of the scoping event broker is astonishingly simple. Basically it is only two lines of code. </p>
<script type="syntaxhighlighter" class="brush: csharp"><![CDATA[// Create the special event broker factory which derives from the standard factory
// There should only one such a factory per event broker, aka Singleton per Event Broker
var eventScopingStandardFactory = new EventScopingStandardFactory();
// Pass it into the constructor
var eventBroker = new EventBroker(eventScopingStandardFactory);
]]>
</script>
<p>Everything is setup now. But in order to get the scoping mechanism working you have to explicitely tell the scoping event broker when a scopes starts, ends or is rolled back. This can be done either with the provided unit of work scope or the transaction scope.<p>
<h2>Basic usage with the unit of work</h2>
<script type="syntaxhighlighter" class="brush: csharp"><![CDATA[// Use the eventScopingStandardFactory to create a scope context
IEventScopeContext scopeContext = eventScopingStandardFactory.CreateScopeContext();
// Whenever a scope is needed
using (IEventScope scope = scopeContext.Acquire())
{
publisher.Publish();
scope.Release();
}
]]>
</script>
For more and detailed information about the unit of work approach read <a href="scopingeventbrokerunitofwork.html">here</a>.
<h2>Basic usage with the transaction scope</h2>
<script type="syntaxhighlighter" class="brush: csharp"><![CDATA[// Whenever a scope is needed create a new transaction scope
using (var tx = new TransactionScope())
{
publisher.Publish();
tx.Complete();
}
]]>
</script>
For more and detailed information about the transaction scope approach read <a href="scopingeventbrokertransactionscope.html">here</a>.
<h2>Recommendations</h2>
Whenever your technology of choice (i.ex. Entity Framework or NHibernate) supports TransactionScope we suggest that you use the transaction scope approach because this doesn't actually expose your code to the scoping event broker whenever you need scoping.