Exemple #1
0
            //-------------------------------------------------------------------------------------------------------------------------------------------------

            private Type LoadComponentContainerBuilderType()
            {
                var containerBuilderTypes = OwnerHost.LoadAssembly(
                    typeof(IComponentContainerBuilder),
                    OwnerHost.BootConfig.MicroserviceConfig.InjectionAdapter.Assembly);

                if (containerBuilderTypes.Count != 1)
                {
                    throw new Exception($"{containerBuilderTypes.Count} IComponentContainerBuilder found.");
                }

                return(containerBuilderTypes.First());
            }
Exemple #2
0
            //-------------------------------------------------------------------------------------------------------------------------------------------------

            private void LoadFeatures()
            {
                _componentContainerBuilderType = LoadComponentContainerBuilderType();

                var rootBuilder = CreateComponentContainerBuilder(rootContainer: null);

                OwnerHost.RegisterHostComponents(rootBuilder);

                var rootContainer  = rootBuilder.CreateComponentContainer(isRootContainer: true);
                var featureLoaders = GetConfiguredFeatureLoaders();

                executeFeatureLoaderStep((feature, newComponents) => feature.ContributeConfigSections(newComponents));

                //TODO: compile & register contributed configuration objects

                executeFeatureLoaderStep((feature, newComponents) => feature.ContributeConfiguration(rootContainer));
                executeFeatureLoaderStep((feature, newComponents) => feature.ContributeComponents(rootContainer, newComponents));
                executeFeatureLoaderStep((feature, newComponents) => feature.ContributeAdapterComponents(rootContainer, newComponents));

                if (rootContainer.TryResolve <ITypeLibrary <IRuntimeTypeFactoryArtifact> >(out ITypeLibrary <IRuntimeTypeFactoryArtifact> typeLibrary))
                {
                    executeFeatureLoaderStep((feature, newComponents) => feature.CompileComponents(rootContainer));
                    typeLibrary.CompileDeclaredTypeMembers();
                    executeFeatureLoaderStep((feature, newComponents) => feature.ContributeCompiledComponents(rootContainer, newComponents));
                }

                OwnerHost.Container = rootContainer;

                void executeFeatureLoaderStep(Action <IFeatureLoader, IComponentContainerBuilder> step)
                {
                    var newComponents = CreateComponentContainerBuilder(rootContainer);

                    foreach (var feature in featureLoaders)
                    {
                        step(feature, newComponents);
                    }
                    ;

                    rootContainer.Merge(newComponents);
                }
            }
Exemple #3
0
            //-------------------------------------------------------------------------------------------------------------------------------------------------

            private IEnumerable <IFeatureLoader> GetFeatureLoadersByModuleConfigs(params MicroserviceConfig.ModuleConfig[] configs)
            {
                var types = new List <Type>();

                foreach (var moduleConfig in configs)
                {
                    var featureLoaderTypes = OwnerHost.LoadAssembly(typeof(IFeatureLoader), moduleConfig.Assembly);

                    types.AddRange(featureLoaderTypes.Where(x => x.GetTypeInfo().IsDefined(typeof(DefaultFeatureLoaderAttribute))).ToList());

                    if (moduleConfig.Features != null)
                    {
                        foreach (var featureConfig in moduleConfig.Features)
                        {
                            var type = GetTypeByFeatureLoaderConfig(featureLoaderTypes, featureConfig);
                            if (type == null)
                            {
                                throw new Exception($"Feature wasn't found: '{featureConfig.Name}'.");
                            }
                            else
                            {
                                types.Add(type);
                            }
                        }
                    }
                }

                var featureLoaderList = types
                                        .Distinct()
                                        .Select(x => {
                    OwnerHost.Logger.FoundFeatureLoaderComponent(x.FriendlyName());
                    return((IFeatureLoader)Activator.CreateInstance(x));
                })
                                        .ToList();

                return(featureLoaderList);
            }