Skip to content

Commit

Permalink
update to .NET5
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigoreis committed Aug 31, 2021
1 parent 8090f2f commit e685b57
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 149 deletions.
31 changes: 15 additions & 16 deletions src/Chat.Ui/Chat.Ui.csproj
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
<LangVersion>Latest</LangVersion>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<LangVersion>latest</LangVersion>
<IsPackable>false</IsPackable>
<ProjectGuid>{6DEA27FC-54FF-4716-9E6F-668CC44009B9}</ProjectGuid>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="5.0.9"/>
<PackageReference Include="System.Text.Json" Version="5.0.2"/>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
</ItemGroup>


<ItemGroup>
<ProjectReference Include="..\Chat.Models\Chat.Models.csproj" />
<ProjectReference Include="..\Chat.Repositories.Abstractions\Chat.Repositories.Abstractions.csproj" />
<ProjectReference Include="..\Chat.Repositories.DependencyInjections\Chat.Repositories.DependencyInjections.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Chat.Models\Chat.Models.csproj"/>
<ProjectReference Include="..\Chat.Repositories.Abstractions\Chat.Repositories.Abstractions.csproj"/>
<ProjectReference Include="..\Chat.Repositories.DependencyInjections\Chat.Repositories.DependencyInjections.csproj"/>
</ItemGroup>

</Project>
11 changes: 6 additions & 5 deletions src/Chat.Ui/Hub/ChatHub.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System.Text.Json;
using System.Threading.Tasks;
using Chat.Models;
using Chat.Repositories.Abstractions;
using Microsoft.AspNetCore.SignalR;
using Newtonsoft.Json;
using System.Threading.Tasks;

namespace Chat.Hubs
namespace Chat.Ui.Hub
{
public class ChatHub : Hub
public class ChatHub : Microsoft.AspNetCore.SignalR.Hub
{
private readonly IConnectionsRepository _connectionsRepository;

Expand All @@ -17,9 +17,10 @@ public ChatHub(IConnectionsRepository connectionsRepository)

public override Task OnConnectedAsync()
{
var user = JsonConvert.DeserializeObject<User>(Context.GetHttpContext().Request.Query["user"]);
var user = JsonSerializer.Deserialize<User>(Context.GetHttpContext().Request.Query["user"]);
_connectionsRepository.Add(Context.ConnectionId, user);
Clients.All.SendAsync("chat", _connectionsRepository.GetAllUser(), user);

return base.OnConnectedAsync();
}

Expand Down
6 changes: 1 addition & 5 deletions src/Chat.Ui/Pages/Error.cshtml.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace Chat.Pages
namespace Chat.Ui.Pages
{
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public class ErrorModel : PageModel
Expand Down
9 changes: 2 additions & 7 deletions src/Chat.Ui/Pages/Index.cshtml.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace Chat.Pages
namespace Chat.Ui.Pages
{
public class IndexModel : PageModel
{
Expand Down
9 changes: 2 additions & 7 deletions src/Chat.Ui/Pages/Privacy.cshtml.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace Chat.Pages
namespace Chat.Ui.Pages
{
public class PrivacyModel : PageModel
{
Expand Down
3 changes: 1 addition & 2 deletions src/Chat.Ui/Pages/_ViewImports.cshtml
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
@using Chat
@namespace Chat.Pages
@namespace Chat.Ui.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
1 change: 1 addition & 0 deletions src/Chat.Ui/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Chat.Ui;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
Expand Down
17 changes: 1 addition & 16 deletions src/Chat.Ui/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,6 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:5170",
"sslPort": 44333
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": false,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Chat": {
"Chat.Ui": {
"commandName": "Project",
"launchBrowser": false,
"applicationUrl": "https://localhost:5001;http://localhost:5000",
Expand Down
49 changes: 27 additions & 22 deletions src/Chat.Ui/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,37 +1,39 @@
using Chat.Hubs;
using Chat.Repositories.DependencyInjections;
using Chat.Ui.Hub;
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 Microsoft.Extensions.Hosting;

namespace Chat
namespace Chat.Ui
{
public class Startup
{
public IConfiguration Configuration { get; }
private readonly IConfiguration _configuration;

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

public void ConfigureServices(IServiceCollection services)
{
services.Configure<CookiePolicyOptions>(options =>
{
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
services
.AddRouting(options =>
{
options.LowercaseUrls = true;
options.LowercaseQueryStrings = true;
}
)
.AddRazorPages()
.AddRazorRuntimeCompilation();

services.AddRepositories();
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
services.AddSignalR();
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
Expand All @@ -45,14 +47,17 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)

app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseCookiePolicy();

app.UseMvc();

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

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

0 comments on commit e685b57

Please sign in to comment.