我知道它已經解決了,但我無法找到如何真正實現任何例子InstallerFactory,所以這裏有一個解決方案,如果有人正在使用它。
使用方法:
[InstallerPriority(0)]
public class ImportantInstallerToRunFirst : IWindsorInstaller
{
public void Install(IWindsorContainer container, Castle.MicroKernel.SubSystems.Configuration.IConfigurationStore store)
{
// do registrations
}
}
只是一個優先添加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()));
手動添加安裝在您需要的順序?無論如何,你能告訴我們爲什麼你需要定義一個特定的訂單嗎? – 2011-06-15 13:49:26
好吧,讓我們假設我想保證Service安裝程序首先運行(依賴關係圖允許)。該文檔說覆蓋InstallerFactory是要走的路。這個話題似乎很少涉及。我認爲最終歸結爲重新排序傳遞給Select方法的IEnumerable –
2011-06-15 16:09:03