After some time using DI and IoC, I start to question my habits. My starting point is why I use XML and not fluent configuration?
After I read some articles (http://ift.tt/1sTZIGL, http://ift.tt/TuZ5S4, and this related stack overflow topic (base on Jim Cooper awnser) Mock framework vs MS Fakes frameworks on testing frameworks that discuss injection in comments)
My scenario is the following: I have an user interface with all my features (lets say using ASP.NET MVC). I have my interfaces with the methods to access the data. I have my dependency resolver (Unity container) doing the injection. And the configuration in XML.
But one of the requeriments is that the customers can have different types of databases or ways to access to the data source (SQL Server, MySql or give us an SDK).
Base on that requirement I will have one interface and multiple implementations of the access to data.
Currently I change the configurations in the XML and will change the concret class to be injected.
<!-- language: lang-xml -->
<container>
<!-- Customer with Sql Server -->
<register type="Foo.Interfaces.IFoo, Foo" mapTo="Foo.SqlServer.Foo, Foo.SqlServer" >
</register>
<!-- Customer with MySql -->
<!-- <register type="Foo.Interfaces.IFoo, Foo" mapTo="Foo.MySql.Foo, Foo.MySql" >
</register> -->
<!-- Customer with Customer SDK -->
<!-- <register type="Foo.Interfaces.IFoo, Foo" mapTo="Foo.CustomerXSdk.Foo, Foo.CustomerXSdk" >
</register> -->
<container>
But if I want to use fluent configuration as suggested in the links, how should I configure it in order to inject the right class base on the customer?
Some one can provide a link with examples, or some code snippet?
Thanks in advance
No comments:
Post a Comment