Example #1
0
        public virtual void Configure(IEngine engine, AutofacContainerManager containerManager)
        {
            //other dependencies
            containerManager.AddComponentInstance <IEngine>(engine, "Kore.Engine");
            containerManager.AddComponentInstance <ContainerConfigurer>(this, "Kore.ContainerConfigurer");

            //type finder
            containerManager.AddComponent <ITypeFinder, ConsoleAppTypeFinder>("Kore.TypeFinder");

            //register dependencies provided by other assemblies
            var typeFinder = containerManager.Resolve <ITypeFinder>();

            containerManager.UpdateContainer(x =>
            {
                var drTypes     = typeFinder.FindClassesOfType <IDependencyRegistrar <ContainerBuilder> >();
                var drInstances = new List <IDependencyRegistrar <ContainerBuilder> >();
                foreach (var drType in drTypes)
                {
                    drInstances.Add((IDependencyRegistrar <ContainerBuilder>)Activator.CreateInstance(drType));
                }
                //sort
                drInstances = drInstances.AsQueryable().OrderBy(t => t.Order).ToList();
                foreach (var dependencyRegistrar in drInstances)
                {
                    dependencyRegistrar.Register(x, typeFinder);
                }
            });
        }
Example #2
0
        private void RunStartupTasks()
        {
            if (!DataSettingsHelper.IsDatabaseInstalled)
            {
                return;
            }

            var typeFinder       = _containerManager.Resolve <ITypeFinder>();
            var startUpTaskTypes = typeFinder.FindClassesOfType <IStartupTask>();
            var startUpTasks     = new List <IStartupTask>();

            foreach (var startUpTaskType in startUpTaskTypes)
            {
                startUpTasks.Add((IStartupTask)Activator.CreateInstance(startUpTaskType));
            }
            //sort
            startUpTasks = startUpTasks.AsQueryable().OrderBy(st => st.Order).ToList();
            foreach (var startUpTask in startUpTasks)
            {
                startUpTask.Execute();
            }
        }