Ticket T846735
Visible to All Users

chatting/messaging in the XAF application : best way to query the XPO objects from the Hub Class in signalR

created 5 years ago

I am using SignalR to the chatting application along with XAF framework. as in most of the applications we need to show the online users and then an user can start a chat with another so to get the list I have to write a complex query using 4-5 tables so my question is what is the best way to query the tables/XPO from the Hub class.
In the Below class i have another method where I want to get all the online users and display in a list in the page.

C#
[HubName("ChatHub")] public class ChatHub : Hub<IChatHub> { public void ClientWelcomeMessage(string message) { Clients.All.ClientWelcomeMessage(message); } }

Answers approved by DevExpress Support

created 5 years ago

Hello,

In XAF applications, you can use Object Space to query or modify data. Refer to the Create, Read, Update, and Delete Data article for additional information.

Consider adding a property of the XafApplication type to your ChatHub class, and use the XafApplication.CreateObjectSpace method to create an Object Space instance when you need to query or modify data.

If ChatHub's lifetime equals the XafApplication lifetime, you can create a ChatHub instance in the application entry point (the Program.cs file in a Win application and the Global.asax file in a Web application) and pass an XafApplication object as a constructor parameter.

Let me know if you have additional questions. I will be happy to answer them.

P.S.
To help us prioritize development efforts, please cast your vote for features/capabilities you’d like to see us introduce in 2020: eXpressApp Framework Roadmap 2020 - Your Vote Counts.

    Show previous comments (3)
    DevExpress Support Team 5 years ago

      Hi,

      I followed the Adding SignalR to an ASP.NET WebForms Project and ASP.NET SignalR Hubs API Guide - JavaScript Client articles to add SignalR to an XAF Web application. I've attached my results. In my project, a user will receive a notification if another user logs in. I've done this by calling my Hub in the application OnLoggedOn method.

        Hey Gosha,
        My question is how to get the data from DB/update data in DB through the signalR hub class i.e I want to get all the online users and display in the list and user and select any online user and chat and save the messages in the DB. so Main concern is how to connect/query the DB in hub class

        DevExpress Support Team 5 years ago

          Hi,

          Please follow the recommendations Uriah provided in his answer to perform CRUD operations in your SignalR hub. The Create, Read, Update and Delete Data article lists our API used in such scenarios. In short, you need to create an ObjectSpace instance to call its corresponding methods. To create an ObjectSpace instance, use the XAF application CreateObjectSpace method. In XAF Web, you can access an XAF application instance to call the CreateObjectSpace method by using the static WebApplication.Instance property.

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.