Exemple #1
0
        public static void Run(
            IUnityContainer container, Func <IMicroservice> microserviceFactory,
            bool useSignalRLog = true, bool verbose = true, IEnumerable <IPollableEventSource> ocassionallyConnectedSources = null)
        {
            lock (_lockObject)
            {
                // Double checking
                if (_microservice != null || isRunning)
                {
                    return;
                }

                DbConfiguration.SetConfiguration(new TransientFaultHandlingDbConfiguration());
                container     = ContainerFactory.ResolveCommonDependenciesForMainContainer(container, useSignalRLog, verbose);
                _microservice = microserviceFactory.Invoke();

                if (ocassionallyConnectedSources != null)
                {
                    var inMemoryEventPublisher = container.Resolve <IInMemoryEventPublisher>();
                    ocassionallyConnectedSources.ForEach(x => inMemoryEventPublisher.Register(x));
                }

                _microservice.Start();
                isRunning = true;
            }
        }
        public ConsoleApplication Start()
        {
            _logger.Info("Starting application");
            _logger.Info("Press Ctrl+C to exit");

            if (_microservice == null)
            {
                throw new InvalidOperationException("Not initialized");
            }

            Console.CancelKeyPress += (sender, ea) =>
            {
                _logger.Info("Stopping application...");

                Stop();

                _logger.Info("ConsoleApplication is stopped");
            };

            _logger.Info($"Running microservice {_microservice.GetType().Name}...");

            _microservice.Start(_cancellationTokenSource.Token);

            return(this);
        }