Exemple #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Bootloader"/> class.
 /// </summary>
 /// <param name="boot"><see cref="Boot"/> to use.</param>
 public Bootloader(Boot boot)
 {
     _boot = boot;
 }
        /// <inheritdoc/>
        public BootStagesResult Perform(Boot boot)
        {
            var newBindingsNotificationHub = new NewBindingsNotificationHub();
            var results = new List <BootStageResult>();
            var aggregatedAssociations = new Dictionary <string, object>()
            {
                { WellKnownAssociations.NewBindingsNotificationHub, newBindingsNotificationHub }
            };
            IBindingCollection bindingCollection = new BindingCollection(new[]
            {
                new BindingBuilder(Binding.For(typeof(GetContainer))).To((GetContainer)(() => _container)).Build()
            });

            _logger = new NullLogger();

            aggregatedAssociations[WellKnownAssociations.Bindings] = bindingCollection;

            while (_stages.Count > 0)
            {
                var stage = _stages.Dequeue();
                if (aggregatedAssociations.ContainsKey(WellKnownAssociations.Logger))
                {
                    _logger = aggregatedAssociations[WellKnownAssociations.Logger] as ILogger;
                }

                var interfaces = stage.GetType().GetInterfaces();

                var isBefore = interfaces.Any(_ => _.IsGenericType && _.GetGenericTypeDefinition() == typeof(ICanRunBeforeBootStage <>));
                var isAfter  = interfaces.Any(_ => _.IsGenericType && _.GetGenericTypeDefinition() == typeof(ICanRunAfterBootStage <>));

                var suffix = string.Empty;
                if (isBefore)
                {
                    suffix = " (before)";
                }
                if (isAfter)
                {
                    suffix = " (after)";
                }

                _logger.Information($"<********* BOOTSTAGE : {stage.BootStage}{suffix} *********>");

                var performer    = interfaces.SingleOrDefault(_ => _.IsGenericType && _.GetGenericTypeDefinition() == typeof(ICanPerformPartOfBootStage <>));
                var settingsType = performer.GetGenericArguments()[0];
                var settings     = boot.GetSettingsByType(settingsType);
                var method       = performer.GetMethod("Perform", BindingFlags.Public | BindingFlags.Instance);

                aggregatedAssociations[WellKnownAssociations.Bindings] = bindingCollection;
                var builder = new BootStageBuilder(container: _container, initialAssociations: aggregatedAssociations);
                method.Invoke(stage, new object[] { settings, builder });
                var result = builder.Build();
                results.Add(result);

                result.Associations.ForEach(_ => aggregatedAssociations[_.Key] = _.Value);

                newBindingsNotificationHub.Notify(result.Bindings);
                bindingCollection = aggregatedAssociations[WellKnownAssociations.Bindings] as IBindingCollection;

                bindingCollection = new BindingCollection(bindingCollection, result.Bindings);
                _container        = result.Container;
            }

            return(new BootStagesResult(_container, aggregatedAssociations, results));
        }
Exemple #3
0
        /// <inheritdoc/>
        public Boot Build()
        {
            var boot = new Boot(_settings.Values);

            return(boot);
        }