0
votes

I need to have two entityManagers in an angular app using breese so that I can get data from two different services. One service is an OData API and the other is a standard breeze web api (asp.net web api using breeze controllers).

My OData context works fine but when I create the standard one the uriBuilder property is still odata and when this manager trys to get metedata is is prefixing the $metadata value onto the end of the url.

 breeze.config.initializeAdapterInstance('modelLibrary', 'backingStore', true);
            breeze.NamingConvention.camelCase.setAsDefault();

            var serviceName = common.testApiUrl;
            var metadataStore = createMetadataStore();

does anyone know if its even possible to have the two setup?

1

1 Answers

0
votes

I have managed to get this working and the trick is to use the DataService to contruct the entitymanagers. This means that they're separate objects with their own configuration and you can indeed use OData and WebApi together.

Here is how I did it:

Create a data service object

var dataService = new breeze.DataService({
                serviceName: myConfig.testApiUrl,
                hasServerMetadata: true,
                adapterName: 'WebApi'
            });

Instantiate an entity manager using this data service

 function newManager() {
                var mgr = new breeze.EntityManager({
                    dataService: dataService
                });
                return mgr;
            }

You can then use this same pattern for however many you need and just change the adapter name. There is some extra config but all standard breeze stuff so I haven't included it all here.

I then create a DataContext for each EntityManager to encapsulate them and I can then just inject the context that I need as and when I need it.