Microsoft的Unity依賴注入框架可以通過代碼或通過應用程序配置文件(app.config)進行配置。Unity應該在代碼或配置文件中進行配置嗎?
代碼示例:
IUnityContainer container = new UnityContainer()
.RegisterType<IInterface, ConcreteImplementation>();
配置例子:
<unity>
<containers>
<container>
<types>
<type type="IInterface, MyAssembly"
mapTo="ConcreteImplementation, MyAssembly" />
有什麼優勢/劣勢每種方法?我可以想到「用戶可以輕鬆配置您的應用程序」的明顯優勢,以及「用戶可以輕鬆打破您的應用程序」的明顯缺點,但是有什麼不明顯的嗎?
Duplicate:http://stackoverflow.com/questions/2512316/ioc-dependency-injection-please-explain-code-versus-xml – 2011-03-24 11:45:03
不是重複的。這個問題涉及如何使用基於代碼的配置。我的問題是爲什麼 - 權衡/好處是什麼。 – 2011-03-24 12:32:19
好吧,夠公平的 - 我會嘗試回答。 – 2011-03-24 12:52:58