I’m about to build a fairly complex web application from the bottom up, and I want to do it the right way with appropriate design patterns (which I haven’t always used in the past) and the latest .Net technologies.
My ambition is to start out with a web application, but make it possible for future mobile apps, and third-party application development and plug-ins.
This leads me to my main conundrum: For the web site (which I’m going to build using the MVC pattern) should I use WCF to expose my data model as an API, or should I simply reference my data through a dll (or a separate project in the web application solution)?
Let me back it up and give you some of my other design thoughts, so you know what I’m trying to do, and please come with input and suggestions if any of this seem like the wrong approach:
- I want to build my data model using EF and the code-first approach, using design patterns such as Unit of work and Repositories.
- I want to expose my data model (1) through an API using WCF.
- I want to build a web application using TDD and MVC, where I get my data from my data model (1).
So, given the above, it seems like an additional hassle to have the web application use the WCF API when I can easily access the data model elsewise, simply by referencing it in my web application. In addition, the latter seems easier since I would have immediate access to all the objects in my data model. I can’t see how that would be possible using web services? The reason I would want to use a WCF API is that I’ve heard so much praise for the idea of only exposing your data through an API, no exceptions, in order to truly be able to develop for multiple platforms. What other reasons are there? Can I use anything but Http messages for the WCF? Can I expose objects, and, if so, how?
I feel like a lot of the answers I’m seeking can be found on-line, but I’ve spent a lot of time looking at the separate pieces of the puzzle and still have a hard time connecting them all to fit together. I hope you guys can help, and that this is a question that can benefit others as well.
As I said, I want to do this the right way, so your input (at any stage of the design phase) is very appreciated.
Thanks!
I’d say build a data API using the new WebAPI framework. That way, anything that can consume a RESTful interface via HTTP can connect to it: http://www.asp.net/web-api
Also, you can set up your project so your Data Model is referenced from a separate project so you don’t necessarily have to go over the network in your main web application. The WebAPI project can be separate, but use the common model to make sure things are consistent