views:

29

answers:

3

Hi,

BACKGROUND: I am working on a .NET WinForms application now (C#) with an ADO.net database for the data layer.

QUESTION: How an I develop this now such that it would be easy to migrate to a model where the data layer is abstracted via a HTTP web-service or REST interface?

For example would just use of a standard C# interface with a Factory to obtain a concrete implementation of the interface where this uses ADO.net be the best?

thanks

+2  A: 

Actually what you wanna do is to make your 2-tier application (Application <--> Database) change into an n-tier system (Application(s) <--> App Server <--> Database).

This is a complex change because you have to think of security, business logic and everything.

One Idea could be to use a third-party library like DataAbstract. This is a complete n-Tier framework, still allowing you features like LINQ to a remote data source and making n-tier development really easy. It also provides a web-service interface to easily access your business logic within the application layer from any source. Going further it provides you with client libraries for the iPhone and also windows mobile that do allow you a faster (because binary) access to the layer. You would need the web service interface only for platforms where DataAbstract is not available for.

Sebastian P.R. Gingter
+1  A: 

You've hit the nail on the head - it's about abstraction. Start out right now by abstracting away from storage-specific semantics in your business logic. Develop a clean, object-oriented DAL and do all CRUD/Query operations through it, and while your object model (or domain model, if you want to recognize a difference between the two) can use concrete classes, your DAL operations should be defined in an interface. Whether you use a factory depends on your particular use case, but if you're developing with this sort of abstraction in mind, it makes sense to adopt an inversion of control container and handle this sort of wiring by dependency injection. There are lots to choose from.

Dathan
If I still need to specify interfaces would an IOC container be overkill just to wire the client code tothe data access code? Just wondering how big/complex an app needs to be before adding IOC will make it simpler overall rather than more complex?
Greg
The convention-over-configuration support in a lot of the popular .Net IoC containers makes the entry threshold very low. I'd say if you have more than four or five interfaces for which you need to provide different implementations based on configuration or context, it's time to start looking at an IoC container. By the time you get to ten or more, you're definitely there. As always, YMMV. And of course, you don't HAVE to specify an interface for your DAL operations (a la `ISession` for NHibernate) - but it's good programming practice to depend on abstractions when possible.
Dathan
+1  A: 

You would never want to abstract a DAL with a REST interface. A REST interface is something that you expose directly to a "User Agent". You would never want your business layer to consume data via REST.

The only exception is if your primary goal is to expose the raw data to some remote third party.

Darrel Miller
Darrel - what would you recommend if the migration was to thick WinForms client on the desktop (rich client) talking to a backend then? Would you recommend Web Services for this then? But my perception was that HTTP REST was just another form of webservice based on a protocol with less overhead no?
Greg
You can do a rich client application that talks to a REST service. However, it ends up being a pretty dumb rich client as all the application logic moves behind the REST interface. IMHO "Web Services" are a way of exposing a library of functions to a remote client, just that. REST is an approach to building distributed applications, usually over HTTP and says a lot more about how your distributed application components should be built and how they should interact. REST is a lot more than just a lightweight web service.
Darrel Miller