简体   繁体   中英

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 ?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM