If so any help/pointers/example code as to the best way to go would be very much appreciated.
Obviously your C# business logic can't flow to the js client, so your business logic must run on the server and if you need it to also run on the client you'll need to reimplement it (and maintain it) a second time in js.
Given that backdrop, it is best to view the angular client as a separate app that is making service calls to a server app that exposes a service interface. Not n-tier, but service-oriented.
Following that train of thought, the solution is to define the service interface needed to support your angular app, then implement that service interface using something like Web API. The actual Web API service endpoints will consume/return JSON according to your public contract, and internally they will be implemented using your CSLA-based business objects.
This technique works very well in practice, and I recommend it.
Thanks for the reply.
I have mostly used CSLA in the past in WinForms apps, but increasingly customers are asking for Web apps.
Are there any samples, examples or write ups in the e-books of a CSLA Web API service.
I have also seen quite a few examples where BreezeJS is used with Angular to provide the data However this mostly seems to be based around EF and it looks to me that the best way to get this to work with CSLA would be to write a Breeze ContextProvider for CSLA. Has anyone attempted this or would this be a non-starter.
I am working on something similar to this. We opted to write a REST service layer using Web Api. We created new models with most, but certainly not all properties our CSLA objects have. We use AutoMapper when mapping from CSLA to these new models. We manually pump the data back to issues updates because we have complex rules and sometimes the order in which properties are set matter and some properties are maintained by business objects. We treat Web Api as a product on its own, thus layout groundwork for exposing our entire application as a service, which we could not do with raw CSLA because of proprietary communication format and because we would want to have isolation between business objects and external service consumers.
Hope this helps.
We are working on a similar project. We opted to create new Web Api based service layer. We created a new set of models behind it instead of exposing CSLA objects. We have written some tools to help us generate those models, but this is work in progress. We are using AutoMapper to pump the data from CSLA objects into models, and we are manually pushing the data in the opposite direction because we have complex rules and some properties are not set and some are set in a specific order at time, to support specific UI.
Hope this helps.
Thanks sergeyb.
I have been looking at the Magenic MyVote app on GitHub and that seems to be working along similar lines to your app. Coming form writing CSLA WinForms apps it is a bit disconcerting to see the BusinessObject/model defined in 3 places : 1. As A CSLA Buisiness Object, 2 In the Web Api Server as a class and 3 In the WebUI as a typescript interface (auto generated with typelite).
I would like to investigate the BreezeJS route, but don't currently have time to do that.
Yes, it is in 3 places, but the TypeScript interface is generated from the model, so you are down to 2: CSLA BO and Service Model. In our case this decision is intentional - we do not want tight coupling between CSLA objects and models exposed through services and UI. Yes, there is some overhead in keeping them in synch when necessary.
Thanks, that does make good sense that you would not want to always expose the whole object through the service.
Copyright (c) Marimer LLC