How would I use breeze against an odata service using only the
server's metadata to define the model? Will the context still be
able to handle crud operations to a non web api service?
I have seen
// service name is route to the Web API controller
var serviceName = 'api/CarBones';
/*** dataservice proper ***/
// manager (aka context) is the service gateway and cache holder
var manager = new entityModel.EntityManager(serviceName);
Can I do something like replacing the serviceName with an oData uri
and then continue using breeze as usual?
var serviceName = "http://localhost:1234/Northwind.svc"
Thanks for your help!
This question was posted by jpirok on our IdeaBlade forums. I am reposting the question and answer here since I think it will be useful to the Breeze Stack Overflow community.
Absolutely, to switch to using an OData service simply initialize Breeze with the correct adapter. For OData this would look like:
breeze.config.initializeAdapterInstance("dataService", "OData");
Make sure you make this call before creating your first EntityManager and remember to use an OData uri as the service name.
This provides full OData query support. OData saves have not yet been implemented although they are on the near term roadmap. If you really need OData save functionality, you might want to vote for it on our Breeze User Voice https://breezejs.uservoice.com/forums/173093-breeze-feature-suggestions. We take that venue seriously in making decisions about what to do next.
Related
How do I write a resolver for making multiple API calls to fulfil a GraphQL query using Apollo-iOS on the client side (in my swift project)?
For Example: If, to construct a Person object from a query having name and age parameters - I have to fetch name from a service call and age from another service call and stitch them to form the Person object, then how would the resolver look like and where should I write it?
Any help is appreciated.
I believe GraphQL resolvers are only a concept server-side. The client simply asks for the data. The server is supposed to resolve the query sent by the client so your resolvers should make the necessary calls to different services to be able to resolve the query completely by accessing the single endpoint.
A more in-depth explanation of resolvers in GraphQL: https://medium.com/paypal-engineering/graphql-resolvers-best-practices-cd36fdbcef55
You could write your own swift code to grab data from two separate GraphQL endpoints/services if needed.
I have a simple question. I'm newer with UnityContainer of Miscrosoft. I'm writing an ASP.NET MVC application with Unity for DI.
Have I a different CONTAINER for each user connected to my web app? Or the CONTAINER is the same for all users?
So if I resolve the life time of an object with ContainerControlledLifetimeManager does it mean that only for one user session this object is always the same?
I hope you understand.
Thanks,
Christian
Lifetime refers to the life of the object created by the DI process. Per request means each request gets its own object. If the object depends on the current user, querystring values on that request or values/presence of Request headers a PerRequest lifetime is appropriate. If you have settings that vary based on location of your service, for example, you saved values from web.config, then a the container is most likely created in global.asa and these objects can live as long as the container lives.
A concrete example:
You have a service as part of your site and you are migrating to vNext of that service. Users can opt-in by clicking a link that includes a parameter like &myService=vNext to see the new behavior. your Factory method uses the value of this parameter to select vNow or vNext for each request.
Here's some pseudo code to get you started:
container.RegisterInstance<IProductFactory>("enterprise", new EnterpriseProductFactory());
container.RegisterInstance<IProductFactory>("retail", new RetailProductFactory());
container.RegisterVersionedServiceFactory<IProductFactorySettings, IProductFactory>();
In this example RegisterVersionedServiceFactory is an extension method that does nothing but decide which of the IProductFactory instances to use for the current request. The factory provides the current instance (there are only two for the life of the service) to use for this request (thousands per seconds).
This pattern is what makes a very large site you probably used recently both very stable and very flexible. New versions of services are rolled out using this exact same pattern to help keep the site very stable.
I have a question, how can i get userId from Application controller? I saw many samples, how to get it from Hubs. But i don't know how can i call hub from controller in other way then
var context = GlobalHost.ConnectionManager.GetHubContext<MyHub>();
in the context i havent any id.
I saw samples like that, here i can call context and get UserId, but this works only in the Hub.
var name = context.User.Identity.Name;
I know that i can do something like that:
public class MyHub : Hub
{
public void Send(string userId, string message)
{
Clients.User(userId).send(message);
}
}
But i have to call hub from the controller.
Thanks for help
May I suggest a slightly different approach. In general that poking into the the hub from outside the signalr context doesn't work well or at least makes things more complicated.
You could have the controller act as client to the hub itself and expose the information you need via the hub to the controller. All you'd need is the SignalR Desktop Client package. While it adds an overhead, you'll have a much more compliant way for data retreivement and as a benefit a nice separation of concerns.
Here's a similar question that I replied to. HTH.
If you have some kind of authentication in your application, a good idea might be keeping a mapping between users and connections.
This way, whenever you want to send a message to a user, simply retrieve all that user's connectin IDs and send the message to all of them.
foreach(var connectionId in UserMapping)
context.Clints.Client(connectionId).sendMessage(message);
This way, you are able to send messages to specific clients from outside the hub and you are sure that all instances of the client get notified.
Take a look here for more information on Mapping SignalR Users to Connections.
Hope this helps.
Best of luck!
i found a solution.
By the way, thanks for your answers.
I try to use signalR from class which was calling by the application controller.
In the class i haven't got any context and special data about user who called server.
But i found into the controller info about which user calling the server.
this.User.Identity.Name
Happy coding ;)
I managed to create a chat application using SignalR and Asp.NET.
My next objective is to send and accept friend request.
Could anyone suggest some good sites/forums where I can get help regarding this.
Thanks
You need to think about this from a system design standpoint prior to approaching a solution directly with ASP.NET and SignalR. Some of the things you need to consider and decide on are:
How will one user be associated to another user in order to create a friendship? (ex: new table to group two users)
How should friend requests be made?
How will friend request denials work?
Once you start brainstorming on how you would want this all to work, you can then build it out on the server side prior to ever getting into SignalR. Assure all areas of functionality work appropriately and then you can expose these method calls to your clients front-end through SignalR.
The key is to break down each part of the process into components and working on it one step at a time.
to send friend request to specific user use hub method
Clients.Client(toConnectTo).sendRequest(currentname+" SentYouFriendRequest");
and call it on client
chat.client.sendRequest = function (msg) {
$('#sentmsg').append('<li>'+msg+'</li>');
};
Breeze.js - + Facing problem while accessing service metata.
Request for metadata is sent to
http://mylocalmachine:4625/WcfDataService1.svc/Metadata
but metadata is getting published at http://mylocalmachine:4625/WcfDataService1.svc/$Metadata
Your Breeze client must be configured to communicate with your remote service. As I read your question, it appears that you're trying to reach an OData data source whose data service name is "http://mylocalmachine:4625/WcfDataService1.svc".
If so, you'll have to tell Breeze to switch from its default Web Api dataService adapter to the OData dataService adapter. Do that during your application bootstrapping with a line such as:
breeze.config.initializeAdapterInstance("dataService", "OData");
Now, when you run your app and look at the network traffic, you should see that Breeze requests metadata with something like
http://mylocalmachine:4625/WcfDataService1.svc/$Metadata
There is a prerequisite JavaScript library that you will need to include on the page in order to use the OData adapater.
It's mentioned in the documentation:- dataJS.
Hope this helps.