Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET CORE Don't have app.UseEndpoints() Method

Just learning ASP.NET Core now and in some guides I see app.UseEndpoints() method.

But when I created my ASP NET CORE Project I've only seen app.Run in StartUp.cs

  1. So Need I install some utilities for this or UseEndPoints was removed?
  2. How Can I realize this method app.UseEndpoints(endpoints => { endpoints.MapHub<ChatHub>("/chat"); });
like image 995
Overmastered Avatar asked Apr 24 '20 08:04

Overmastered


1 Answers

If you are using Net Core 2.1, you have to configure it that way:

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using SignalRChat.Hubs;

namespace SignalRChat
{


public class Startup
{
    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

    public IConfiguration Configuration { get; }


    public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
        services.AddSignalR();
    }


    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {

        app.UseSignalR(routes =>
        {
            routes.MapHub<ChatHub>("/chat");
        });
        app.UseMvc();
    }
}

}

Only afrer version 3.0 you can use app.UseEndpoints

app.UseEndpoints(endpoints =>
        {              
            endpoints.MapHub<ChatHub>("/chat");
        });

See docs:

ASP.NET Core 2.1

ASP.NET Core 3.0 +

like image 200
Mateech Avatar answered Oct 30 '22 20:10

Mateech