Skip to content

Commit 0428ba3

Browse files
committed
Added stub JsonServicesConnectionManager class.
1 parent 58ef991 commit 0428ba3

File tree

7 files changed

+104
-35
lines changed

7 files changed

+104
-35
lines changed
File renamed without changes.

sample/sample-core-server/JsonServices.Sample.CoreServer.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,10 @@
1313
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All" />
1414
</ItemGroup>
1515

16+
<ItemGroup>
17+
<ProjectReference Include="..\..\src\JsonServices.Core.Tests\JsonServices.Core.Tests.csproj" />
18+
<ProjectReference Include="..\..\src\JsonServices.Core\JsonServices.Core.csproj" />
19+
<ProjectReference Include="..\..\src\JsonServices.Serialization.ServiceStack\JsonServices.Serialization.ServiceStack.csproj" />
20+
</ItemGroup>
21+
1622
</Project>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using JsonServices.Transport;
6+
7+
namespace JsonServices.Sample.CoreServer
8+
{
9+
public class JsonServicesConnectionManager : IServer
10+
{
11+
public bool Started { get; private set; }
12+
13+
public void Start() => Started = true;
14+
15+
public void Dispose() => Started = false;
16+
17+
public IConnection TryGetConnection(string connectionId)
18+
{
19+
throw new NotImplementedException();
20+
}
21+
22+
public Task SendAsync(string connectionId, string data)
23+
{
24+
throw new NotImplementedException();
25+
}
26+
27+
public IEnumerable<IConnection> Connections => throw new NotImplementedException();
28+
29+
public event EventHandler<MessageEventArgs> MessageReceived;
30+
31+
public event EventHandler<MessageEventArgs> ClientConnected;
32+
33+
public event EventHandler<MessageEventArgs> ClientDisconnected;
34+
}
35+
}

sample/sample-core-server/JsonServicesMiddleware.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Threading.Tasks;
5+
using JsonServices.Transport;
56
using Microsoft.AspNetCore.Http;
67

78
namespace JsonServices.Sample.CoreServer
@@ -10,9 +11,12 @@ public class JsonServicesMiddleware
1011
{
1112
private RequestDelegate Next { get; }
1213

13-
public JsonServicesMiddleware(RequestDelegate next)
14+
private JsonServicesConnectionManager ConnectionManager { get; }
15+
16+
public JsonServicesMiddleware(RequestDelegate next, IServer connectionManager)
1417
{
1518
Next = next;
19+
ConnectionManager = (JsonServicesConnectionManager)connectionManager;
1620
}
1721

1822
public async Task InvokeAsync(HttpContext context)

sample/sample-core-server/JsonServicesMiddlewareExtensions.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,30 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Threading.Tasks;
5+
using JsonServices.Serialization;
6+
using JsonServices.Services;
7+
using JsonServices.Transport;
58
using Microsoft.AspNetCore.Builder;
9+
using Microsoft.Extensions.DependencyInjection;
610

711
namespace JsonServices.Sample.CoreServer
812
{
913
public static class JsonServicesMiddlewareExtensions
1014
{
1115
public static IApplicationBuilder UseJsonServices(this IApplicationBuilder builder) =>
1216
builder.UseMiddleware<JsonServicesMiddleware>();
17+
18+
public static IServiceCollection AddJsonServices<TSerializer, TServiceExecutor, TMessageTypeProvider>(this IServiceCollection services)
19+
where TSerializer : class, ISerializer
20+
where TServiceExecutor : class, IServiceExecutor
21+
where TMessageTypeProvider : class, IMessageTypeProvider
22+
{
23+
services.AddSingleton<ISerializer, TSerializer>();
24+
services.AddSingleton<IServiceExecutor, TServiceExecutor>();
25+
services.AddSingleton<IMessageTypeProvider, TMessageTypeProvider>();
26+
services.AddSingleton<IServer, JsonServicesConnectionManager>();
27+
services.AddSingleton<JsonServer>();
28+
return services;
29+
}
1330
}
1431
}

sample/sample-core-server/Program.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@
1010

1111
namespace JsonServices.Sample.CoreServer
1212
{
13-
public class Program
14-
{
15-
public static void Main(string[] args)
16-
{
17-
var builder = CreateWebHostBuilder(args);
18-
var webHost = builder.Build();
19-
webHost.Run();
20-
}
13+
public class Program
14+
{
15+
public static void Main(string[] args)
16+
{
17+
var builder = CreateWebHostBuilder(args);
18+
var webHost = builder.Build();
19+
webHost.Run();
20+
}
2121

22-
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
23-
WebHost.CreateDefaultBuilder(args)
24-
.UseStartup<Startup>();
25-
}
22+
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
23+
WebHost.CreateDefaultBuilder(args)
24+
.UseStartup<Startup>();
25+
}
2626
}

sample/sample-core-server/Startup.cs

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,36 @@
99

1010
namespace JsonServices.Sample.CoreServer
1111
{
12-
public class Startup
13-
{
14-
// This method gets called by the runtime. Use this method to add services to the container.
15-
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
16-
public void ConfigureServices(IServiceCollection services)
17-
{
18-
}
12+
using Serializer = Serialization.ServiceStack.Serializer;
13+
using Executor = Tests.Services.StubExecutor;
14+
using TypeProvider = Tests.Services.StubMessageTypeProvider;
1915

20-
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
21-
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
22-
{
23-
if (env.IsDevelopment())
24-
{
25-
app.UseDeveloperExceptionPage();
26-
}
16+
public class Startup
17+
{
18+
// This method gets called by the runtime. Use this method to add services to the container.
19+
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
20+
public void ConfigureServices(IServiceCollection services)
21+
{
22+
// initialize JsonServices classes
23+
services.AddJsonServices<Serializer, Executor, TypeProvider>();
24+
}
2725

28-
app.UseWebSockets();
29-
app.UseJsonServices();
26+
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
27+
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
28+
{
29+
if (env.IsDevelopment())
30+
{
31+
app.UseDeveloperExceptionPage();
32+
}
3033

31-
app.Run(async (context) =>
32-
{
33-
await context.Response.WriteAsync("Hello World!");
34-
});
35-
}
36-
}
34+
// setup JsonServices request pipeline
35+
app.UseWebSockets();
36+
app.UseJsonServices();
37+
38+
app.Run(async (context) =>
39+
{
40+
await context.Response.WriteAsync("Hello World!");
41+
});
42+
}
43+
}
3744
}

0 commit comments

Comments
 (0)