/// <summary>
 /// Set the writer context which is used to "wrap" events written so we know who wrote them (and why)
 /// </summary>
 /// <param name="context">
 /// The context to use when writing events
 /// </param>
 public void SetContext(IWriteContext context)
 {
     if (null != context)
     {
         _context = context;
         if (null != _writer)
         {
             _writer.SetContext(_context);
         }
     }
 }
        public EventStream(EventStreamAttribute attribute,
                           IWriteContext context              = null,
                           IEventStreamSettings settings      = null,
                           INotificationDispatcher dispatcher = null
                           )
        {
            _domainName     = attribute.DomainName;
            _entityTypeName = attribute.EntityTypeName;
            _instanceKey    = attribute.InstanceKey;


            if (null == settings)
            {
                _settings = new EventStreamSettings();
            }
            else
            {
                _settings = settings;
            }

            // wire up the event stream writer
            _writer = _settings.CreateWriterForEventStream(attribute);

            if (null != context)
            {
                _context = context;
                if (null != _writer)
                {
                    _writer.SetContext(_context);
                }
            }

            if (null == dispatcher)
            {
                if (!string.IsNullOrWhiteSpace(attribute.NotificationDispatcherName))
                {
                    _notificationDispatcher = NotificationDispatcherFactory.GetDispatcher(attribute.NotificationDispatcherName);
                }
                else
                {
                    // Create a new dispatcher
                    _notificationDispatcher = NotificationDispatcherFactory.GetDefaultDispatcher();
                }
            }
            else
            {
                _notificationDispatcher = dispatcher;
            }
        }