Line data Source code
1 : #region Copyright
2 : // // -----------------------------------------------------------------------
3 : // // <copyright company="Chinchilla Software Limited">
4 : // // Copyright Chinchilla Software Limited. All rights reserved.
5 : // // </copyright>
6 : // // -----------------------------------------------------------------------
7 : #endregion
8 :
9 : using System;
10 : using Microsoft.ServiceBus.Messaging;
11 :
12 : namespace Cqrs.Azure.ServiceBus
13 : {
14 : /// <summary>
15 : /// Represents the factory for the default event processor.
16 : /// </summary>
17 : /// <typeparam name="TEventProcessor">The type of the event.</typeparam>
18 : internal class DefaultEventProcessorFactory<TEventProcessor>
19 : : IEventProcessorFactory
20 : where TEventProcessor : IEventProcessor
21 : {
22 : protected TEventProcessor Instance { get; set; }
23 :
24 : /// <summary>
25 : /// Initializes a new instance of the <see cref="T:Microsoft.ServiceBus.Messaging.DefaultEventProcessorFactory`1"/> class.
26 : /// </summary>
27 1 : public DefaultEventProcessorFactory()
28 : {
29 : }
30 :
31 : /// <summary>
32 : /// Initializes a new instance of the <see cref="T:Microsoft.ServiceBus.Messaging.DefaultEventProcessorFactory`1"/> class using the specified instance.
33 : /// </summary>
34 : /// <param name="instance">The instance.</param>
35 1 : public DefaultEventProcessorFactory(TEventProcessor instance)
36 : {
37 : Instance = instance;
38 : }
39 :
40 : /// <summary>
41 : /// Creates an event processor.
42 : /// </summary>
43 : /// <param name="context">The partition context.</param>
44 : /// <returns>
45 : /// The created event processor.
46 : /// </returns>
47 1 : public IEventProcessor CreateEventProcessor(PartitionContext context)
48 : {
49 : if (Instance == null)
50 : return Activator.CreateInstance<TEventProcessor>();
51 : return Instance;
52 : }
53 : }
54 : }
|