SignalR

SignalR is an ASP.NET Core library that allows server-side code to be instantly pushed to the client.

Prerequisites

  • Visual Studio 2019 or higher
  • Azure account (to publish SignalR service)

Steps

  1. Create ASP.NET Core web application in Visual Studio and name it UnoChat.Service.

    project-template

  2. Add SignalR Hub to your [YourProjectName].Service project in a Hubs folder.

  3. In your Startup.cs file, add your SignalR service and a CORS policy to the ConfigureServices method.

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddRazorPages();
        services.AddSignalR();
    
        services.AddCors(o => o.AddPolicy(
            "CorsPolicy",
            builder => builder
                .AllowAnyOrigin()
                .AllowAnyMethod()
                .AllowAnyHeader()
        ));
    }
    
  4. In your Configure method, add your CORS policy and Hubs endpoint

    app.UseCors("CorsPolicy");
    
    app.UseEndpoints(endpoints =>
    {
        endpoints.MapRazorPages();
        endpoints.MapHub<Hubs.[YourProjectHub]>("/yourProjectHub");
    });
    

You now have a SignalR service that you can use with your Uno application!