Skip to content

Commit c1f5ef9

Browse files
author
Juan Manuel Abanto
committed
Separate responsibility
1 parent bd3cdde commit c1f5ef9

34 files changed

Lines changed: 943 additions & 711 deletions

Sofisoft-Core.sln

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sofisoft.MongoDb", "src\Sof
2323
EndProject
2424
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sofisoft.MongoDb.Tests", "test\Sofisoft.MongoDb.Tests\Sofisoft.MongoDb.Tests.csproj", "{40E7E159-7FF8-4CF9-8CAB-613DBF2B6B23}"
2525
EndProject
26+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sofisoft.MongoDb.Models", "src\Sofisoft.MongoDb.Models\Sofisoft.MongoDb.Models.csproj", "{2BD4105D-EC40-41D2-913C-21034C44EF61}"
27+
EndProject
28+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sofisoft.AspNetCore", "src\Sofisoft.AspNetCore\Sofisoft.AspNetCore.csproj", "{2A57F27D-F8C4-4F25-8F99-F81E099DC5FD}"
29+
EndProject
30+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sofisoft.AspNetCore.Tests", "test\Sofisoft.AspNetCore.Tests\Sofisoft.AspNetCore.Tests.csproj", "{F1293025-2ADC-4DD0-99A3-044818F1C45E}"
31+
EndProject
2632
Global
2733
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2834
Debug|Any CPU = Debug|Any CPU
@@ -64,6 +70,18 @@ Global
6470
{40E7E159-7FF8-4CF9-8CAB-613DBF2B6B23}.Debug|Any CPU.Build.0 = Debug|Any CPU
6571
{40E7E159-7FF8-4CF9-8CAB-613DBF2B6B23}.Release|Any CPU.ActiveCfg = Release|Any CPU
6672
{40E7E159-7FF8-4CF9-8CAB-613DBF2B6B23}.Release|Any CPU.Build.0 = Release|Any CPU
73+
{2BD4105D-EC40-41D2-913C-21034C44EF61}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
74+
{2BD4105D-EC40-41D2-913C-21034C44EF61}.Debug|Any CPU.Build.0 = Debug|Any CPU
75+
{2BD4105D-EC40-41D2-913C-21034C44EF61}.Release|Any CPU.ActiveCfg = Release|Any CPU
76+
{2BD4105D-EC40-41D2-913C-21034C44EF61}.Release|Any CPU.Build.0 = Release|Any CPU
77+
{2A57F27D-F8C4-4F25-8F99-F81E099DC5FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
78+
{2A57F27D-F8C4-4F25-8F99-F81E099DC5FD}.Debug|Any CPU.Build.0 = Debug|Any CPU
79+
{2A57F27D-F8C4-4F25-8F99-F81E099DC5FD}.Release|Any CPU.ActiveCfg = Release|Any CPU
80+
{2A57F27D-F8C4-4F25-8F99-F81E099DC5FD}.Release|Any CPU.Build.0 = Release|Any CPU
81+
{F1293025-2ADC-4DD0-99A3-044818F1C45E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
82+
{F1293025-2ADC-4DD0-99A3-044818F1C45E}.Debug|Any CPU.Build.0 = Debug|Any CPU
83+
{F1293025-2ADC-4DD0-99A3-044818F1C45E}.Release|Any CPU.ActiveCfg = Release|Any CPU
84+
{F1293025-2ADC-4DD0-99A3-044818F1C45E}.Release|Any CPU.Build.0 = Release|Any CPU
6785
EndGlobalSection
6886
GlobalSection(NestedProjects) = preSolution
6987
{3D77729C-059F-477E-933B-21679EBEAC20} = {C41F6762-8D90-4781-9330-FCEF5BB32D79}
@@ -74,5 +92,8 @@ Global
7492
{A9D950A7-260C-4F84-BF86-393843D6A405} = {65C8BE55-D0C1-4537-AB6F-77F3100F00A1}
7593
{B3ABAF1E-5417-46CE-8521-EF0612C1EE4B} = {C41F6762-8D90-4781-9330-FCEF5BB32D79}
7694
{40E7E159-7FF8-4CF9-8CAB-613DBF2B6B23} = {65C8BE55-D0C1-4537-AB6F-77F3100F00A1}
95+
{2BD4105D-EC40-41D2-913C-21034C44EF61} = {C41F6762-8D90-4781-9330-FCEF5BB32D79}
96+
{2A57F27D-F8C4-4F25-8F99-F81E099DC5FD} = {C41F6762-8D90-4781-9330-FCEF5BB32D79}
97+
{F1293025-2ADC-4DD0-99A3-044818F1C45E} = {65C8BE55-D0C1-4537-AB6F-77F3100F00A1}
7798
EndGlobalSection
7899
EndGlobal

samples/Web.Api/Program.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using MongoDB.Driver;
12
using Sofisoft.Logging;
23

34
var builder = WebApplication.CreateBuilder(args);
@@ -44,7 +45,10 @@
4445
options.AddSupportedUICultures(supportedCultures);
4546
});
4647

47-
app.UseMiddleware<SofisoftLoggingMiddleware>();
48+
app.UseLogging();
49+
app.UseDbTransaction<IClientSessionHandle>();
50+
51+
// app.UseMiddleware<SofisoftLoggingMiddleware>();
4852

4953
app.UseRouting();
5054
app.UseAuthorization();

samples/Web.Api/Web.Api.csproj

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1-
<Project Sdk="Microsoft.NET.Sdk.Web">
2-
3-
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
5-
<Nullable>enable</Nullable>
6-
<ImplicitUsings>enable</ImplicitUsings>
7-
</PropertyGroup>
8-
9-
<ItemGroup>
10-
<ProjectReference Include="..\..\src\Sofisoft.Logging\Sofisoft.Logging.csproj"/>
11-
<ProjectReference Include="..\..\src\Sofisoft.MongoDb\Sofisoft.MongoDb.csproj"/>
12-
<ProjectReference Include="..\..\src\Sofisoft.Identity\Sofisoft.Identity.csproj"/>
13-
</ItemGroup>
14-
15-
<ItemGroup>
16-
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
17-
</ItemGroup>
18-
19-
</Project>
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
<PropertyGroup>
3+
<TargetFramework>net6.0</TargetFramework>
4+
<Nullable>enable</Nullable>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
</PropertyGroup>
7+
<ItemGroup>
8+
<ProjectReference Include="..\..\src\Sofisoft.AspNetCore\Sofisoft.AspNetCore.csproj"/>
9+
<ProjectReference Include="..\..\src\Sofisoft.Identity\Sofisoft.Identity.csproj"/>
10+
<ProjectReference Include="..\..\src\Sofisoft.Logging\Sofisoft.Logging.csproj"/>
11+
<ProjectReference Include="..\..\src\Sofisoft.MongoDb\Sofisoft.MongoDb.csproj"/>
12+
</ItemGroup>
13+
<ItemGroup>
14+
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3"/>
15+
<PackageReference Include="MongoDB.Driver" Version="2.14.1"/>
16+
</ItemGroup>
17+
</Project>

src/Sofisoft.MongoDb/Attributes/BsonCollectionAttribute.cs renamed to src/Sofisoft.Abstractions/Attributes/BsonCollectionAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace Sofisoft.MongoDb.Attributes
1+
namespace Sofisoft.Abstractions.Attributes
22
{
33
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
44
public class BsonCollectionAttribute : Attribute
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace Sofisoft.Abstractions.Attributes
2+
{
3+
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
4+
public class TransactionAttribute : Attribute
5+
{
6+
public TransactionAttribute() { }
7+
}
8+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace Sofisoft.Abstractions
2+
{
3+
public interface ISofisoftDbContext<TContextTransaction>
4+
where TContextTransaction : class
5+
{
6+
bool HasActiveTransaction { get; }
7+
Task<TContextTransaction?> BeginTransactionAsync();
8+
Task CommitTransactionAsync(TContextTransaction? transaction);
9+
TContextTransaction? GetCurrentTransaction();
10+
TDatabase GetDatabase<TDatabase>();
11+
}
12+
}

src/Sofisoft.Abstractions/Models/IEntity.cs renamed to src/Sofisoft.Abstractions/Models/IBaseEntity.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace Sofisoft.Abstractions.Models
22
{
3-
public interface IEntity
3+
public interface IBaseEntity
44
{
55
/// <summary>
66
/// Get the Id of entity.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using Sofisoft.Abstractions.Models;
2+
3+
namespace Sofisoft.Abstractions.Repositories
4+
{
5+
public interface ICommandRepository<TEntity>
6+
where TEntity : IBaseEntity
7+
{
8+
9+
/// <summary>
10+
/// Delete a record from the database by Id.
11+
/// </summary>
12+
/// <param name="id">Entity id.</param>
13+
/// <param name="cancellationToken">cancellation token.</param>
14+
Task DeleteByIdAsync(
15+
string id,
16+
CancellationToken cancellationToken = default);
17+
18+
/// <summary>
19+
/// Insert a single entity
20+
/// </summary>
21+
/// <param name="entity">Entity to be inserted.</param>
22+
/// <param name="cancellationToken">Cancellation token.</param>
23+
Task InsertOneAsync(
24+
TEntity entity,
25+
CancellationToken cancellationToken = default);
26+
27+
/// <summary>
28+
/// Insert many entities.
29+
/// </summary>
30+
/// <param name="entities">Collection of entities to be inserted.</param>
31+
/// <param name="cancellationToken">cancellation token.</param>
32+
Task InsertManyAsync(
33+
ICollection<TEntity> entities,
34+
CancellationToken cancellationToken = default);
35+
36+
/// <summary>
37+
/// Update a single entity.
38+
/// </summary>
39+
/// <param name="entity">Entity being modified.</param>
40+
/// <param name="cancellationToken">cancellation token.</param>
41+
Task<long> UpdateOneAsync(
42+
TEntity entity,
43+
CancellationToken cancellationToken = default);
44+
}
45+
}

src/Sofisoft.Abstractions/Repositories/IRepository.cs renamed to src/Sofisoft.Abstractions/Repositories/IQueryRepository.cs

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
namespace Sofisoft.Abstractions.Repositories
55
{
6-
public interface IRepository<TEntity>
7-
where TEntity : IEntity
6+
public interface IQueryRepository<TEntity>
7+
where TEntity : IBaseEntity
88
{
99
/// <summary>
1010
/// Returns number of records according to the expression.
@@ -15,15 +15,6 @@ Task<long> CountAsync(
1515
Expression<Func<TEntity, bool>> filterExpression,
1616
CancellationToken cancellationToken = default);
1717

18-
/// <summary>
19-
/// Delete a record from the database by Id.
20-
/// </summary>
21-
/// <param name="id">Entity id.</param>
22-
/// <param name="cancellationToken">cancellation token.</param>
23-
Task DeleteByIdAsync(
24-
string id,
25-
CancellationToken cancellationToken = default);
26-
2718
/// <summary>
2819
/// Filter entities by an expression.
2920
/// </summary>
@@ -73,24 +64,6 @@ Task<TProjected> FindOneAsync<TProjected>(
7364
Expression<Func<TEntity, TProjected>> projectionExpression,
7465
CancellationToken cancellationToken = default);
7566

76-
/// <summary>
77-
/// Insert a single entity
78-
/// </summary>
79-
/// <param name="entity">Entity to be inserted.</param>
80-
/// <param name="cancellationToken">Cancellation token.</param>
81-
Task InsertOneAsync(
82-
TEntity entity,
83-
CancellationToken cancellationToken = default);
84-
85-
/// <summary>
86-
/// Insert many entities.
87-
/// </summary>
88-
/// <param name="entities">Collection of entities to be inserted.</param>
89-
/// <param name="cancellationToken">cancellation token.</param>
90-
Task InsertManyAsync(
91-
ICollection<TEntity> entities,
92-
CancellationToken cancellationToken = default);
93-
9467
/// <summary>
9568
/// Returns paged list.
9669
/// </summary>
@@ -123,13 +96,5 @@ Task<IEnumerable<TProjected>> PaginatedAsync<TProjected>(
12396
int start,
12497
CancellationToken cancellationToken = default);
12598

126-
/// <summary>
127-
/// Update a single entity.
128-
/// </summary>
129-
/// <param name="entity">Entity being modified.</param>
130-
/// <param name="cancellationToken">cancellation token.</param>
131-
Task<long> UpdateOneAsync(
132-
TEntity entity,
133-
CancellationToken cancellationToken = default);
13499
}
135100
}

src/Sofisoft.Abstractions/Sofisoft.Abstractions.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</PropertyGroup>
77
<PropertyGroup>
88
<PackageId>Sofisoft.Abstractions</PackageId>
9-
<Version>1.0.0-preview.3</Version>
9+
<Version>1.0.0-preview.4</Version>
1010
<Title>Sofisoft Abstractions</Title>
1111
<Description>Abstractions and more used for Sofisoft services.</Description>
1212
<Authors>Sofisoft Lab</Authors>

0 commit comments

Comments
 (0)