Dragos Durlut
Dragos Durlut

Reputation: 8098

ASP.NET MVC Web Site & WCF Web Service - Sharing functionalities

I have the following situation: I have to create a website and a web service that will share a part of the functionalities.

This is why I do not want to write code twice.

I have thought of the following architecture:

MyApp.BusinessLogic --> here we save the DataModels to the database

MyApp.DataAccess -> DataModels & Entity & mapping


MyApp.UI.Models -> ViewModels

MyApp.UI.ServiceLayer -> Acceses the Business Logic, creates the UI ViewModels for the website, and transforms the ViewModels back into DataModels for saving with the help of the BusinessLogic Layer

MyApp.WebSite


MyApp.WS.Models - >Ws Models, these will be the objects passed between the client and the WS

MyApp.WS.ServiceLayer -> Accesses the business Logic, creates the WS Models for the web service, and transfoms the WS.Models back into DataModels for saving with the help of the BusinessLogic Layer

MyApp.WebService


Is the architecture overkill ? What problems will I encounter ? Will I have problems with the controllers in the ASP.NET MVC website ?

Upvotes: 0

Views: 259

Answers (2)

finman
finman

Reputation: 545

Define basically :)

If you want to reduce the code usage, why not create your service, then just consume it in the app?

So if you would have something like...

Foo.DataAccess
-Foo.BusinessLogic
--Foo.ServiceLayer

Then have that referenced by:
Foo.WebService (including models for view/update... but probably simplify externally)

Then use
Foo.WebApp
and have this consuming Foo.Webservice to make the data calls on it's behalf

Having UI and web service models increases your code duplication, you could use something like Fluent validation to let the service handle your validation, and enhance the basic validation system.

Upvotes: 0

Patrick
Patrick

Reputation: 2790

When I design my applications I do it like this. My only issue is the dull copying of models to view models. The best way to overcome this to use AutoMapper.

I would though create some unittests because there is a high risk of breaking the app when changing the services (and visa versa). Unit testing would tell you that early on.

Upvotes: 1

Related Questions