我想解決基於條件的依賴關係。解決條件依賴關係autofac
private static readonly Dictionary<string, Action<ContainerBuilder>> QRTypeDictionary =
new Dictionary<string, System.Action<ContainerBuilder>>() {
{ "REST" , (builder)=> builder
.RegisterType<RestPublisher>()
.As<Publisher>()},
{ "DB" , (builder)=> builder
.RegisterType<DBPublisher>()
.As<Publisher>()}
}
我只是想確定如果這是解決依賴條件的唯一方法。我一直在使用Ninject到目前爲止並正在尋找類似如下:
kernel.Bind<Publisher>()
.To<DbPublisher>()
.When(x => Defs.AppSettings.PublisherType == "DB")
只是想確認我在做正確的事與Autofac
是'Defs.AppSettings.PublisherType'需要重新啓動應用程序來更改配置值,也可以從隨時間改變(請求之間例如)? – Steven