forked from ServiceStackApps/Chat
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgrade to .net8 + ServiceStack v8 with endpoint routing
- Loading branch information
Showing
18 changed files
with
737 additions
and
730 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,24 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<AssemblyName>Chat</AssemblyName> | ||
<PackageId>Chat</PackageId> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel> | ||
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked> | ||
<PublishProfile>DefaultContainer</PublishProfile> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="ServiceStack.Text" Version="6.*" /> | ||
<PackageReference Include="ServiceStack.Interfaces" Version="6.*" /> | ||
<PackageReference Include="ServiceStack.Client" Version="6.*" /> | ||
<PackageReference Include="ServiceStack.Common" Version="6.*" /> | ||
<PackageReference Include="ServiceStack" Version="6.*" /> | ||
<PackageReference Include="ServiceStack.Mvc" Version="6.*" /> | ||
<PackageReference Include="ServiceStack.Redis" Version="6.*" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="8.*" /> | ||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.*" /> | ||
<PackageReference Include="ServiceStack.Text" Version="8.*" /> | ||
<PackageReference Include="ServiceStack.Interfaces" Version="8.*" /> | ||
<PackageReference Include="ServiceStack.Client" Version="8.*" /> | ||
<PackageReference Include="ServiceStack.Common" Version="8.*" /> | ||
<PackageReference Include="ServiceStack" Version="8.*" /> | ||
<PackageReference Include="ServiceStack.Mvc" Version="8.*" /> | ||
<PackageReference Include="ServiceStack.Redis" Version="8.*" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System.Net; | ||
using ServiceStack; | ||
using ServiceStack.Auth; | ||
|
||
[assembly: HostingStartup(typeof(Chat.AppHost))] | ||
|
||
namespace Chat; | ||
|
||
public class AppHost() : AppHostBase("Chat"), IHostingStartup | ||
{ | ||
public void Configure(IWebHostBuilder builder) => builder | ||
.ConfigureServices((context, services) => { | ||
// Configure ASP.NET Core IOC Dependencies | ||
services.AddSingleton<IChatHistory, MemoryChatHistory>(); | ||
services.AddPlugin(new ServerEventsFeature()); | ||
}); | ||
|
||
public override void Configure() | ||
{ | ||
SetConfig(new HostConfig | ||
{ | ||
DefaultContentType = MimeTypes.Json, | ||
AllowSessionIdsInHttpParams = true, | ||
}); | ||
|
||
this.CustomErrorHttpHandlers.Remove(HttpStatusCode.Forbidden); | ||
|
||
//Register all Authentication methods you want to enable for this web app. | ||
Plugins.Add(new AuthFeature(() => new AuthUserSession(), [ | ||
new TwitterAuthProvider(AppSettings), //Sign-in with Twitter | ||
new FacebookAuthProvider(AppSettings), //Sign-in with Facebook | ||
new GithubAuthProvider(AppSettings) //Sign-in with GitHub | ||
])); | ||
|
||
// for lte IE 9 support + allow connections from local web dev apps | ||
Plugins.Add(new CorsFeature( | ||
allowOriginWhitelist: ["http://localhost", "http://127.0.0.1:8080", "http://localhost:8080", "http://localhost:8081", "http://null.jsbin.com"], | ||
allowCredentials: true, | ||
allowedHeaders: "Content-Type, Allow, Authorization")); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using ServiceStack; | ||
using Chat.ServiceModel; | ||
|
||
namespace Chat; | ||
|
||
public interface IChatHistory | ||
{ | ||
long GetNextMessageId(string channel); | ||
|
||
void Log(string channel, ChatMessage msg); | ||
|
||
List<ChatMessage> GetRecentChatHistory(string channel, long? afterId, int? take); | ||
|
||
void Flush(); | ||
} | ||
|
||
public class MemoryChatHistory(IServerEvents serverEvents) : IChatHistory | ||
{ | ||
public int DefaultLimit { get; set; } = 100; | ||
|
||
Dictionary<string, List<ChatMessage>> MessagesMap = new(); | ||
|
||
public long GetNextMessageId(string channel) | ||
{ | ||
return serverEvents.GetNextSequence("chatMsg"); | ||
} | ||
|
||
public void Log(string channel, ChatMessage msg) | ||
{ | ||
if (!MessagesMap.TryGetValue(channel, out var msgs)) | ||
MessagesMap[channel] = msgs = new List<ChatMessage>(); | ||
|
||
msgs.Add(msg); | ||
} | ||
|
||
public List<ChatMessage> GetRecentChatHistory(string channel, long? afterId, int? take) | ||
{ | ||
if (!MessagesMap.TryGetValue(channel, out var msgs)) | ||
return []; | ||
|
||
var ret = msgs.Where(x => x.Id > afterId.GetValueOrDefault()) | ||
.Reverse() //get latest logs | ||
.Take(take.GetValueOrDefault(DefaultLimit)) | ||
.Reverse(); //reverse back | ||
|
||
return ret.ToList(); | ||
} | ||
|
||
public void Flush() | ||
{ | ||
MessagesMap = new Dictionary<string, List<ChatMessage>>(); | ||
} | ||
} |
Oops, something went wrong.