如何强制执行安装程序执行顺序

| 我一直在用Cas­tle执行我的DI来构建一个新的.NET解决方案。 现在是我要控制安装程序运行顺序的阶段。我建立了单独的类,这些类实现了IWindsorInstalstaller来处理我的核心类型,例如IRepos­tory,IMap­per和IService等。 我看到它的建议是在此类中实现我自己的Installer­Fac­tory(猜测我只是覆盖Select)。 然后在我的电话中使用这个新工厂:
FromAssembly.InDirectory(new AssemblyFilter(\"bin loca­tion\")); 
我的问题是(当重写了save方法时)什么是强制执行安装程序订单的最佳方法。     
已邀请:
        我知道它已经解决了,但是我找不到关于如何实际实现InstallerFactory的任何示例,因此如果有人在搜索它,这是一个解决方案。 如何使用:
[InstallerPriority(0)]
    public class ImportantInstallerToRunFirst : IWindsorInstaller
    {
        public void Install(IWindsorContainer container, Castle.MicroKernel.SubSystems.Configuration.IConfigurationStore store)
        {
            // do registrations
        }
    }
只需向您的\“ install-order-sensitive \”类添加具有优先级的
InstallerPriority
属性。安装程序将按升序排序。没有优先级的安装程序将默认为100。 实施方法:
public class WindsorBootstrap : InstallerFactory
    {

        public override IEnumerable<Type> Select(IEnumerable<Type> installerTypes)
        {
            var retval =  installerTypes.OrderBy(x => this.GetPriority(x));
            return retval;
        }

        private int GetPriority(Type type)
        {
            var attribute = type.GetCustomAttributes(typeof(InstallerPriorityAttribute), false).FirstOrDefault() as InstallerPriorityAttribute;
            return attribute != null ? attribute.Priority : InstallerPriorityAttribute.DefaultPriority;
        }

    }


[AttributeUsage(AttributeTargets.Class)]
    public sealed class InstallerPriorityAttribute : Attribute
    {
        public const int DefaultPriority = 100;

        public int Priority { get; private set; }
        public InstallerPriorityAttribute(int priority)
        {
            this.Priority = priority;
        }
    }
启动应用程序时,global.asax等:
container.Install(FromAssembly.This(new WindsorBootstrap()));
    
        您可以按照需要在Global.asax.cs中实例化安装程序的顺序来调用它们。在Bootstrapper类中,该类从Global.asax.cs中调用。
        IWindsorContainer container = new WindsorContainer()
            .Install(                    
                new LoggerInstaller()           // No dependencies
                , new PersistenceInstaller()    // --\"\"--
                , new RepositoriesInstaller()   // Depends on Persistence
                , new ServicesInstaller()       // Depends on Repositories
                , new ControllersInstaller()    // Depends on Services
            );
它们按此顺序实例化,您可以在其后添加一个断点并检查容器中是否有
\"Potentially misconfigured components\"
。 如果有的话,请检查他们的
Status
->ѭ8if,如果没有,那是正确的顺序。 该解决方案快速简便,文档中提到使用InstallerFactory类对安装程序进行更严格的控制,因此,如果您有大量的安装程序,则其他解决方案可能更合适。 (使用代码作为惯例应该不需要大量的安装程序吗?) http://docs.castleproject.org/Windsor.Installers.ashx#codeInstallerFactorycode_class_4     
        最后,我必须使用
InstallerFactory
并按照前面建议的方式执行排序规则,即将
IEnumerable<Type>
与我的特定订单一起返回     

要回复问题请先登录注册