Event Aggregation Scope Behavior Attribute


Assembly  EnterpriseLibraryExtensions.Events.ServiceModel.dll
Namespace  EnterpriseLibraryExtensions.Events.ServiceModel
 Class  EventAggregationScopeBehaviorAttribute 


The EventAggregationScopeBehaviorAttribute can decorate a class method. Decorating a method with the attribute automatically makes the method work in a new event aggregation scope and the scope will automatically complete when the service method completes.

If an exception occurs in the service, resulting in a faulted state, the event aggregation scope will not complete. This works just like the transactional behavior. The following service contract demonstrates a method with the event aggregation scope behavior defined.

[ServiceContract]
internal interface IServiceWithEventAggregationScopeAttribute 
{
  [OperationContract]
  [EventAggregationScopeBehavior]
  void Execute();
}

Configure Filtering Options

Just like initializing an event aggregation scope with a using statement, there can be scenarios where it is desirable to be able to control filtering options. To pass an object with filtering options to the service, create a class which implements the IScopeOptions interface or use one of the built in classes.

When the class is created, it can be assigned to the scope by specifying its type in the EventAggregationScopeBehavior attribute’s constructory like so:
[ServiceContract]
public interface IServiceWithEventAggregationScopeAttributeWithOptionsSet 
{
  [OperationContract] 
  [EventAggregationScopeBehavior(typeof(MyCustomScopeOptions))] 
  void Execute();
}

Specifying a class that does not expose the IScopeOptions interface will result in an ArgumentException being thrown.

Further Information

You can find more sample code in the quick starts sub directory called Events and it can be beneficial to look into the reference library file provided with a shortcut in your start menu.

Last edited Apr 24, 2012 at 7:47 PM by RasmusTherkelsen, version 1

Comments

No comments yet.