i've not tried it, so i'm just guessing ...
if it works, and i'm guessing again that it might work, i'm thinking you've got a terrific idea ...
it's imho much better than having two copies of your classes floating around where their only difference is in the decorations.
g.
B-) Please help me by completing my school survey about computer programmers on my website. Thank you!!! Gerry Lowry +1 705-429-7550 wasaga beach, ontario, canada
please report your results here for the benefit of your forums.asp.net peers.
thnx/g.,
B-) Please help me by completing my school survey about computer programmers on my website. Thank you!!! Gerry Lowry +1 705-429-7550 wasaga beach, ontario, canada
the wcf project has data contracts that have thesame names and properties with the model classes in asp.net mvc .
my question is,
would I be writing bad code, design or breaking some SOA principle if I
used thesame classes as both wcf datacontracts and mvc data model classes?
Anytime I see the same thing is created in duplicate in 2 different places I get concerned about a maintenance syncronization nightmare and also why does it have to be in (2 or more places)? Can you not just use only the WCF data contract classes
and consume the WCF service in your MVC application without having to create them twice? I think it would be best to have all that logic in a single place and in the service if it needs to span multiple applications for consumption.
ysfkel
Member
137 Points
167 Posts
A WCF DESIGN QUESTION
Feb 20, 2012 04:45 PM|LINK
I have a wcf application project
I also have a asp.net mvc project
the wcf project has data contracts that have thesame names and properties with the model classes in asp.net mvc .
my question is,
would I be writing bad code, design or breaking some SOA principle if I
used thesame classes as both wcf datacontracts and mvc data model classes?
i.e creating a class library, decorating the classes with both wcf attributes (datacontract, datamember) and entity framework attributes
and then referencing this class library from both projects,
or is it preferable to design these classes seperately for each project? i.e a datacontract classes for wcf and data model classes for mvc,
even if they used same name and properties?
gerrylowry
All-Star
20513 Points
5712 Posts
Re: A WCF DESIGN QUESTION
Feb 21, 2012 01:05 AM|LINK
@ ysfkel
i've not tried it, so i'm just guessing ... if it works, and i'm guessing again that it might work, i'm thinking you've got a terrific idea ...
it's imho much better than having two copies of your classes floating around where their only difference is in the decorations.
g.
ysfkel
Member
137 Points
167 Posts
Re: A WCF DESIGN QUESTION
Feb 21, 2012 12:19 PM|LINK
Guess ill give it a shot, thanks
gerrylowry
All-Star
20513 Points
5712 Posts
Re: A WCF DESIGN QUESTION
Feb 21, 2012 12:38 PM|LINK
@ ysfkel
you're welcome!
please report your results here for the benefit of your forums.asp.net peers.
thnx/g.,
ysfkel
Member
137 Points
167 Posts
Re: A WCF DESIGN QUESTION
Feb 21, 2012 04:38 PM|LINK
I tried a simple test
created a class library "DomainModel" with a simple class called contact
I added the datacontract and datamemeber (System.Runtime.Serialization) attributes and the required (DataAnnotations) attribute
I created a web service application and mvc application,
I referenecd the class library containing the DataContract/POCO class.
this is a simple test and it seems ok, except for the fact that model validation
only worked when I used the contact class from DomainModel reference and
did not work when I used contact class from web reference.
atconway
All-Star
16846 Points
2756 Posts
Re: A WCF DESIGN QUESTION
Feb 24, 2012 02:50 AM|LINK
Anytime I see the same thing is created in duplicate in 2 different places I get concerned about a maintenance syncronization nightmare and also why does it have to be in (2 or more places)? Can you not just use only the WCF data contract classes and consume the WCF service in your MVC application without having to create them twice? I think it would be best to have all that logic in a single place and in the service if it needs to span multiple applications for consumption.