Fix Hub Route issue on Registering ...
This commit is contained in:
+51
-26
@@ -19,14 +19,17 @@ using xPushService.Interfaces;
|
||||
using xPushService.Providers;
|
||||
using xPushService.Store;
|
||||
|
||||
namespace xPushService.DI {
|
||||
public static partial class XDIHelperExtension {
|
||||
namespace xPushService.DI
|
||||
{
|
||||
public static partial class XDIHelperExtension
|
||||
{
|
||||
/// <summary>
|
||||
/// Extract Module Configuration from provided IConfiguration
|
||||
/// </summary>
|
||||
/// <param name="config"></param>
|
||||
/// <returns>an instance of XPushServiceConfiguration</returns>
|
||||
public static XPushServiceConfiguration GetXPushServiceConfiguration (this IConfiguration config) {
|
||||
public static XPushServiceConfiguration GetXPushServiceConfiguration(this IConfiguration config)
|
||||
{
|
||||
//
|
||||
var xPushConfigSection = config.GetSection(XPushServiceConstants.XConfigurationNodes.XPushServiceConfiguration);
|
||||
return xPushConfigSection.Get<XPushServiceConfiguration>();
|
||||
@@ -40,10 +43,12 @@ namespace xPushService.DI {
|
||||
public static void AddXPushServiceHelper(
|
||||
this IServiceCollection services,
|
||||
XPushServiceHelper helper
|
||||
) {
|
||||
)
|
||||
{
|
||||
//
|
||||
// Validate Args ...
|
||||
if (helper.IsNull ()) {
|
||||
if (helper.IsNull())
|
||||
{
|
||||
//
|
||||
Log("AddXPushServiceHelper failed, helper not provided ...");
|
||||
throw XException.InvalidArgs.ToException();
|
||||
@@ -63,7 +68,8 @@ namespace xPushService.DI {
|
||||
this IServiceCollection services,
|
||||
IConfiguration config,
|
||||
ServiceLifetime lifeTime = ServiceLifetime.Singleton
|
||||
) {
|
||||
)
|
||||
{
|
||||
AddPushService(
|
||||
services,
|
||||
config.GetXPushServiceConfiguration(),
|
||||
@@ -80,7 +86,8 @@ namespace xPushService.DI {
|
||||
this IServiceCollection services,
|
||||
XPushServiceConfiguration config,
|
||||
ServiceLifetime lifeTime = ServiceLifetime.Singleton
|
||||
) {
|
||||
)
|
||||
{
|
||||
AddPushService(
|
||||
services,
|
||||
config,
|
||||
@@ -96,11 +103,13 @@ namespace xPushService.DI {
|
||||
public static void UseXPushService(
|
||||
this IApplicationBuilder app,
|
||||
XPushServiceHelper helper
|
||||
) {
|
||||
)
|
||||
{
|
||||
//
|
||||
// Validate Args ...
|
||||
var isHelperExists = !helper.IsNull();
|
||||
if (!isHelperExists) {
|
||||
if (!isHelperExists)
|
||||
{
|
||||
//
|
||||
Log("AddXPushServiceHelper failed, helper not provided ...");
|
||||
throw XException.InvalidArgs.ToException();
|
||||
@@ -108,7 +117,8 @@ namespace xPushService.DI {
|
||||
|
||||
//
|
||||
// Create an Scope for Accessing Registered Services ...
|
||||
using (var scope = app.ApplicationServices.CreateScope ()) {
|
||||
using (var scope = app.ApplicationServices.CreateScope())
|
||||
{
|
||||
//
|
||||
// try to Retrieve Configuration ....
|
||||
var config = scope.ServiceProvider.GetService<XPushServiceConfiguration>();
|
||||
@@ -116,7 +126,8 @@ namespace xPushService.DI {
|
||||
config.IsNull() ||
|
||||
config.BaseRoute.IsNullOrEmpty() ||
|
||||
config.BaseRoute.Trim().IsNullOrEmpty()
|
||||
) {
|
||||
)
|
||||
{
|
||||
//
|
||||
Log("AddXPushServiceHelper failed, Configuration not provided ...");
|
||||
throw XException.InvalidConfiguration.ToException();
|
||||
@@ -127,7 +138,8 @@ namespace xPushService.DI {
|
||||
//
|
||||
// Base Reoute ...
|
||||
config.BaseRoute = config.BaseRoute.ToNormalString();
|
||||
if (!config.BaseRoute.StartsWith ("/")) {
|
||||
if (!config.BaseRoute.StartsWith("/"))
|
||||
{
|
||||
config.BaseRoute = "/" + config.BaseRoute;
|
||||
}
|
||||
#endregion
|
||||
@@ -141,11 +153,13 @@ namespace xPushService.DI {
|
||||
// Try to Register Hubs ...
|
||||
//
|
||||
// Use SignalR in App ...
|
||||
app.UseSignalR (routes => {
|
||||
app.UseSignalR(routes =>
|
||||
{
|
||||
//
|
||||
helper.GetHubs ().ForEach (hubDescriptor => {
|
||||
helper.GetHubs().ForEach(hubDescriptor =>
|
||||
{
|
||||
//
|
||||
var hubRoute = Path.Combine (config.BaseRoute, hubDescriptor.Route);
|
||||
var hubRoute = config.BaseRoute + "/" + hubDescriptor.Route; // Path.Combine (config.BaseRoute, hubDescriptor.Route);
|
||||
hubRoutes.Add(hubRoute);
|
||||
Console.WriteLine($"XPushService HubRoute: {hubRoute}");
|
||||
|
||||
@@ -157,7 +171,8 @@ namespace xPushService.DI {
|
||||
m.Name == "MapHub" &&
|
||||
m.GetParameters().Length == 1
|
||||
);
|
||||
if (mapHubMethod.IsNull ()) {
|
||||
if (mapHubMethod.IsNull())
|
||||
{
|
||||
throw XException.ActionFailed.ToException();
|
||||
}
|
||||
|
||||
@@ -181,7 +196,8 @@ namespace xPushService.DI {
|
||||
/// print a log in Console ...
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
private static void Log (string message) {
|
||||
private static void Log(string message)
|
||||
{
|
||||
Console.WriteLine($"{XLogTag} => {message}");
|
||||
}
|
||||
|
||||
@@ -195,7 +211,8 @@ namespace xPushService.DI {
|
||||
IServiceCollection services,
|
||||
XPushServiceConfiguration config,
|
||||
ServiceLifetime lifeTime
|
||||
) {
|
||||
)
|
||||
{
|
||||
//
|
||||
#region Validate Args ...
|
||||
//
|
||||
@@ -204,7 +221,8 @@ namespace xPushService.DI {
|
||||
//
|
||||
// Services ...
|
||||
var isServicesExists = !services.IsNull();
|
||||
if (!isServicesExists) {
|
||||
if (!isServicesExists)
|
||||
{
|
||||
//
|
||||
Log("AddXPushServiceHelper failed, services not provided ...");
|
||||
throw exception;
|
||||
@@ -213,7 +231,8 @@ namespace xPushService.DI {
|
||||
//
|
||||
// Config ...
|
||||
var isConfigExists = !config.IsNull();
|
||||
if (!isConfigExists) {
|
||||
if (!isConfigExists)
|
||||
{
|
||||
//
|
||||
Log("AddXPushServiceHelper failed, configuration not provided ...");
|
||||
throw exception;
|
||||
@@ -222,7 +241,8 @@ namespace xPushService.DI {
|
||||
//
|
||||
// Lifetime ...
|
||||
var isLifetimeExists = !lifeTime.IsNull();
|
||||
if (!isLifetimeExists) {
|
||||
if (!isLifetimeExists)
|
||||
{
|
||||
//
|
||||
Log("AddXPushServiceHelper failed, lifetime not provided ...");
|
||||
throw exception;
|
||||
@@ -237,7 +257,8 @@ namespace xPushService.DI {
|
||||
#region Try to Register Stores ...
|
||||
//
|
||||
var groupStore = services.GetRegisteredService<IXPushGroupStore>();
|
||||
if (groupStore.IsNull ()) {
|
||||
if (groupStore.IsNull())
|
||||
{
|
||||
//
|
||||
Log($"there is no provided PushGroupStore, try to register XPushGroupInMemoryStore ...");
|
||||
groupStore = new XPushGroupInMemoryStore();
|
||||
@@ -246,7 +267,8 @@ namespace xPushService.DI {
|
||||
|
||||
//
|
||||
var connectionStore = services.GetRegisteredService<IXPushConnectionStore>();
|
||||
if (connectionStore.IsNull ()) {
|
||||
if (connectionStore.IsNull())
|
||||
{
|
||||
//
|
||||
Log($"there is no provided XPushConnectionStore, try to register XPushConnectionInMemoryStore ...");
|
||||
connectionStore = new XPushConnectionInMemoryStore();
|
||||
@@ -255,7 +277,8 @@ namespace xPushService.DI {
|
||||
|
||||
//
|
||||
var webRtcConnectionStore = services.GetRegisteredService<IXWebRTCConnectionStore>();
|
||||
if (webRtcConnectionStore.IsNull ()) {
|
||||
if (webRtcConnectionStore.IsNull())
|
||||
{
|
||||
//
|
||||
Log($"there is no provided XWebRTCConnectionStore, try to register XWebRTCConnectionInMemoryStore ...");
|
||||
webRtcConnectionStore = new XWebRTCConnectionInMemoryStore();
|
||||
@@ -269,7 +292,8 @@ namespace xPushService.DI {
|
||||
|
||||
//
|
||||
// Add NewtonSoftJson Protocol ...
|
||||
builder.AddNewtonsoftJsonProtocol (x => {
|
||||
builder.AddNewtonsoftJsonProtocol(x =>
|
||||
{
|
||||
x.PayloadSerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
|
||||
x.PayloadSerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
|
||||
});
|
||||
@@ -280,7 +304,8 @@ namespace xPushService.DI {
|
||||
|
||||
//
|
||||
// add Message Protocol Support ...
|
||||
if (config.AddSupportMessageProtocol) {
|
||||
if (config.AddSupportMessageProtocol)
|
||||
{
|
||||
builder.AddMessagePackProtocol();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user