asp.net mvc 2 with dynamically generated views
i am trying to build an asp.net mvc 2 app for data ent开发者_JAVA百科ry. I want to generate the views on the forms dynamically so will be using htmlhelpers . What would be the most flexible option for the datasource ? so when i change the database i dont have to actually change the code at all(so i guess EF is not an option)? so no model/controller changes etc. Or i don't have a choice but changing the models in my code?
Well by change database, i assume you mean change dbms, from sql server to oracle for example.
I doubt you'll find a solution to do this without any code changes at all, but you can make things a lot simpler by using interfaces for all you services.
For example
public interface IDataRepository
{
...
}
public class SqlServerDataRepository : IDataRepository
{
...
}
and for testing
public class MockRepository : IDataRepository
{
...
}
and later if you swith databases
public class OracleRepository : IDataRepository
{
...
}
This could then be used simple by referring to interfaces
public class MyService
{
public MyService(IRepository repo)
{
//ctor
{
}
And ideally injecting objects with Inversion of control, Ninject or structuremap for example.
Apologies if this is all already know to you and your looking for something different!
精彩评论