Skip to content

Commit 7c3476a

Browse files
committed
Move IdentityServer To Separate & Shared Project
1 parent 631d18c commit 7c3476a

File tree

1,317 files changed

+13307
-76834
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,317 files changed

+13307
-76834
lines changed

.github/workflows/.net-build-microservices.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ jobs:
3636
- name: Publish Identity.Api
3737
run: dotnet publish Services.Identity/ClassifiedAds.Services.Identity.Api/*.csproj --configuration Release
3838

39-
- name: Publish Identity.AuthServer
40-
run: dotnet publish Services.Identity/ClassifiedAds.Services.Identity.AuthServer/*.csproj --configuration Release
41-
4239
- name: Publish Identity.Grpc
4340
run: dotnet publish Services.Identity/ClassifiedAds.Services.Identity.Grpc/*.csproj --configuration Release
4441

@@ -78,12 +75,6 @@ jobs:
7875
name: ClassifiedAds.Services.Identity.Api
7976
path: src/Microservices/Services.Identity/ClassifiedAds.Services.Identity.Api/bin/Release/net6.0/publish
8077

81-
- name: Upload ClassifiedAds.Services.Identity.AuthServer
82-
uses: actions/[email protected]
83-
with:
84-
name: ClassifiedAds.Services.Identity.AuthServer
85-
path: src/Microservices/Services.Identity/ClassifiedAds.Services.Identity.AuthServer/bin/Release/net6.0/publish
86-
8778
- name: Upload ClassifiedAds.Services.Identity.Grpc
8879
uses: actions/[email protected]
8980
with:

.github/workflows/.net-build-modularmonolith.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ jobs:
3030
- name: Publish ClassifiedAds.BackgroundServer
3131
run: dotnet publish ClassifiedAds.BackgroundServer/*.csproj --configuration Release
3232

33-
- name: Publish ClassifiedAds.IdentityServer
34-
run: dotnet publish ClassifiedAds.IdentityServer/*.csproj --configuration Release
35-
3633
- name: Publish ClassifiedAds.Migrator
3734
run: dotnet publish ClassifiedAds.Migrator/*.csproj --configuration Release
3835

@@ -45,12 +42,6 @@ jobs:
4542
name: ClassifiedAds.BackgroundServer
4643
path: src/ModularMonolith/ClassifiedAds.BackgroundServer/bin/Release/net6.0/publish
4744

48-
- name: Upload ClassifiedAds.IdentityServer
49-
uses: actions/[email protected]
50-
with:
51-
name: ClassifiedAds.IdentityServer
52-
path: src/ModularMonolith/ClassifiedAds.IdentityServer/bin/Release/net6.0/publish
53-
5445
- name: Upload ClassifiedAds.Migrator
5546
uses: actions/[email protected]
5647
with:

.github/workflows/.net-build-monolith.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ jobs:
3939
- name: Publish ClassifiedAds.WebAPI
4040
run: dotnet publish ClassifiedAds.WebAPI/*.csproj --configuration Release
4141

42-
- name: Publish ClassifiedAds.IdentityServer
43-
run: dotnet publish ClassifiedAds.IdentityServer/*.csproj --configuration Release
44-
4542
- name: Publish ClassifiedAds.WebMVC
4643
run: dotnet publish ClassifiedAds.WebMVC/*.csproj --configuration Release
4744

@@ -74,12 +71,6 @@ jobs:
7471
with:
7572
name: ClassifiedAds.WebAPI
7673
path: src/Monolith/ClassifiedAds.WebAPI/bin/Release/net6.0/publish
77-
78-
- name: Upload ClassifiedAds.IdentityServer
79-
uses: actions/[email protected]
80-
with:
81-
name: ClassifiedAds.IdentityServer
82-
path: src/Monolith/ClassifiedAds.IdentityServer/bin/Release/net6.0/publish
8374

8475
- name: Upload ClassifiedAds.WebMVC
8576
uses: actions/[email protected]

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Ignore the Migrations folder for now since this repo is for learning and testing purposes
22
## We don't want to mess things up with lot of migration files anytime we make changes to the database structure.
3-
/src/Monolith/ClassifiedAds.Persistence/Migrations/
3+
/src/IdentityServer/ClassifiedAds.Migrator/Migrations/
44
/src/Monolith/ClassifiedAds.Migrator/Migrations/
55
/src/ModularMonolith/ClassifiedAds.Migrator/Migrations/
66
/src/Microservices/Services.AuditLog/ClassifiedAds.Services.AuditLog.Api/Migrations/
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
using ClassifiedAds.Application;
2+
using ClassifiedAds.Application.EmailMessages.Services;
3+
using ClassifiedAds.Application.EventLogs;
4+
using ClassifiedAds.Application.Products.Services;
5+
using ClassifiedAds.Application.SmsMessages.Services;
6+
using ClassifiedAds.Application.Users.Services;
7+
using ClassifiedAds.Domain.Entities;
8+
using ClassifiedAds.Domain.Events;
9+
using System;
10+
using System.Linq;
11+
using System.Reflection;
12+
13+
namespace Microsoft.Extensions.DependencyInjection
14+
{
15+
public static class ApplicationServicesExtensions
16+
{
17+
public static IServiceCollection AddApplicationServices(this IServiceCollection services, Action<Type, Type, ServiceLifetime> configureInterceptor = null)
18+
{
19+
DomainEvents.RegisterHandlers(Assembly.GetExecutingAssembly(), services);
20+
21+
services
22+
.AddScoped<IDomainEvents, DomainEvents>()
23+
.AddScoped(typeof(ICrudService<>), typeof(CrudService<>))
24+
.AddScoped<IUserService, UserService>()
25+
.AddScoped<IProductService, ProductService>()
26+
.AddScoped<EmailMessageService>()
27+
.AddScoped<SmsMessageService>()
28+
.AddScoped<PublishEventService>();
29+
30+
if (configureInterceptor != null)
31+
{
32+
var aggregateRootTypes = typeof(IAggregateRoot).Assembly.GetTypes().Where(x => x.BaseType == typeof(Entity<Guid>) && x.GetInterfaces().Contains(typeof(IAggregateRoot))).ToList();
33+
foreach (var type in aggregateRootTypes)
34+
{
35+
configureInterceptor(typeof(ICrudService<>).MakeGenericType(type), typeof(CrudService<>).MakeGenericType(type), ServiceLifetime.Scoped);
36+
}
37+
38+
configureInterceptor(typeof(IUserService), typeof(UserService), ServiceLifetime.Scoped);
39+
configureInterceptor(typeof(IProductService), typeof(ProductService), ServiceLifetime.Scoped);
40+
}
41+
42+
return services;
43+
}
44+
45+
public static IServiceCollection AddMessageHandlers(this IServiceCollection services)
46+
{
47+
services.AddScoped<Dispatcher>();
48+
49+
var assemblyTypes = Assembly.GetExecutingAssembly().GetTypes();
50+
51+
foreach (var type in assemblyTypes)
52+
{
53+
var handlerInterfaces = type.GetInterfaces()
54+
.Where(Utils.IsHandlerInterface)
55+
.ToList();
56+
57+
if (!handlerInterfaces.Any())
58+
{
59+
continue;
60+
}
61+
62+
var handlerFactory = new HandlerFactory(type);
63+
foreach (var interfaceType in handlerInterfaces)
64+
{
65+
services.AddTransient(interfaceType, provider => handlerFactory.Create(provider, interfaceType));
66+
}
67+
}
68+
69+
var aggregateRootTypes = typeof(IAggregateRoot).Assembly.GetTypes().Where(x => x.BaseType == typeof(Entity<Guid>) && x.GetInterfaces().Contains(typeof(IAggregateRoot))).ToList();
70+
71+
var genericHandlerTypes = new[]
72+
{
73+
typeof(GetEntititesQueryHandler<>),
74+
typeof(GetEntityByIdQueryHandler<>),
75+
typeof(AddOrUpdateEntityCommandHandler<>),
76+
typeof(DeleteEntityCommandHandler<>),
77+
};
78+
79+
foreach (var aggregateRootType in aggregateRootTypes)
80+
{
81+
foreach (var genericHandlerType in genericHandlerTypes)
82+
{
83+
var handlerType = genericHandlerType.MakeGenericType(aggregateRootType);
84+
var handlerInterfaces = handlerType.GetInterfaces();
85+
86+
var handlerFactory = new HandlerFactory(handlerType);
87+
foreach (var interfaceType in handlerInterfaces)
88+
{
89+
services.AddTransient(interfaceType, provider => handlerFactory.Create(provider, interfaceType));
90+
}
91+
}
92+
}
93+
94+
return services;
95+
}
96+
}
97+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
3+
namespace ClassifiedAds.Application.AuditLogEntries.DTOs
4+
{
5+
public class AuditLogEntryDTO
6+
{
7+
public Guid Id { get; set; }
8+
9+
public Guid UserId { get; set; }
10+
11+
public string UserName { get; set; }
12+
13+
public string Action { get; set; }
14+
15+
public string ObjectId { get; set; }
16+
17+
public string Log { get; set; }
18+
19+
public DateTimeOffset CreatedDateTime { get; set; }
20+
}
21+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using ClassifiedAds.Application.AuditLogEntries.DTOs;
2+
using ClassifiedAds.Domain.Repositories;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Threading;
6+
using System.Threading.Tasks;
7+
8+
namespace ClassifiedAds.Application.AuditLogEntries.Queries
9+
{
10+
public class GetAuditEntriesQuery : AuditLogEntryQueryOptions, IQuery<List<AuditLogEntryDTO>>
11+
{
12+
}
13+
14+
internal class GetAuditEntriesQueryHandler : IQueryHandler<GetAuditEntriesQuery, List<AuditLogEntryDTO>>
15+
{
16+
private readonly IAuditLogEntryRepository _auditLogEntryRepository;
17+
private readonly IUserRepository _userRepository;
18+
19+
public GetAuditEntriesQueryHandler(IAuditLogEntryRepository auditLogEntryRepository, IUserRepository userRepository)
20+
{
21+
_auditLogEntryRepository = auditLogEntryRepository;
22+
_userRepository = userRepository;
23+
}
24+
25+
public async Task<List<AuditLogEntryDTO>> HandleAsync(GetAuditEntriesQuery query, CancellationToken cancellationToken = default)
26+
{
27+
var auditLogs = _auditLogEntryRepository.Get(query);
28+
var users = _userRepository.GetAll();
29+
30+
var rs = auditLogs.Join(users, x => x.UserId, y => y.Id,
31+
(x, y) => new AuditLogEntryDTO
32+
{
33+
Id = x.Id,
34+
UserId = x.UserId,
35+
Action = x.Action,
36+
ObjectId = x.ObjectId,
37+
Log = x.Log,
38+
CreatedDateTime = x.CreatedDateTime,
39+
UserName = y.UserName,
40+
});
41+
42+
return await _userRepository.ToListAsync(rs.OrderByDescending(x => x.CreatedDateTime));
43+
}
44+
}
45+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using ClassifiedAds.Application.AuditLogEntries.DTOs;
2+
using ClassifiedAds.Application.Common.DTOs;
3+
using ClassifiedAds.CrossCuttingConcerns.ExtensionMethods;
4+
using ClassifiedAds.Domain.Repositories;
5+
using System.Linq;
6+
using System.Threading;
7+
using System.Threading.Tasks;
8+
9+
namespace ClassifiedAds.Application.AuditLogEntries.Queries
10+
{
11+
public class GetPagedAuditEntriesQuery : AuditLogEntryQueryOptions, IQuery<Paged<AuditLogEntryDTO>>
12+
{
13+
public int Page { get; set; }
14+
15+
public int PageSize { get; set; }
16+
}
17+
18+
internal class GetPagedAuditEntriesQueryHandler : IQueryHandler<GetPagedAuditEntriesQuery, Paged<AuditLogEntryDTO>>
19+
{
20+
private readonly IAuditLogEntryRepository _auditLogEntryRepository;
21+
private readonly IUserRepository _userRepository;
22+
23+
public GetPagedAuditEntriesQueryHandler(IAuditLogEntryRepository auditLogEntryRepository, IUserRepository userRepository)
24+
{
25+
_auditLogEntryRepository = auditLogEntryRepository;
26+
_userRepository = userRepository;
27+
}
28+
29+
public async Task<Paged<AuditLogEntryDTO>> HandleAsync(GetPagedAuditEntriesQuery queryOptions, CancellationToken cancellationToken = default)
30+
{
31+
var query = _auditLogEntryRepository.Get(queryOptions);
32+
var users = _userRepository.GetAll();
33+
34+
var result = new Paged<AuditLogEntryDTO>
35+
{
36+
TotalItems = query.Count(),
37+
};
38+
39+
var auditLogs = query.OrderByDescending(x => x.CreatedDateTime)
40+
.Paged(queryOptions.Page, queryOptions.PageSize);
41+
42+
var rs = auditLogs.Join(users, x => x.UserId, y => y.Id,
43+
(x, y) => new AuditLogEntryDTO
44+
{
45+
Id = x.Id,
46+
UserId = x.UserId,
47+
Action = x.Action,
48+
ObjectId = x.ObjectId,
49+
Log = x.Log,
50+
CreatedDateTime = x.CreatedDateTime,
51+
UserName = y.UserName,
52+
});
53+
54+
result.Items = await _userRepository.ToListAsync(rs);
55+
56+
return result;
57+
}
58+
}
59+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<AnalysisMode>Recommended</AnalysisMode>
6+
<AnalysisModeSecurity>All</AnalysisModeSecurity>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" />
11+
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0" />
12+
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
13+
<PrivateAssets>all</PrivateAssets>
14+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
15+
</PackageReference>
16+
</ItemGroup>
17+
18+
<ItemGroup>
19+
<ProjectReference Include="..\ClassifiedAds.Domain\ClassifiedAds.Domain.csproj" />
20+
</ItemGroup>
21+
22+
</Project>

0 commit comments

Comments
 (0)