Choosing between XML data provider and SQL with Ninject from a config file
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:
- Which is the best way to define what particular implementation to user in app.config?
- Is there an automatic way for Ninject 2 to read the preferred bindings from code?
- 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.
精彩评论