开发者

Choosing between XML data provider and SQL with Ninject from a config file

开发者 https://www.devze.com 2023-02-26 23:22 出处:网络
I need a general Ninject usage advice. I have an Interface IDataProvider and two implementations XmlProvider:IDataProvider and OracleSqlProvider:IDataProvider.

I need a general Ninject usage advice.

I have an Interface IDataProvider and two implementations XmlProvider:IDataProvider and OracleSqlProvider:IDataProvider.

I want to use Ninject to instantiate an interface implementation, given that it is defined somehow in app.config.

Questions:

  1. Which is the best way to define what particular implementation to user in app.config?
  2. Is there an automatic way for Ninject 2 to read the preferred bindings from code?
  3. What if my XML provider needs no parameters in the constructor, whereas SQL needs a connection string.开发者_C百科 How does this affect my declaration in app.config and further instantiation in Ninject Module?


In my opinion the best way in your sceanrio is to implement a Provider that gets the information from the app.config and returns the appropriate provider. This also allows to pass the connection string.


See Ninject.Extensions.Xml, i think that is what you need.

0

精彩评论

暂无评论...
验证码 换一张
取 消