-
Notifications
You must be signed in to change notification settings - Fork 558
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move IdentityServer To Separate & Shared Project
- Loading branch information
1 parent
631d18c
commit 7c3476a
Showing
1,317 changed files
with
13,307 additions
and
76,834 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 |
---|---|---|
|
@@ -36,9 +36,6 @@ jobs: | |
- name: Publish Identity.Api | ||
run: dotnet publish Services.Identity/ClassifiedAds.Services.Identity.Api/*.csproj --configuration Release | ||
|
||
- name: Publish Identity.AuthServer | ||
run: dotnet publish Services.Identity/ClassifiedAds.Services.Identity.AuthServer/*.csproj --configuration Release | ||
|
||
- name: Publish Identity.Grpc | ||
run: dotnet publish Services.Identity/ClassifiedAds.Services.Identity.Grpc/*.csproj --configuration Release | ||
|
||
|
@@ -78,12 +75,6 @@ jobs: | |
name: ClassifiedAds.Services.Identity.Api | ||
path: src/Microservices/Services.Identity/ClassifiedAds.Services.Identity.Api/bin/Release/net6.0/publish | ||
|
||
- name: Upload ClassifiedAds.Services.Identity.AuthServer | ||
uses: actions/[email protected] | ||
with: | ||
name: ClassifiedAds.Services.Identity.AuthServer | ||
path: src/Microservices/Services.Identity/ClassifiedAds.Services.Identity.AuthServer/bin/Release/net6.0/publish | ||
|
||
- name: Upload ClassifiedAds.Services.Identity.Grpc | ||
uses: actions/[email protected] | ||
with: | ||
|
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 |
---|---|---|
|
@@ -30,9 +30,6 @@ jobs: | |
- name: Publish ClassifiedAds.BackgroundServer | ||
run: dotnet publish ClassifiedAds.BackgroundServer/*.csproj --configuration Release | ||
|
||
- name: Publish ClassifiedAds.IdentityServer | ||
run: dotnet publish ClassifiedAds.IdentityServer/*.csproj --configuration Release | ||
|
||
- name: Publish ClassifiedAds.Migrator | ||
run: dotnet publish ClassifiedAds.Migrator/*.csproj --configuration Release | ||
|
||
|
@@ -45,12 +42,6 @@ jobs: | |
name: ClassifiedAds.BackgroundServer | ||
path: src/ModularMonolith/ClassifiedAds.BackgroundServer/bin/Release/net6.0/publish | ||
|
||
- name: Upload ClassifiedAds.IdentityServer | ||
uses: actions/[email protected] | ||
with: | ||
name: ClassifiedAds.IdentityServer | ||
path: src/ModularMonolith/ClassifiedAds.IdentityServer/bin/Release/net6.0/publish | ||
|
||
- name: Upload ClassifiedAds.Migrator | ||
uses: actions/[email protected] | ||
with: | ||
|
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 |
---|---|---|
|
@@ -39,9 +39,6 @@ jobs: | |
- name: Publish ClassifiedAds.WebAPI | ||
run: dotnet publish ClassifiedAds.WebAPI/*.csproj --configuration Release | ||
|
||
- name: Publish ClassifiedAds.IdentityServer | ||
run: dotnet publish ClassifiedAds.IdentityServer/*.csproj --configuration Release | ||
|
||
- name: Publish ClassifiedAds.WebMVC | ||
run: dotnet publish ClassifiedAds.WebMVC/*.csproj --configuration Release | ||
|
||
|
@@ -74,12 +71,6 @@ jobs: | |
with: | ||
name: ClassifiedAds.WebAPI | ||
path: src/Monolith/ClassifiedAds.WebAPI/bin/Release/net6.0/publish | ||
|
||
- name: Upload ClassifiedAds.IdentityServer | ||
uses: actions/[email protected] | ||
with: | ||
name: ClassifiedAds.IdentityServer | ||
path: src/Monolith/ClassifiedAds.IdentityServer/bin/Release/net6.0/publish | ||
|
||
- name: Upload ClassifiedAds.WebMVC | ||
uses: actions/[email protected] | ||
|
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
File renamed without changes.
97 changes: 97 additions & 0 deletions
97
src/IdentityServer/ClassifiedAds.Application/ApplicationServicesExtensions.cs
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,97 @@ | ||
using ClassifiedAds.Application; | ||
using ClassifiedAds.Application.EmailMessages.Services; | ||
using ClassifiedAds.Application.EventLogs; | ||
using ClassifiedAds.Application.Products.Services; | ||
using ClassifiedAds.Application.SmsMessages.Services; | ||
using ClassifiedAds.Application.Users.Services; | ||
using ClassifiedAds.Domain.Entities; | ||
using ClassifiedAds.Domain.Events; | ||
using System; | ||
using System.Linq; | ||
using System.Reflection; | ||
|
||
namespace Microsoft.Extensions.DependencyInjection | ||
{ | ||
public static class ApplicationServicesExtensions | ||
{ | ||
public static IServiceCollection AddApplicationServices(this IServiceCollection services, Action<Type, Type, ServiceLifetime> configureInterceptor = null) | ||
{ | ||
DomainEvents.RegisterHandlers(Assembly.GetExecutingAssembly(), services); | ||
|
||
services | ||
.AddScoped<IDomainEvents, DomainEvents>() | ||
.AddScoped(typeof(ICrudService<>), typeof(CrudService<>)) | ||
.AddScoped<IUserService, UserService>() | ||
.AddScoped<IProductService, ProductService>() | ||
.AddScoped<EmailMessageService>() | ||
.AddScoped<SmsMessageService>() | ||
.AddScoped<PublishEventService>(); | ||
|
||
if (configureInterceptor != null) | ||
{ | ||
var aggregateRootTypes = typeof(IAggregateRoot).Assembly.GetTypes().Where(x => x.BaseType == typeof(Entity<Guid>) && x.GetInterfaces().Contains(typeof(IAggregateRoot))).ToList(); | ||
foreach (var type in aggregateRootTypes) | ||
{ | ||
configureInterceptor(typeof(ICrudService<>).MakeGenericType(type), typeof(CrudService<>).MakeGenericType(type), ServiceLifetime.Scoped); | ||
} | ||
|
||
configureInterceptor(typeof(IUserService), typeof(UserService), ServiceLifetime.Scoped); | ||
configureInterceptor(typeof(IProductService), typeof(ProductService), ServiceLifetime.Scoped); | ||
} | ||
|
||
return services; | ||
} | ||
|
||
public static IServiceCollection AddMessageHandlers(this IServiceCollection services) | ||
{ | ||
services.AddScoped<Dispatcher>(); | ||
|
||
var assemblyTypes = Assembly.GetExecutingAssembly().GetTypes(); | ||
|
||
foreach (var type in assemblyTypes) | ||
{ | ||
var handlerInterfaces = type.GetInterfaces() | ||
.Where(Utils.IsHandlerInterface) | ||
.ToList(); | ||
|
||
if (!handlerInterfaces.Any()) | ||
{ | ||
continue; | ||
} | ||
|
||
var handlerFactory = new HandlerFactory(type); | ||
foreach (var interfaceType in handlerInterfaces) | ||
{ | ||
services.AddTransient(interfaceType, provider => handlerFactory.Create(provider, interfaceType)); | ||
} | ||
} | ||
|
||
var aggregateRootTypes = typeof(IAggregateRoot).Assembly.GetTypes().Where(x => x.BaseType == typeof(Entity<Guid>) && x.GetInterfaces().Contains(typeof(IAggregateRoot))).ToList(); | ||
|
||
var genericHandlerTypes = new[] | ||
{ | ||
typeof(GetEntititesQueryHandler<>), | ||
typeof(GetEntityByIdQueryHandler<>), | ||
typeof(AddOrUpdateEntityCommandHandler<>), | ||
typeof(DeleteEntityCommandHandler<>), | ||
}; | ||
|
||
foreach (var aggregateRootType in aggregateRootTypes) | ||
{ | ||
foreach (var genericHandlerType in genericHandlerTypes) | ||
{ | ||
var handlerType = genericHandlerType.MakeGenericType(aggregateRootType); | ||
var handlerInterfaces = handlerType.GetInterfaces(); | ||
|
||
var handlerFactory = new HandlerFactory(handlerType); | ||
foreach (var interfaceType in handlerInterfaces) | ||
{ | ||
services.AddTransient(interfaceType, provider => handlerFactory.Create(provider, interfaceType)); | ||
} | ||
} | ||
} | ||
|
||
return services; | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/IdentityServer/ClassifiedAds.Application/AuditLogEntries/DTOs/AuditLogEntryDTO.cs
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,21 @@ | ||
using System; | ||
|
||
namespace ClassifiedAds.Application.AuditLogEntries.DTOs | ||
{ | ||
public class AuditLogEntryDTO | ||
{ | ||
public Guid Id { get; set; } | ||
|
||
public Guid UserId { get; set; } | ||
|
||
public string UserName { get; set; } | ||
|
||
public string Action { get; set; } | ||
|
||
public string ObjectId { get; set; } | ||
|
||
public string Log { get; set; } | ||
|
||
public DateTimeOffset CreatedDateTime { get; set; } | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
src/IdentityServer/ClassifiedAds.Application/AuditLogEntries/Queries/GetAuditEntriesQuery.cs
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,45 @@ | ||
using ClassifiedAds.Application.AuditLogEntries.DTOs; | ||
using ClassifiedAds.Domain.Repositories; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace ClassifiedAds.Application.AuditLogEntries.Queries | ||
{ | ||
public class GetAuditEntriesQuery : AuditLogEntryQueryOptions, IQuery<List<AuditLogEntryDTO>> | ||
{ | ||
} | ||
|
||
internal class GetAuditEntriesQueryHandler : IQueryHandler<GetAuditEntriesQuery, List<AuditLogEntryDTO>> | ||
{ | ||
private readonly IAuditLogEntryRepository _auditLogEntryRepository; | ||
private readonly IUserRepository _userRepository; | ||
|
||
public GetAuditEntriesQueryHandler(IAuditLogEntryRepository auditLogEntryRepository, IUserRepository userRepository) | ||
{ | ||
_auditLogEntryRepository = auditLogEntryRepository; | ||
_userRepository = userRepository; | ||
} | ||
|
||
public async Task<List<AuditLogEntryDTO>> HandleAsync(GetAuditEntriesQuery query, CancellationToken cancellationToken = default) | ||
{ | ||
var auditLogs = _auditLogEntryRepository.Get(query); | ||
var users = _userRepository.GetAll(); | ||
|
||
var rs = auditLogs.Join(users, x => x.UserId, y => y.Id, | ||
(x, y) => new AuditLogEntryDTO | ||
{ | ||
Id = x.Id, | ||
UserId = x.UserId, | ||
Action = x.Action, | ||
ObjectId = x.ObjectId, | ||
Log = x.Log, | ||
CreatedDateTime = x.CreatedDateTime, | ||
UserName = y.UserName, | ||
}); | ||
|
||
return await _userRepository.ToListAsync(rs.OrderByDescending(x => x.CreatedDateTime)); | ||
} | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
...tityServer/ClassifiedAds.Application/AuditLogEntries/Queries/GetPagedAuditEntriesQuery.cs
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,59 @@ | ||
using ClassifiedAds.Application.AuditLogEntries.DTOs; | ||
using ClassifiedAds.Application.Common.DTOs; | ||
using ClassifiedAds.CrossCuttingConcerns.ExtensionMethods; | ||
using ClassifiedAds.Domain.Repositories; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace ClassifiedAds.Application.AuditLogEntries.Queries | ||
{ | ||
public class GetPagedAuditEntriesQuery : AuditLogEntryQueryOptions, IQuery<Paged<AuditLogEntryDTO>> | ||
{ | ||
public int Page { get; set; } | ||
|
||
public int PageSize { get; set; } | ||
} | ||
|
||
internal class GetPagedAuditEntriesQueryHandler : IQueryHandler<GetPagedAuditEntriesQuery, Paged<AuditLogEntryDTO>> | ||
{ | ||
private readonly IAuditLogEntryRepository _auditLogEntryRepository; | ||
private readonly IUserRepository _userRepository; | ||
|
||
public GetPagedAuditEntriesQueryHandler(IAuditLogEntryRepository auditLogEntryRepository, IUserRepository userRepository) | ||
{ | ||
_auditLogEntryRepository = auditLogEntryRepository; | ||
_userRepository = userRepository; | ||
} | ||
|
||
public async Task<Paged<AuditLogEntryDTO>> HandleAsync(GetPagedAuditEntriesQuery queryOptions, CancellationToken cancellationToken = default) | ||
{ | ||
var query = _auditLogEntryRepository.Get(queryOptions); | ||
var users = _userRepository.GetAll(); | ||
|
||
var result = new Paged<AuditLogEntryDTO> | ||
{ | ||
TotalItems = query.Count(), | ||
}; | ||
|
||
var auditLogs = query.OrderByDescending(x => x.CreatedDateTime) | ||
.Paged(queryOptions.Page, queryOptions.PageSize); | ||
|
||
var rs = auditLogs.Join(users, x => x.UserId, y => y.Id, | ||
(x, y) => new AuditLogEntryDTO | ||
{ | ||
Id = x.Id, | ||
UserId = x.UserId, | ||
Action = x.Action, | ||
ObjectId = x.ObjectId, | ||
Log = x.Log, | ||
CreatedDateTime = x.CreatedDateTime, | ||
UserName = y.UserName, | ||
}); | ||
|
||
result.Items = await _userRepository.ToListAsync(rs); | ||
|
||
return result; | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/IdentityServer/ClassifiedAds.Application/ClassifiedAds.Application.csproj
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,22 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<AnalysisMode>Recommended</AnalysisMode> | ||
<AnalysisModeSecurity>All</AnalysisModeSecurity> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0" /> | ||
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\ClassifiedAds.Domain\ClassifiedAds.Domain.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
34 changes: 34 additions & 0 deletions
34
src/IdentityServer/ClassifiedAds.Application/Common/Commands/AddEntityCommand.cs
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,34 @@ | ||
using ClassifiedAds.Domain.Entities; | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace ClassifiedAds.Application | ||
{ | ||
public class AddEntityCommand<TEntity> : ICommand | ||
where TEntity : Entity<Guid>, IAggregateRoot | ||
{ | ||
public AddEntityCommand(TEntity entity) | ||
{ | ||
Entity = entity; | ||
} | ||
|
||
public TEntity Entity { get; set; } | ||
} | ||
|
||
internal class AddEntityCommandHandler<TEntity> : ICommandHandler<AddEntityCommand<TEntity>> | ||
where TEntity : Entity<Guid>, IAggregateRoot | ||
{ | ||
private readonly ICrudService<TEntity> _crudService; | ||
|
||
public AddEntityCommandHandler(ICrudService<TEntity> crudService) | ||
{ | ||
_crudService = crudService; | ||
} | ||
|
||
public async Task HandleAsync(AddEntityCommand<TEntity> command, CancellationToken cancellationToken = default) | ||
{ | ||
await _crudService.AddAsync(command.Entity); | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/IdentityServer/ClassifiedAds.Application/Common/Commands/AddOrUpdateEntityCommand.cs
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,34 @@ | ||
using ClassifiedAds.Domain.Entities; | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace ClassifiedAds.Application | ||
{ | ||
public class AddOrUpdateEntityCommand<TEntity> : ICommand | ||
where TEntity : Entity<Guid>, IAggregateRoot | ||
{ | ||
public AddOrUpdateEntityCommand(TEntity entity) | ||
{ | ||
Entity = entity; | ||
} | ||
|
||
public TEntity Entity { get; set; } | ||
} | ||
|
||
internal class AddOrUpdateEntityCommandHandler<TEntity> : ICommandHandler<AddOrUpdateEntityCommand<TEntity>> | ||
where TEntity : Entity<Guid>, IAggregateRoot | ||
{ | ||
private readonly ICrudService<TEntity> _crudService; | ||
|
||
public AddOrUpdateEntityCommandHandler(ICrudService<TEntity> crudService) | ||
{ | ||
_crudService = crudService; | ||
} | ||
|
||
public async Task HandleAsync(AddOrUpdateEntityCommand<TEntity> command, CancellationToken cancellationToken = default) | ||
{ | ||
await _crudService.AddOrUpdateAsync(command.Entity); | ||
} | ||
} | ||
} |
Oops, something went wrong.