[代码] 扫描注册机,在系统启动时调用一次。

using System.Collections.Generic;
using System.Reflection;
using Skight.eLiteWeb.Domain.BasicExtensions;
using Skight.eLiteWeb.Domain.Containers;

namespace Skight.eLiteWeb.Application.Startup
{
    public class RegistrationScanner:StartupCommand
    {
        private readonly Registration registration;
        private readonly IEnumerable<Assembly> assemblies;

        public RegistrationScanner(Registration registration, params Assembly[] assemblies)
        {
            this.registration = registration;
            this.assemblies = assemblies;
        }

        public void run()
        {
            assemblies
                .each(assembly =>
                      assembly.GetTypes()
                              .each(type =>
                                    type.run_againste_attribute<RegisterInContainerAttribute>(
                                        attribute =>
                                            {
                                                attribute.type_to_register_in_container = type;
                                                attribute.register_using(registration);
                                            })));
        }
    }
}