Search code examples
breezehottowel

Using Breeze.js with business services (SOA)?


I am just starting out with Hot Towel, and I want to convert our existing (pretty large) system from using old MVC2 to being a nice SPA. I need to reuse our services which handles all repository work for us. I may be able to create some IQueryable methods for getting the entities, but the saving needs to be through the old methods. As I have said, I am just getting started, so forgive me if this is overly noob.

How can I make my BreezeController talk to my services instead of the datacontext from the samples? My biggest obstacle right now is the metadata.

Thanks,

Morten


Solution

  • Breeze does not require a DbContext but as you've discovered without one you will need to describe the Breeze metadata explicitly.

    The NoDb sample in the Breeze zip has an example that how to do this. Note that you can either define metadata directly on the client via method calls against the MetadataStore or you can return a single json object in the Breeze metadata format from the Metadata() method on your server. The Metadata format is described in more detail in the Breeze docs on the website.

    One approach is to define the metadata on the server in a separate document, "metadata.json" in the example below and then just return it.

    [HttpGet]
    public String Metadata() {
      var folder = Path.Combine(HttpRuntime.AppDomainAppPath, "App_Data");
      var fileName = Path.Combine(folder, "metadata.json");
      var jsonMetadata = File.ReadAllText(fileName);
      return jsonMetadata;
    }