Skip to content

Commit

Permalink
registering configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidEggenberger committed Apr 26, 2024
1 parent c60bd67 commit 0741340
Show file tree
Hide file tree
Showing 14 changed files with 134 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Modules.Subscriptions.Features.Infrastructure.Configuration;
using Modules.Subscriptions.Features.Infrastructure.EFCore;
using Shared.Features.EFCore;
using Shared.Features.Modules;
using Shared.Features.Modules.Configuration;
using Stripe;
using System.Reflection;

Expand All @@ -14,11 +18,9 @@ public class SubscriptionsModuleStartup : IModuleStartup
public void ConfigureServices(IServiceCollection services, IConfiguration configuration)
{
StripeConfiguration.ApiKey = configuration["Stripe:StripeKey"];
//services.Configure<StripeOptions>(configuration);
//services.AddScoped<IStripeSubscriptionService, StripeSubscriptionTypeService>();

services.AddControllers()
.AddApplicationPart(typeof(SubscriptionsModuleStartup).Assembly);
services.RegisterDbContext<SubscriptionsDbContext>("subscriptions");
services.RegisterModuleConfiguration<SubscriptionsConfiguration, SubscriptionsConfigurationValidator>(configuration);
}

public void Configure(IApplicationBuilder app, IHostEnvironment env)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using Modules.TenantIdentity.Features.DomainFeatures.UserAggregate.Application.Commands;
using Shared.Features.Server;

namespace Web.Server.Controllers.Identity
namespace Modules.TenantIdentity.Web.Server
{
[Route("api/[controller]")]
[AllowAnonymous]
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

35 changes: 35 additions & 0 deletions Source/Shared/Features/Registrator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Shared.Features.Messaging;
using Shared.Features.EFCore;
using Shared.Features.Modules;
using Shared.Features.Server.ExecutionContext;

namespace Shared.Features
{
public static class Registrator
{
public static IServiceCollection AddSharedFeatures(this IServiceCollection services)
{
var serviceProvider = services.BuildServiceProvider();
var configuration = serviceProvider.GetRequiredService<IConfiguration>();

services.AddMessaging();
services.AddEFCore(configuration);
services.AddServerExecutionContext();

return services;
}

public static IApplicationBuilder UseSharedFeaturesMiddleware(this IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseEFCoreMiddleware();
app.UseServerExecutionContextMiddleware();
app.UseModulesMiddleware(env);

return app;
}
}
}
8 changes: 8 additions & 0 deletions Source/Shared/Features/SignalR/NotificationHub.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Microsoft.AspNetCore.SignalR;

namespace Shared.Features.SignalR
{
public class NotificationHub : Hub
{
}
}
26 changes: 26 additions & 0 deletions Source/Shared/Features/SignalR/NotificationHubService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Microsoft.AspNetCore.SignalR;
using Shared.Kernel.Constants;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Shared.Features.SignalR
{
public class NotificationHubService
{
private readonly IHubContext<NotificationHub> notificationHubContext;

public NotificationHubService(IHubContext<NotificationHub> notificationHubContext)
{
this.notificationHubContext = notificationHubContext;
}

public async Task SendNotificationAsync(Guid userId, string triggeredMethodName)
{
await notificationHubContext.Clients.User(userId.ToString()).SendAsync(triggeredMethodName);
}
}
}
27 changes: 27 additions & 0 deletions Source/Shared/Features/SignalR/Registrator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.DependencyInjection;
using Shared.Kernel.Constants;

namespace Shared.Features.SignalR
{
public static class Registrator
{
public static IServiceCollection Add_SignalR(this IServiceCollection services)
{
services.AddSingleton<IUserIdProvider, UserIdProvider>();
services.AddScoped<NotificationHubService>();
return services;
}

public static IApplicationBuilder UseSignalRMiddleware(this IApplicationBuilder app)
{
app.UseEndpoints(endpoints =>
{
endpoints.MapHub<NotificationHub>(NotificationHubConstants.Hub);
});

return app;
}
}
}
15 changes: 15 additions & 0 deletions Source/Shared/Features/SignalR/UserIdProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Microsoft.AspNetCore.SignalR;
using Shared.Kernel.Extensions.ClaimsPrincipal;

namespace Shared.Features.SignalR
{
public class UserIdProvider : IUserIdProvider
{
public string GetUserId(HubConnectionContext connection)
{
return connection.User.Identity.IsAuthenticated
? connection.User?.GetUserId<string>()
: string.Empty;
}
}
}
7 changes: 7 additions & 0 deletions Source/Shared/Kernel/Constants/NotificationHubConstants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Shared.Kernel.Constants
{
public class NotificationHubConstants
{
public const string Hub = "NotificationHub";
}
}
2 changes: 1 addition & 1 deletion Source/Web/Server/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
"applicationUrl": "https://localhost:5001",
"dotnetRunMessages": "true",
"launchUrl": "/"
"launchUrl": ""
},
"Docker": {
"commandName": "Docker",
Expand Down
8 changes: 8 additions & 0 deletions Source/Web/Server/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Web.Server.BuildingBlocks;
using Modules.Subscriptions.Features;
using Modules.TenantIdentity.Features;
using Shared.Features;

namespace Web.Server
{
Expand All @@ -22,9 +23,15 @@ public Startup(IConfiguration configuration, IWebHostEnvironment webHostEnvironm
Configuration = configuration;
WebHostEnvironment = webHostEnvironment;
}

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.AddRazorPages();
services.AddServerSideBlazor();

services.AddSharedFeatures();
services.AddBuildingBlocks();

services.AddModule<ChannelsModuleStartup>(Configuration);
Expand All @@ -46,6 +53,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
app.UseAuthentication();
app.UseAuthorization();

app.UseSharedFeaturesMiddleware(env);
app.UseBuildingBlocks();

app.UseEndpoints(endpoints =>
Expand Down
18 changes: 0 additions & 18 deletions Source/Web/Server/appsettings.Docker.json

This file was deleted.

0 comments on commit 0741340

Please sign in to comment.