Esempio n. 1
0
        protected override async Task SynchronizedStartAsync(CancellationToken cancellationToken)
        {
            if (ActivationGroups == null ||
                ActivationGroups.Count == 0)
            {
                throw new InvalidOperationException($"There's no defined activation group names. Please add at least one it into '{nameof(ActivationGroups)}' property.");
            }

            _logger.Debug("Loading types for activation...");

            foreach (var serviceType in GetServiceTypes())
            {
                var activatable = GetActivatable(serviceType);
                if (!ActivationGroups.Contains(activatable.Group))
                {
                    continue;
                }

                _logger.Write(LogEventLevel.Debug, nameof(ServiceActivator), null,
                              "Setting up service '{ServiceType}' for activation...", serviceType.Name);

                try
                {
                    var container = CreateServiceContainer(serviceType, activatable);
                    var service   = container.GetInstance <IService>();

                    _serviceContainer.Add(service, activatable.Tier);
                    ServiceProviders.Add(serviceType, container);
                }
                catch (Exception ex)
                {
                    _logger.Error(ex, "An error occurred while activating service '{ServiceType}'", serviceType.Name);

                    throw;
                }
            }

            _logger.Debug("Starting service container...");

            await _serviceContainer.StartAsync(cancellationToken);

            _logger.Debug("Service container started");

            await base.SynchronizedStartAsync(cancellationToken);
        }
Esempio n. 2
0
 public void AddServiceProvider(ServiceProvider serviceProvider)
 {
     ServiceProviders.Add(serviceProvider);
 }