/// <summary>
 /// Prevents a default instance of the <see cref="ConfigurationContext"/> class from being created.
 /// </summary>
 private ConfigurationContext(Configuration configuration)
 {
     if (configuration == null)
     {
         throw new ArgumentNullException("configuration");
     }
     this.configuration = configuration;
 }
 /// <summary>
 /// Prevents a default instance of the <see cref="ConfigurationContext"/> class from being created.
 /// </summary>
 private ConfigurationContext(Configuration configuration)
 {
     if (configuration == null)
     {
         throw new ArgumentNullException(nameof(configuration));
     }
     Configuration = configuration;
 }
        public static ConfigurationContext Establish(Configuration configuration)
        {
            var current = Current;

            if (current != null && !current.AllowOverride)
            {
                throw new InvalidOperationException("ConfigurationContexts cannot be nested.");
            }

            current = new ConfigurationContext(configuration);
            CallContext.LogicalSetData(callContextKey, current.Id);
            contexts.GetOrAdd(current.Id, current);

            return current;
        }
        public override void SetUp()
        {
            base.SetUp();

            schedulerActivity = new List<IScheduledCommand>();

            using (VirtualClock.Start(DateTimeOffset.Now.AddMonths(1)))
            {
                disposables = new CompositeDisposable();
                Settings.Sources = new ISettingsSource[] { new ConfigDirectorySettings(@"c:\dev\.config") }.Concat(Settings.Sources);

                serviceBusSettings = Settings.Get<ServiceBusSettings>();
                serviceBusSettings.NamePrefix = "itscqrstests";
                serviceBusSettings.ConfigureQueue = q => { q.AutoDeleteOnIdle = TimeSpan.FromMinutes(15); };

                var clockName = Any.Paragraph(4);

                var configuration = new Configuration()
                    .UseSqlEventStore()
                    .UseDependency<GetClockName>(_ => @event => clockName)
                    .UseSqlStorageForScheduledCommands()
                    .AddToCommandSchedulerPipeline<Order>(
                        schedule: async (cmd, next) =>
                        {
                            await next(cmd);
                            schedulerActivity.Add(cmd);
                        },
                        deliver: async (cmd, next) =>
                        {
                            await next(cmd);
                            schedulerActivity.Add(cmd);
                        });

                queueSender = new ServiceBusCommandQueueSender(serviceBusSettings)
                {
                    MessageDeliveryOffsetFromCommandDueTime = TimeSpan.FromSeconds(30)
                };

                disposables.Add(queueSender.Messages.Subscribe(s => Console.WriteLine("[ServiceBusCommandQueueSender] " + s.ToJson())));
                disposables.Add(configuration);
                disposables.Add(ConfigurationContext.Establish(configuration));
            }
        }
        public override void SetUp()
        {
            base.SetUp();

            using (VirtualClock.Start(DateTimeOffset.Now.AddMonths(1)))
            {
                disposables = new CompositeDisposable();
                Settings.Sources = new ISettingsSource[] { new ConfigDirectorySettings(@"c:\dev\.config") }.Concat(Settings.Sources);

                serviceBusSettings = Settings.Get<ServiceBusSettings>();
                serviceBusSettings.NamePrefix = "itscqrstests";
                serviceBusSettings.ConfigureQueue = q =>
                {
                    q.AutoDeleteOnIdle = TimeSpan.FromMinutes(15);
                };

                bus = new FakeEventBus();
                orderRepository = new SqlEventSourcedRepository<Order>(bus);

                var configuration = new Configuration()
                    .UseSqlEventStore(() => new EventStoreDbContext())
                    .UseEventBus(bus)
                    .UseSqlCommandScheduling()
                    .UseDependency<IEventSourcedRepository<Order>>(t => orderRepository);

                var clockName = Any.Paragraph(4);
                scheduler = new SqlCommandScheduler(configuration) { GetClockName = @event => clockName };

                queueSender = new ServiceBusCommandQueueSender(serviceBusSettings)
                {
                    MessageDeliveryOffsetFromCommandDueTime = TimeSpan.FromSeconds(30)
                };

                disposables.Add(scheduler.Activity.Subscribe(s => Console.WriteLine("SqlCommandScheduler: " + s.ToJson())));
                disposables.Add(queueSender.Messages.Subscribe(s => Console.WriteLine("ServiceBusCommandQueueSender: " + s.ToJson())));
                disposables.Add(bus.Subscribe(scheduler));
                disposables.Add(configuration);
                disposables.Add(ConfigurationContext.Establish(configuration));
            }
        }
Пример #6
0
 /// <summary>
 /// Initializes the <see cref="Configuration"/> class.
 /// </summary>
 static Configuration()
 {
     global = new Configuration();
     global.Container.Register<IEventBus>(c => InProcessEventBus.Instance);
 }