I'd like to build my business application using the MVVM pattern. I choose MVVM-Light because it fits to my needs. In every example I've seen about MVVM-Light, no-one use the WCF RIA. The classic MIX10 example uses a Service in the same project while WCF RIA create a service in the Web project. The question is: it looks very hard to build an interface of the whole DomainContex the WCF Ria creates (it is surely hard for me!) but without an interface how could I build a fake DomainContex to be used in Blend and in tests as well? Am I missing something? Thanks.
相关问题
- How to make a .svc file write to asp.net Trace.axd
- WCF Service Using Client Certificates Requires Ano
- WCF error with net.tcp "The service endpoint faile
- WCF Service Reference Support Files Not Updating
- WCF Web Service: Upload a file, Process that file,
相关文章
- WCF发布Windows服务 POST方式报错 GET方式没有问题 应该怎么解决?
- XCopy or MOVE do not work when a WCF Service runs
- Could not find default endpoint element that refer
- The 'DbProviderFactories' section can only
- Do I need to expose a constructor in a WCF DataCon
- exposing net.tcp endpoint
- When is destructor called in a WCF service
- Getting error detail from WCF REST
What I have found that works well for me is the following (which I have taken parts from both MVVM light and the RIA business template).
I build a new ViewModelBase class, inheriting from MVVM Light's ViewModelBase class, where I implementment a DomainContext, list of possibly pending operations, current operation, IsBusy property, a SaveCommand, and a protected method to log any operations created by ViewModels that inherit from this class.
Here is an example:
Then, in your actual view models, you can focus on the properties, and commands for the view model - and all the domain context is really wired for you already. Just use the _context property - for example:
and a property might look something like this:
The key part is that the VMBase class handles all wiring and management of the DomainContext. To make this happen, in your ViewModel implementations, be sure to assign any _context.BaseOperationCall(..)'s return value to the currrentOperation, then immediately call the logCurrentOperation. After that, it's hands off. You can then bind a BusyIndicator to your IsWorking propery, and you have a simplified RIA implementation.
Hopefully this helps you get started.
Actually, the solution I am using is blendable, and makes the blending process even simpler.
Here is an exmample of how I accomplish this using this framework:
Then all the sample data is defined in the constructor of the Acutal View Models that are bound in your ViewModelLocator class. The VMBase takes care of not trying to instantiate the DataContext when you are in blend.